diff --git a/language/English/how-set.md b/language/English/how-set.md new file mode 100644 index 00000000..3632a440 --- /dev/null +++ b/language/English/how-set.md @@ -0,0 +1,2 @@ +Change the link in index.js No.151 to the following content:
+`https://tira-tw.github.io/english-url/"+config.theme+"/index.html` diff --git a/language/English/index.html b/language/English/index.html new file mode 100644 index 00000000..bbf572cd --- /dev/null +++ b/language/English/index.html @@ -0,0 +1,110 @@ + + + + + + + Shorter URL + + + +
+
Shorten your Url
+
+
Please enter the long URL to be shortened :
+
+ +
+ +
+
+ +

+
+
+ + + + + + + diff --git a/language/English/index.js b/language/English/index.js new file mode 100644 index 00000000..ea16cab9 --- /dev/null +++ b/language/English/index.js @@ -0,0 +1,211 @@ +const config = { +no_ref: "off", //Control the HTTP referrer header, if you want to create an anonymous link that will hide the HTTP Referer header, please set to "on" . +theme:"",//Homepage theme, use the empty value for default theme. To use urlcool theme, please fill with "theme/urlcool" . +cors: "on",//Allow Cross-origin resource sharing for API requests. +unique_link:true,//If it is true, the same long url will be shorten into the same short url +custom_link:false,//Allow users to customize the short url. +safe_browsing_api_key: "" //Enter Google Safe Browsing API Key to enable url safety check before redirect. +} + +const html404 = ` + +

404 Not Found.

+

The url you visit is not found.

+ want host?come! +` + +let response_header={ + "content-type": "text/html;charset=UTF-8", +} + +if (config.cors=="on"){ + response_header={ + "content-type": "text/html;charset=UTF-8", + "Access-Control-Allow-Origin":"*", + "Access-Control-Allow-Methods": "POST", + } +} + +async function randomString(len) { +  len = len || 6; +  let $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/ +  let maxPos = $chars.length; +  let result = ''; +  for (i = 0; i < len; i++) { +    result += $chars.charAt(Math.floor(Math.random() * maxPos)); +  } +  return result; +} + +async function sha512(url){ + url = new TextEncoder().encode(url) + + const url_digest = await crypto.subtle.digest( + { + name: "SHA-512", + }, + url, // The data you want to hash as an ArrayBuffer + ) + const hashArray = Array.from(new Uint8Array(url_digest)); // convert buffer to byte array + const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); + //console.log(hashHex) + return hashHex +} +async function checkURL(URL){ + let str=URL; + let Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/; + let objExp=new RegExp(Expression); + if(objExp.test(str)==true){ + if (str[0] == 'h') + return true; + else + return false; + }else{ + return false; + } +} +async function save_url(URL){ + let random_key=await randomString() + let is_exist=await LINKS.get(random_key) + console.log(is_exist) + if (is_exist == null) + return await LINKS.put(random_key, URL),random_key + else + save_url(URL) +} +async function is_url_exist(url_sha512){ + let is_exist = await LINKS.get(url_sha512) + console.log(is_exist) + if (is_exist == null) { + return false + }else{ + return is_exist + } +} +async function is_url_safe(url){ + + let raw = JSON.stringify({"client":{"clientId":"Url-Shorten-Worker","clientVersion":"1.0.7"},"threatInfo":{"threatTypes":["MALWARE","SOCIAL_ENGINEERING","POTENTIALLY_HARMFUL_APPLICATION","UNWANTED_SOFTWARE"],"platformTypes":["ANY_PLATFORM"],"threatEntryTypes":["URL"],"threatEntries":[{"url":url}]}}); + + let requestOptions = { + method: 'POST', + body: raw, + redirect: 'follow' + }; + + result = await fetch("https://safebrowsing.googleapis.com/v4/threatMatches:find?key="+config.safe_browsing_api_key, requestOptions) + result = await result.json() + console.log(result) + if (Object.keys(result).length === 0){ + return true + }else{ + return false + } +} +async function handleRequest(request) { + console.log(request) + if (request.method === "POST") { + let req=await request.json() + console.log(req["url"]) + if(!await checkURL(req["url"])){ + return new Response(`{"status":500,"key":": Error: Url info maybe is fish website or virus or not this url"}`, { + headers: response_header, + })} + let stat,random_key + if (config.unique_link){ + let url_sha512 = await sha512(req["url"]) + let url_key = await is_url_exist(url_sha512) + if(url_key){ + random_key = url_key + }else{ + stat,random_key=await save_url(req["url"]) + if (typeof(stat) == "undefined"){ + console.log(await LINKS.put(url_sha512,random_key)) + } + } + }else{ + stat,random_key=await save_url(req["url"]) + } + console.log(stat) + if (typeof(stat) == "undefined"){ + return new Response(`{"status":200,"key":"/`+random_key+`"}`, { + headers: response_header, + }) + }else{ + return new Response(`{"status":200,"key":": Error:Reach the KV write limitation."}`, { + headers: response_header, + })} + }else if(request.method === "OPTIONS"){ + return new Response(``, { + headers: response_header, + }) + + } + + const requestURL = new URL(request.url) + const path = requestURL.pathname.split("/")[1] + const params = requestURL.search; + + console.log(path) + if(!path){ + + const html= await fetch("https://tira-tw.github.io/english-url/"+config.theme+"/index.html") + + return new Response(await html.text(), { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + } + + const value = await LINKS.get(path); + let location ; + + if(params) { + location = value + params + } else { + location = value + } + console.log(value) + + + if (location) { + if (config.safe_browsing_api_key){ + if(!(await is_url_safe(location))){ + let warning_page = await fetch("https://xytom.github.io/Url-Shorten-Worker/safe-browsing.html") + warning_page =await warning_page.text() + warning_page = warning_page.replace(/{Replace}/gm, location) + return new Response(warning_page, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + } + } + if (config.no_ref=="on"){ + let no_ref= await fetch("https://xytom.github.io/Url-Shorten-Worker/no-ref.html") + no_ref=await no_ref.text() + no_ref=no_ref.replace(/{Replace}/gm, location) + return new Response(no_ref, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + }else{ + return Response.redirect(location, 302) + } + + } + // If request not in kv, return 404 + return new Response(html404, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + status: 404 + }) +} + + + +addEventListener("fetch", async event => { + event.respondWith(handleRequest(event.request)) +}) diff --git a/language/Indonesia/Bagaimana mengatur.md b/language/Indonesia/Bagaimana mengatur.md new file mode 100644 index 00000000..c1f8975c --- /dev/null +++ b/language/Indonesia/Bagaimana mengatur.md @@ -0,0 +1,2 @@ +Ubah link di index.js No.151 menjadi konten berikut:
+`https://tira-tw.github.io/Indonesia-url/"+config.theme+"/index.html` diff --git a/language/Indonesia/index.html b/language/Indonesia/index.html new file mode 100644 index 00000000..321b462a --- /dev/null +++ b/language/Indonesia/index.html @@ -0,0 +1,110 @@ + + + + + + + URL pendek + + + +
+
Pendekan URL anda!
+
+
Mohon masukan URL panjang yang ingin
+
+ +
+ +
+
+ +

+
+
+ + + + + + + diff --git a/language/Indonesia/index.js b/language/Indonesia/index.js new file mode 100644 index 00000000..fd8f0b0d --- /dev/null +++ b/language/Indonesia/index.js @@ -0,0 +1,211 @@ +const config = { +no_ref: "off", //Control the HTTP referrer header, if you want to create an anonymous link that will hide the HTTP Referer header, please set to "on" . +theme:"",//Homepage theme, use the empty value for default theme. To use urlcool theme, please fill with "theme/urlcool" . +cors: "on",//Allow Cross-origin resource sharing for API requests. +unique_link:true,//If it is true, the same long url will be shorten into the same short url +custom_link:false,//Allow users to customize the short url. +safe_browsing_api_key: "" //Enter Google Safe Browsing API Key to enable url safety check before redirect. +} + +const html404 = ` + +

404 Halaman tidak ditemukan

+

Tautan yang Anda kunjungi tidak dapat ditemukan

+ Ingin buat yang sama? Klik! +` + +let response_header={ + "content-type": "text/html;charset=UTF-8", +} + +if (config.cors=="on"){ + response_header={ + "content-type": "text/html;charset=UTF-8", + "Access-Control-Allow-Origin":"*", + "Access-Control-Allow-Methods": "POST", + } +} + +async function randomString(len) { +  len = len || 6; +  let $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/ +  let maxPos = $chars.length; +  let result = ''; +  for (i = 0; i < len; i++) { +    result += $chars.charAt(Math.floor(Math.random() * maxPos)); +  } +  return result; +} + +async function sha512(url){ + url = new TextEncoder().encode(url) + + const url_digest = await crypto.subtle.digest( + { + name: "SHA-512", + }, + url, // The data you want to hash as an ArrayBuffer + ) + const hashArray = Array.from(new Uint8Array(url_digest)); // convert buffer to byte array + const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); + //console.log(hashHex) + return hashHex +} +async function checkURL(URL){ + let str=URL; + let Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/; + let objExp=new RegExp(Expression); + if(objExp.test(str)==true){ + if (str[0] == 'h') + return true; + else + return false; + }else{ + return false; + } +} +async function save_url(URL){ + let random_key=await randomString() + let is_exist=await LINKS.get(random_key) + console.log(is_exist) + if (is_exist == null) + return await LINKS.put(random_key, URL),random_key + else + save_url(URL) +} +async function is_url_exist(url_sha512){ + let is_exist = await LINKS.get(url_sha512) + console.log(is_exist) + if (is_exist == null) { + return false + }else{ + return is_exist + } +} +async function is_url_safe(url){ + + let raw = JSON.stringify({"client":{"clientId":"Url-Shorten-Worker","clientVersion":"1.0.7"},"threatInfo":{"threatTypes":["MALWARE","SOCIAL_ENGINEERING","POTENTIALLY_HARMFUL_APPLICATION","UNWANTED_SOFTWARE"],"platformTypes":["ANY_PLATFORM"],"threatEntryTypes":["URL"],"threatEntries":[{"url":url}]}}); + + let requestOptions = { + method: 'POST', + body: raw, + redirect: 'follow' + }; + + result = await fetch("https://safebrowsing.googleapis.com/v4/threatMatches:find?key="+config.safe_browsing_api_key, requestOptions) + result = await result.json() + console.log(result) + if (Object.keys(result).length === 0){ + return true + }else{ + return false + } +} +async function handleRequest(request) { + console.log(request) + if (request.method === "POST") { + let req=await request.json() + console.log(req["url"]) + if(!await checkURL(req["url"])){ + return new Response(`{"status":500,"key":": Error: informasi URL ini mungkin situs web yang mencurigakan atau mengandung virus atau bukan URL yang benar"}`, { + headers: response_header, + })} + let stat,random_key + if (config.unique_link){ + let url_sha512 = await sha512(req["url"]) + let url_key = await is_url_exist(url_sha512) + if(url_key){ + random_key = url_key + }else{ + stat,random_key=await save_url(req["url"]) + if (typeof(stat) == "undefined"){ + console.log(await LINKS.put(url_sha512,random_key)) + } + } + }else{ + stat,random_key=await save_url(req["url"]) + } + console.log(stat) + if (typeof(stat) == "undefined"){ + return new Response(`{"status":200,"key":"/`+random_key+`"}`, { + headers: response_header, + }) + }else{ + return new Response(`{"status":200,"key":": Error:Reach the KV write limitation."}`, { + headers: response_header, + })} + }else if(request.method === "OPTIONS"){ + return new Response(``, { + headers: response_header, + }) + + } + + const requestURL = new URL(request.url) + const path = requestURL.pathname.split("/")[1] + const params = requestURL.search; + + console.log(path) + if(!path){ + + const html= await fetch("https://tira-tw.github.io/Indonesia-url/"+config.theme+"/index.html") + + return new Response(await html.text(), { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + } + + const value = await LINKS.get(path); + let location ; + + if(params) { + location = value + params + } else { + location = value + } + console.log(value) + + + if (location) { + if (config.safe_browsing_api_key){ + if(!(await is_url_safe(location))){ + let warning_page = await fetch("https://xytom.github.io/Url-Shorten-Worker/safe-browsing.html") + warning_page =await warning_page.text() + warning_page = warning_page.replace(/{Replace}/gm, location) + return new Response(warning_page, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + } + } + if (config.no_ref=="on"){ + let no_ref= await fetch("https://xytom.github.io/Url-Shorten-Worker/no-ref.html") + no_ref=await no_ref.text() + no_ref=no_ref.replace(/{Replace}/gm, location) + return new Response(no_ref, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + }else{ + return Response.redirect(location, 302) + } + + } + // If request not in kv, return 404 + return new Response(html404, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + status: 404 + }) +} + + + +addEventListener("fetch", async event => { + event.respondWith(handleRequest(event.request)) +}) diff --git a/language/Korea/index.html b/language/Korea/index.html new file mode 100644 index 00000000..2dd34c53 --- /dev/null +++ b/language/Korea/index.html @@ -0,0 +1,110 @@ + + + + + + + 짧은 URL + + + +
+
URL 짧게하기!
+
+
URL을 짧게 하기 위해 긴 URL을 입력해주세요:
+
+ +
+ +
+
+ +

+
+
+ + + + + + + diff --git a/language/Korea/index.js b/language/Korea/index.js new file mode 100644 index 00000000..d73861a6 --- /dev/null +++ b/language/Korea/index.js @@ -0,0 +1,210 @@ +const config = { +no_ref: "off", //Control the HTTP referrer header, if you want to create an anonymous link that will hide the HTTP Referer header, please set to "on" . +theme:"",//Homepage theme, use the empty value for default theme. To use urlcool theme, please fill with "theme/urlcool" . +cors: "on",//Allow Cross-origin resource sharing for API requests. +unique_link:true,//If it is true, the same long url will be shorten into the same short url +custom_link:false,//Allow users to customize the short url. +safe_browsing_api_key: "" //Enter Google Safe Browsing API Key to enable url safety check before redirect. +} + +const html404 = ` + +

404 찾을 수 없음.

+

입력한 주소를 찾을 수 없습니다.

+` + +let response_header={ + "content-type": "text/html;charset=UTF-8", +} + +if (config.cors=="on"){ + response_header={ + "content-type": "text/html;charset=UTF-8", + "Access-Control-Allow-Origin":"*", + "Access-Control-Allow-Methods": "POST", + } +} + +async function randomString(len) { +  len = len || 6; +  let $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/ +  let maxPos = $chars.length; +  let result = ''; +  for (i = 0; i < len; i++) { +    result += $chars.charAt(Math.floor(Math.random() * maxPos)); +  } +  return result; +} + +async function sha512(url){ + url = new TextEncoder().encode(url) + + const url_digest = await crypto.subtle.digest( + { + name: "SHA-512", + }, + url, // The data you want to hash as an ArrayBuffer + ) + const hashArray = Array.from(new Uint8Array(url_digest)); // convert buffer to byte array + const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); + //console.log(hashHex) + return hashHex +} +async function checkURL(URL){ + let str=URL; + let Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/; + let objExp=new RegExp(Expression); + if(objExp.test(str)==true){ + if (str[0] == 'h') + return true; + else + return false; + }else{ + return false; + } +} +async function save_url(URL){ + let random_key=await randomString() + let is_exist=await LINKS.get(random_key) + console.log(is_exist) + if (is_exist == null) + return await LINKS.put(random_key, URL),random_key + else + save_url(URL) +} +async function is_url_exist(url_sha512){ + let is_exist = await LINKS.get(url_sha512) + console.log(is_exist) + if (is_exist == null) { + return false + }else{ + return is_exist + } +} +async function is_url_safe(url){ + + let raw = JSON.stringify({"client":{"clientId":"Url-Shorten-Worker","clientVersion":"1.0.7"},"threatInfo":{"threatTypes":["MALWARE","SOCIAL_ENGINEERING","POTENTIALLY_HARMFUL_APPLICATION","UNWANTED_SOFTWARE"],"platformTypes":["ANY_PLATFORM"],"threatEntryTypes":["URL"],"threatEntries":[{"url":url}]}}); + + let requestOptions = { + method: 'POST', + body: raw, + redirect: 'follow' + }; + + result = await fetch("https://safebrowsing.googleapis.com/v4/threatMatches:find?key="+config.safe_browsing_api_key, requestOptions) + result = await result.json() + console.log(result) + if (Object.keys(result).length === 0){ + return true + }else{ + return false + } +} +async function handleRequest(request) { + console.log(request) + if (request.method === "POST") { + let req=await request.json() + console.log(req["url"]) + if(!await checkURL(req["url"])){ + return new Response(`{"status":500,"key":": 오류: Url 정보가 사기성이거나 바이러스가 있거나 올바르지 않습니다."}`, { + headers: response_header, + })} + let stat,random_key + if (config.unique_link){ + let url_sha512 = await sha512(req["url"]) + let url_key = await is_url_exist(url_sha512) + if(url_key){ + random_key = url_key + }else{ + stat,random_key=await save_url(req["url"]) + if (typeof(stat) == "undefined"){ + console.log(await LINKS.put(url_sha512,random_key)) + } + } + }else{ + stat,random_key=await save_url(req["url"]) + } + console.log(stat) + if (typeof(stat) == "undefined"){ + return new Response(`{"status":200,"key":"/`+random_key+`"}`, { + headers: response_header, + }) + }else{ + return new Response(`{"status":200,"key":": Error:Reach the KV write limitation."}`, { + headers: response_header, + })} + }else if(request.method === "OPTIONS"){ + return new Response(``, { + headers: response_header, + }) + + } + + const requestURL = new URL(request.url) + const path = requestURL.pathname.split("/")[1] + const params = requestURL.search; + + console.log(path) + if(!path){ + + const html= await fetch("https://tira-tw.github.io/korea-url/"+config.theme+"/index.html") + + return new Response(await html.text(), { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + } + + const value = await LINKS.get(path); + let location ; + + if(params) { + location = value + params + } else { + location = value + } + console.log(value) + + + if (location) { + if (config.safe_browsing_api_key){ + if(!(await is_url_safe(location))){ + let warning_page = await fetch("https://xytom.github.io/Url-Shorten-Worker/safe-browsing.html") + warning_page =await warning_page.text() + warning_page = warning_page.replace(/{Replace}/gm, location) + return new Response(warning_page, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + } + } + if (config.no_ref=="on"){ + let no_ref= await fetch("https://xytom.github.io/Url-Shorten-Worker/no-ref.html") + no_ref=await no_ref.text() + no_ref=no_ref.replace(/{Replace}/gm, location) + return new Response(no_ref, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + }else{ + return Response.redirect(location, 302) + } + + } + // If request not in kv, return 404 + return new Response(html404, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + status: 404 + }) +} + + + +addEventListener("fetch", async event => { + event.respondWith(handleRequest(event.request)) +}) diff --git "a/language/Korea/\354\204\244\354\240\225\355\225\230\353\212\224 \353\260\251\353\262\225.md" "b/language/Korea/\354\204\244\354\240\225\355\225\230\353\212\224 \353\260\251\353\262\225.md" new file mode 100644 index 00000000..5ce5857a --- /dev/null +++ "b/language/Korea/\354\204\244\354\240\225\355\225\230\353\212\224 \353\260\251\353\262\225.md" @@ -0,0 +1,2 @@ +index.js No.151의 링크를 다음 내용으로 변경합니다: +`https://tira-tw.github.io/korea-url/"+config.theme+"/index.html` diff --git a/language/Philippines/Paano i-set.md b/language/Philippines/Paano i-set.md new file mode 100644 index 00000000..d4835802 --- /dev/null +++ b/language/Philippines/Paano i-set.md @@ -0,0 +1,2 @@ +Baguhin ang link sa index.js No.151 sa sumusunod na nilalaman:
+`https://tira-tw.github.io/philippines-url/"+config.theme+"/index.html` diff --git a/language/Philippines/index.html b/language/Philippines/index.html new file mode 100644 index 00000000..cdedaf64 --- /dev/null +++ b/language/Philippines/index.html @@ -0,0 +1,110 @@ + + + + + + + Mas maikling URL + + + +
+
Paikliin ang iyong mga URL!
+
+
Mangyaring ipasok ang mahabang URL na paikliin :
+
+ +
+ +
+
+ +

+
+
+ + + + + + + diff --git a/language/Philippines/index.js b/language/Philippines/index.js new file mode 100644 index 00000000..aa1915f9 --- /dev/null +++ b/language/Philippines/index.js @@ -0,0 +1,211 @@ +const config = { +no_ref: "off", //Control the HTTP referrer header, if you want to create an anonymous link that will hide the HTTP Referer header, please set to "on" . +theme:"",//Homepage theme, use the empty value for default theme. To use urlcool theme, please fill with "theme/urlcool" . +cors: "on",//Allow Cross-origin resource sharing for API requests. +unique_link:true,//If it is true, the same long url will be shorten into the same short url +custom_link:false,//Allow users to customize the short url. +safe_browsing_api_key: "" //Enter Google Safe Browsing API Key to enable url safety check before redirect. +} + +const html404 = ` + +

404 Hindi Natagpuan.

+

Ang url na binibisita mo ay hindi nahanap.

+ gusto gumawa ng pareho? click! +` + +let response_header={ + "content-type": "text/html;charset=UTF-8", +} + +if (config.cors=="on"){ + response_header={ + "content-type": "text/html;charset=UTF-8", + "Access-Control-Allow-Origin":"*", + "Access-Control-Allow-Methods": "POST", + } +} + +async function randomString(len) { +  len = len || 6; +  let $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/ +  let maxPos = $chars.length; +  let result = ''; +  for (i = 0; i < len; i++) { +    result += $chars.charAt(Math.floor(Math.random() * maxPos)); +  } +  return result; +} + +async function sha512(url){ + url = new TextEncoder().encode(url) + + const url_digest = await crypto.subtle.digest( + { + name: "SHA-512", + }, + url, // The data you want to hash as an ArrayBuffer + ) + const hashArray = Array.from(new Uint8Array(url_digest)); // convert buffer to byte array + const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); + //console.log(hashHex) + return hashHex +} +async function checkURL(URL){ + let str=URL; + let Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/; + let objExp=new RegExp(Expression); + if(objExp.test(str)==true){ + if (str[0] == 'h') + return true; + else + return false; + }else{ + return false; + } +} +async function save_url(URL){ + let random_key=await randomString() + let is_exist=await LINKS.get(random_key) + console.log(is_exist) + if (is_exist == null) + return await LINKS.put(random_key, URL),random_key + else + save_url(URL) +} +async function is_url_exist(url_sha512){ + let is_exist = await LINKS.get(url_sha512) + console.log(is_exist) + if (is_exist == null) { + return false + }else{ + return is_exist + } +} +async function is_url_safe(url){ + + let raw = JSON.stringify({"client":{"clientId":"Url-Shorten-Worker","clientVersion":"1.0.7"},"threatInfo":{"threatTypes":["MALWARE","SOCIAL_ENGINEERING","POTENTIALLY_HARMFUL_APPLICATION","UNWANTED_SOFTWARE"],"platformTypes":["ANY_PLATFORM"],"threatEntryTypes":["URL"],"threatEntries":[{"url":url}]}}); + + let requestOptions = { + method: 'POST', + body: raw, + redirect: 'follow' + }; + + result = await fetch("https://safebrowsing.googleapis.com/v4/threatMatches:find?key="+config.safe_browsing_api_key, requestOptions) + result = await result.json() + console.log(result) + if (Object.keys(result).length === 0){ + return true + }else{ + return false + } +} +async function handleRequest(request) { + console.log(request) + if (request.method === "POST") { + let req=await request.json() + console.log(req["url"]) + if(!await checkURL(req["url"])){ + return new Response(`{"status":500,"key":": Error: Ang impormasyon ng Url ay maaaring website ng isda o virus o hindi ang url na ito"}`, { + headers: response_header, + })} + let stat,random_key + if (config.unique_link){ + let url_sha512 = await sha512(req["url"]) + let url_key = await is_url_exist(url_sha512) + if(url_key){ + random_key = url_key + }else{ + stat,random_key=await save_url(req["url"]) + if (typeof(stat) == "undefined"){ + console.log(await LINKS.put(url_sha512,random_key)) + } + } + }else{ + stat,random_key=await save_url(req["url"]) + } + console.log(stat) + if (typeof(stat) == "undefined"){ + return new Response(`{"status":200,"key":"/`+random_key+`"}`, { + headers: response_header, + }) + }else{ + return new Response(`{"status":200,"key":": Error:Reach the KV write limitation."}`, { + headers: response_header, + })} + }else if(request.method === "OPTIONS"){ + return new Response(``, { + headers: response_header, + }) + + } + + const requestURL = new URL(request.url) + const path = requestURL.pathname.split("/")[1] + const params = requestURL.search; + + console.log(path) + if(!path){ + + const html= await fetch("https://tira-tw.github.io/philippines-url/"+config.theme+"/index.html") + + return new Response(await html.text(), { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + } + + const value = await LINKS.get(path); + let location ; + + if(params) { + location = value + params + } else { + location = value + } + console.log(value) + + + if (location) { + if (config.safe_browsing_api_key){ + if(!(await is_url_safe(location))){ + let warning_page = await fetch("https://xytom.github.io/Url-Shorten-Worker/safe-browsing.html") + warning_page =await warning_page.text() + warning_page = warning_page.replace(/{Replace}/gm, location) + return new Response(warning_page, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + } + } + if (config.no_ref=="on"){ + let no_ref= await fetch("https://xytom.github.io/Url-Shorten-Worker/no-ref.html") + no_ref=await no_ref.text() + no_ref=no_ref.replace(/{Replace}/gm, location) + return new Response(no_ref, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + }else{ + return Response.redirect(location, 302) + } + + } + // If request not in kv, return 404 + return new Response(html404, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + status: 404 + }) +} + + + +addEventListener("fetch", async event => { + event.respondWith(handleRequest(event.request)) +}) diff --git a/language/README.md b/language/README.md new file mode 100644 index 00000000..2b62b589 --- /dev/null +++ b/language/README.md @@ -0,0 +1,24 @@ +[Discord](https://discord.gg/xDeaneQMj9)
+許多語言共有選擇
+many language can use
+本人只翻譯/host 想要提供不同語言.
+開源提供者 : https://github.com/xyTom/Url-Shorten-Worker

+ +------------------------------------------------------------- + +China/Taiwan簡體中文/繁體中文 : [Tira-tw](https://github.com/tira-tw)
+Korea韓國 : [아이바](https://steamcommunity.com/id/yelnya/)
+Indonesia印度尼西亞 : [Wmmt Mosto](https://www.facebook.com/100075041294054/)
+Vietnam越南 : [Allure](https://steamcommunity.com/profiles/76561199512754707/)
+Philippines菲律賓 : [Shuajo/twitch.tv/nanisufi](https://steamcommunity.com/id/09531080506) +![image](https://github.com/Tira-tw/cloudflare-host-url-language/assets/64715639/2d5192dc-a310-486e-8159-251a8ec0f38f) +![image](https://github.com/Tira-tw/cloudflare-host-url-language/assets/64715639/3e0b3f65-d892-4355-a5e9-e99c187a005c) +![image](https://github.com/Tira-tw/cloudflare-host-url-language/assets/64715639/0d3e2357-df55-4457-b533-cc8418ef3442) +![image](https://github.com/Tira-tw/cloudflare-host-url-language/assets/64715639/441a7936-f414-4b8e-94d3-dd546aed381f) +![image](https://github.com/Tira-tw/cloudflare-host-url-language/assets/64715639/7e4fdbe2-db82-4426-ab9a-5864e79cc41b) +![image](https://github.com/Tira-tw/cloudflare-host-url-language/assets/64715639/0f04eda6-6647-4d32-8784-049243c7bfbd) +![image](https://github.com/Tira-tw/cloudflare-host-url-language/assets/64715639/4bee9d7c-1cc6-48dd-a517-d8253b0d72f6) + + + + diff --git "a/language/Vietnam/C\303\241ch \304\221\341\273\203 ch\341\273\211nh s\341\273\255a.md" "b/language/Vietnam/C\303\241ch \304\221\341\273\203 ch\341\273\211nh s\341\273\255a.md" new file mode 100644 index 00000000..59553cdf --- /dev/null +++ "b/language/Vietnam/C\303\241ch \304\221\341\273\203 ch\341\273\211nh s\341\273\255a.md" @@ -0,0 +1,2 @@ +Thay đổi link trong index.js No.151 thành nội dung sau:
+`https://tira-tw.github.io/vietnam-url/"+config.theme+"/index.html` diff --git a/language/Vietnam/index.html b/language/Vietnam/index.html new file mode 100644 index 00000000..2786720f --- /dev/null +++ b/language/Vietnam/index.html @@ -0,0 +1,110 @@ + + + + + + + Link ngắn hơn + + + +
+
Làm ngắn link của bạn!
+
+
Nhập link của bạn để làm ngắn nó lại:
+
+ +
+ +
+
+ +

+
+
+ + + + + + + diff --git a/language/Vietnam/index.js b/language/Vietnam/index.js new file mode 100644 index 00000000..eae8a5a3 --- /dev/null +++ b/language/Vietnam/index.js @@ -0,0 +1,211 @@ +const config = { +no_ref: "off", //Control the HTTP referrer header, if you want to create an anonymous link that will hide the HTTP Referer header, please set to "on" . +theme:"",//Homepage theme, use the empty value for default theme. To use urlcool theme, please fill with "theme/urlcool" . +cors: "on",//Allow Cross-origin resource sharing for API requests. +unique_link:true,//If it is true, the same long url will be shorten into the same short url +custom_link:false,//Allow users to customize the short url. +safe_browsing_api_key: "" //Enter Google Safe Browsing API Key to enable url safety check before redirect. +} + +const html404 = ` + +

404 không thể tìm thấy

+

Link bạn truy cập không được tìm thấy

+ Muốn làm một cái tương tự? Nhấn vào! +` + +let response_header={ + "content-type": "text/html;charset=UTF-8", +} + +if (config.cors=="on"){ + response_header={ + "content-type": "text/html;charset=UTF-8", + "Access-Control-Allow-Origin":"*", + "Access-Control-Allow-Methods": "POST", + } +} + +async function randomString(len) { +  len = len || 6; +  let $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/ +  let maxPos = $chars.length; +  let result = ''; +  for (i = 0; i < len; i++) { +    result += $chars.charAt(Math.floor(Math.random() * maxPos)); +  } +  return result; +} + +async function sha512(url){ + url = new TextEncoder().encode(url) + + const url_digest = await crypto.subtle.digest( + { + name: "SHA-512", + }, + url, // The data you want to hash as an ArrayBuffer + ) + const hashArray = Array.from(new Uint8Array(url_digest)); // convert buffer to byte array + const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); + //console.log(hashHex) + return hashHex +} +async function checkURL(URL){ + let str=URL; + let Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/; + let objExp=new RegExp(Expression); + if(objExp.test(str)==true){ + if (str[0] == 'h') + return true; + else + return false; + }else{ + return false; + } +} +async function save_url(URL){ + let random_key=await randomString() + let is_exist=await LINKS.get(random_key) + console.log(is_exist) + if (is_exist == null) + return await LINKS.put(random_key, URL),random_key + else + save_url(URL) +} +async function is_url_exist(url_sha512){ + let is_exist = await LINKS.get(url_sha512) + console.log(is_exist) + if (is_exist == null) { + return false + }else{ + return is_exist + } +} +async function is_url_safe(url){ + + let raw = JSON.stringify({"client":{"clientId":"Url-Shorten-Worker","clientVersion":"1.0.7"},"threatInfo":{"threatTypes":["MALWARE","SOCIAL_ENGINEERING","POTENTIALLY_HARMFUL_APPLICATION","UNWANTED_SOFTWARE"],"platformTypes":["ANY_PLATFORM"],"threatEntryTypes":["URL"],"threatEntries":[{"url":url}]}}); + + let requestOptions = { + method: 'POST', + body: raw, + redirect: 'follow' + }; + + result = await fetch("https://safebrowsing.googleapis.com/v4/threatMatches:find?key="+config.safe_browsing_api_key, requestOptions) + result = await result.json() + console.log(result) + if (Object.keys(result).length === 0){ + return true + }else{ + return false + } +} +async function handleRequest(request) { + console.log(request) + if (request.method === "POST") { + let req=await request.json() + console.log(req["url"]) + if(!await checkURL(req["url"])){ + return new Response(`{"status":500,"key":": Lỗi: thông tin về link là web lậu hoặc virus hoặc không phải link này"}`, { + headers: response_header, + })} + let stat,random_key + if (config.unique_link){ + let url_sha512 = await sha512(req["url"]) + let url_key = await is_url_exist(url_sha512) + if(url_key){ + random_key = url_key + }else{ + stat,random_key=await save_url(req["url"]) + if (typeof(stat) == "undefined"){ + console.log(await LINKS.put(url_sha512,random_key)) + } + } + }else{ + stat,random_key=await save_url(req["url"]) + } + console.log(stat) + if (typeof(stat) == "undefined"){ + return new Response(`{"status":200,"key":"/`+random_key+`"}`, { + headers: response_header, + }) + }else{ + return new Response(`{"status":200,"key":": Error:Reach the KV write limitation."}`, { + headers: response_header, + })} + }else if(request.method === "OPTIONS"){ + return new Response(``, { + headers: response_header, + }) + + } + + const requestURL = new URL(request.url) + const path = requestURL.pathname.split("/")[1] + const params = requestURL.search; + + console.log(path) + if(!path){ + + const html= await fetch("https://tira-tw.github.io/vietnam-url/"+config.theme+"/index.html") + + return new Response(await html.text(), { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + } + + const value = await LINKS.get(path); + let location ; + + if(params) { + location = value + params + } else { + location = value + } + console.log(value) + + + if (location) { + if (config.safe_browsing_api_key){ + if(!(await is_url_safe(location))){ + let warning_page = await fetch("https://xytom.github.io/Url-Shorten-Worker/safe-browsing.html") + warning_page =await warning_page.text() + warning_page = warning_page.replace(/{Replace}/gm, location) + return new Response(warning_page, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + } + } + if (config.no_ref=="on"){ + let no_ref= await fetch("https://xytom.github.io/Url-Shorten-Worker/no-ref.html") + no_ref=await no_ref.text() + no_ref=no_ref.replace(/{Replace}/gm, location) + return new Response(no_ref, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + }else{ + return Response.redirect(location, 302) + } + + } + // If request not in kv, return 404 + return new Response(html404, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + status: 404 + }) +} + + + +addEventListener("fetch", async event => { + event.respondWith(handleRequest(event.request)) +}) diff --git a/language/chinese-zh-cn/index.html b/language/chinese-zh-cn/index.html new file mode 100644 index 00000000..f0be2982 --- /dev/null +++ b/language/chinese-zh-cn/index.html @@ -0,0 +1,111 @@ + + + + + + + 缩短网址 + + + +
+
缩短你的网址!
+
+
请贴上你要缩短的网址:
+
+ +
+ +
+
+ +

+
+
+ + + + + + + diff --git a/language/chinese-zh-cn/index.js b/language/chinese-zh-cn/index.js new file mode 100644 index 00000000..bd556d76 --- /dev/null +++ b/language/chinese-zh-cn/index.js @@ -0,0 +1,211 @@ +const config = { +no_ref: "off", //Control the HTTP referrer header, if you want to create an anonymous link that will hide the HTTP Referer header, please set to "on" . +theme:"",//Homepage theme, use the empty value for default theme. To use urlcool theme, please fill with "theme/urlcool" . +cors: "on",//Allow Cross-origin resource sharing for API requests. +unique_link:true,//If it is true, the same long url will be shorten into the same short url +custom_link:false,//Allow users to customize the short url. +safe_browsing_api_key: "" //Enter Google Safe Browsing API Key to enable url safety check before redirect. +} + +const html404 = ` + +

404 找不到档案!

+

您的提供的网址无法搜寻!,请确定是否正确.

+ 是否想制作一个? 点击我! +` + +let response_header={ + "content-type": "text/html;charset=UTF-8", +} + +if (config.cors=="on"){ + response_header={ + "content-type": "text/html;charset=UTF-8", + "Access-Control-Allow-Origin":"*", + "Access-Control-Allow-Methods": "POST", + } +} + +async function randomString(len) { +  len = len || 6; +  let $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/ +  let maxPos = $chars.length; +  let result = ''; +  for (i = 0; i < len; i++) { +    result += $chars.charAt(Math.floor(Math.random() * maxPos)); +  } +  return result; +} + +async function sha512(url){ + url = new TextEncoder().encode(url) + + const url_digest = await crypto.subtle.digest( + { + name: "SHA-512", + }, + url, // The data you want to hash as an ArrayBuffer + ) + const hashArray = Array.from(new Uint8Array(url_digest)); // convert buffer to byte array + const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); + //console.log(hashHex) + return hashHex +} +async function checkURL(URL){ + let str=URL; + let Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/; + let objExp=new RegExp(Expression); + if(objExp.test(str)==true){ + if (str[0] == 'h') + return true; + else + return false; + }else{ + return false; + } +} +async function save_url(URL){ + let random_key=await randomString() + let is_exist=await LINKS.get(random_key) + console.log(is_exist) + if (is_exist == null) + return await LINKS.put(random_key, URL),random_key + else + save_url(URL) +} +async function is_url_exist(url_sha512){ + let is_exist = await LINKS.get(url_sha512) + console.log(is_exist) + if (is_exist == null) { + return false + }else{ + return is_exist + } +} +async function is_url_safe(url){ + + let raw = JSON.stringify({"client":{"clientId":"Url-Shorten-Worker","clientVersion":"1.0.7"},"threatInfo":{"threatTypes":["MALWARE","SOCIAL_ENGINEERING","POTENTIALLY_HARMFUL_APPLICATION","UNWANTED_SOFTWARE"],"platformTypes":["ANY_PLATFORM"],"threatEntryTypes":["URL"],"threatEntries":[{"url":url}]}}); + + let requestOptions = { + method: 'POST', + body: raw, + redirect: 'follow' + }; + + result = await fetch("https://safebrowsing.googleapis.com/v4/threatMatches:find?key="+config.safe_browsing_api_key, requestOptions) + result = await result.json() + console.log(result) + if (Object.keys(result).length === 0){ + return true + }else{ + return false + } +} +async function handleRequest(request) { + console.log(request) + if (request.method === "POST") { + let req=await request.json() + console.log(req["url"]) + if(!await checkURL(req["url"])){ + return new Response(`{"status":500,"key":": 错误! 你提供的网址可能是钓鱼网站/病毒/不存在!"}`, { + headers: response_header, + })} + let stat,random_key + if (config.unique_link){ + let url_sha512 = await sha512(req["url"]) + let url_key = await is_url_exist(url_sha512) + if(url_key){ + random_key = url_key + }else{ + stat,random_key=await save_url(req["url"]) + if (typeof(stat) == "undefined"){ + console.log(await LINKS.put(url_sha512,random_key)) + } + } + }else{ + stat,random_key=await save_url(req["url"]) + } + console.log(stat) + if (typeof(stat) == "undefined"){ + return new Response(`{"status":200,"key":"/`+random_key+`"}`, { + headers: response_header, + }) + }else{ + return new Response(`{"status":200,"key":": Error:Reach the KV write limitation."}`, { + headers: response_header, + })} + }else if(request.method === "OPTIONS"){ + return new Response(``, { + headers: response_header, + }) + + } + + const requestURL = new URL(request.url) + const path = requestURL.pathname.split("/")[1] + const params = requestURL.search; + + console.log(path) + if(!path){ + + const html= await fetch("https://tira-tw.github.io/china-url/"+config.theme+"/index.html") + + return new Response(await html.text(), { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + } + + const value = await LINKS.get(path); + let location ; + + if(params) { + location = value + params + } else { + location = value + } + console.log(value) + + + if (location) { + if (config.safe_browsing_api_key){ + if(!(await is_url_safe(location))){ + let warning_page = await fetch("https://xytom.github.io/Url-Shorten-Worker/safe-browsing.html") + warning_page =await warning_page.text() + warning_page = warning_page.replace(/{Replace}/gm, location) + return new Response(warning_page, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + } + } + if (config.no_ref=="on"){ + let no_ref= await fetch("https://xytom.github.io/Url-Shorten-Worker/no-ref.html") + no_ref=await no_ref.text() + no_ref=no_ref.replace(/{Replace}/gm, location) + return new Response(no_ref, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + }else{ + return Response.redirect(location, 302) + } + + } + // If request not in kv, return 404 + return new Response(html404, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + status: 404 + }) +} + + + +addEventListener("fetch", async event => { + event.respondWith(handleRequest(event.request)) +}) diff --git "a/language/chinese-zh-cn/\345\246\202\344\275\225\350\256\276\345\256\232.md" "b/language/chinese-zh-cn/\345\246\202\344\275\225\350\256\276\345\256\232.md" new file mode 100644 index 00000000..25331a5f --- /dev/null +++ "b/language/chinese-zh-cn/\345\246\202\344\275\225\350\256\276\345\256\232.md" @@ -0,0 +1,2 @@ +index.js第151中间的连结改掉以下:
+`https://tira-tw.github.io/china-url/"+config.theme+"/index.html` diff --git a/language/chinese-zh-tw/index.html b/language/chinese-zh-tw/index.html new file mode 100644 index 00000000..8fb4bd21 --- /dev/null +++ b/language/chinese-zh-tw/index.html @@ -0,0 +1,111 @@ + + + + + + + 縮短網址 + + + +
+
縮短你的網址!
+
+
請貼上你要縮短的網址:
+
+ +
+ +
+
+ +

+
+
+ + + + + + + diff --git a/language/chinese-zh-tw/index.js b/language/chinese-zh-tw/index.js new file mode 100644 index 00000000..35eccca4 --- /dev/null +++ b/language/chinese-zh-tw/index.js @@ -0,0 +1,211 @@ +const config = { +no_ref: "off", //Control the HTTP referrer header, if you want to create an anonymous link that will hide the HTTP Referer header, please set to "on" . +theme:"",//Homepage theme, use the empty value for default theme. To use urlcool theme, please fill with "theme/urlcool" . +cors: "on",//Allow Cross-origin resource sharing for API requests. +unique_link:true,//If it is true, the same long url will be shorten into the same short url +custom_link:false,//Allow users to customize the short url. +safe_browsing_api_key: "" //Enter Google Safe Browsing API Key to enable url safety check before redirect. +} + +const html404 = ` + +

404 找不到檔案!

+

您的提供的網址無法搜尋!,請確定是否正確.

+ 是否想製作一個? 點擊我! +` + +let response_header={ + "content-type": "text/html;charset=UTF-8", +} + +if (config.cors=="on"){ + response_header={ + "content-type": "text/html;charset=UTF-8", + "Access-Control-Allow-Origin":"*", + "Access-Control-Allow-Methods": "POST", + } +} + +async function randomString(len) { +  len = len || 6; +  let $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/ +  let maxPos = $chars.length; +  let result = ''; +  for (i = 0; i < len; i++) { +    result += $chars.charAt(Math.floor(Math.random() * maxPos)); +  } +  return result; +} + +async function sha512(url){ + url = new TextEncoder().encode(url) + + const url_digest = await crypto.subtle.digest( + { + name: "SHA-512", + }, + url, // The data you want to hash as an ArrayBuffer + ) + const hashArray = Array.from(new Uint8Array(url_digest)); // convert buffer to byte array + const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); + //console.log(hashHex) + return hashHex +} +async function checkURL(URL){ + let str=URL; + let Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/; + let objExp=new RegExp(Expression); + if(objExp.test(str)==true){ + if (str[0] == 'h') + return true; + else + return false; + }else{ + return false; + } +} +async function save_url(URL){ + let random_key=await randomString() + let is_exist=await LINKS.get(random_key) + console.log(is_exist) + if (is_exist == null) + return await LINKS.put(random_key, URL),random_key + else + save_url(URL) +} +async function is_url_exist(url_sha512){ + let is_exist = await LINKS.get(url_sha512) + console.log(is_exist) + if (is_exist == null) { + return false + }else{ + return is_exist + } +} +async function is_url_safe(url){ + + let raw = JSON.stringify({"client":{"clientId":"Url-Shorten-Worker","clientVersion":"1.0.7"},"threatInfo":{"threatTypes":["MALWARE","SOCIAL_ENGINEERING","POTENTIALLY_HARMFUL_APPLICATION","UNWANTED_SOFTWARE"],"platformTypes":["ANY_PLATFORM"],"threatEntryTypes":["URL"],"threatEntries":[{"url":url}]}}); + + let requestOptions = { + method: 'POST', + body: raw, + redirect: 'follow' + }; + + result = await fetch("https://safebrowsing.googleapis.com/v4/threatMatches:find?key="+config.safe_browsing_api_key, requestOptions) + result = await result.json() + console.log(result) + if (Object.keys(result).length === 0){ + return true + }else{ + return false + } +} +async function handleRequest(request) { + console.log(request) + if (request.method === "POST") { + let req=await request.json() + console.log(req["url"]) + if(!await checkURL(req["url"])){ + return new Response(`{"status":500,"key":": 錯誤! 你提供的網址可能是釣魚網站/病毒/不存在!"}`, { + headers: response_header, + })} + let stat,random_key + if (config.unique_link){ + let url_sha512 = await sha512(req["url"]) + let url_key = await is_url_exist(url_sha512) + if(url_key){ + random_key = url_key + }else{ + stat,random_key=await save_url(req["url"]) + if (typeof(stat) == "undefined"){ + console.log(await LINKS.put(url_sha512,random_key)) + } + } + }else{ + stat,random_key=await save_url(req["url"]) + } + console.log(stat) + if (typeof(stat) == "undefined"){ + return new Response(`{"status":200,"key":"/`+random_key+`"}`, { + headers: response_header, + }) + }else{ + return new Response(`{"status":200,"key":": Error:Reach the KV write limitation."}`, { + headers: response_header, + })} + }else if(request.method === "OPTIONS"){ + return new Response(``, { + headers: response_header, + }) + + } + + const requestURL = new URL(request.url) + const path = requestURL.pathname.split("/")[1] + const params = requestURL.search; + + console.log(path) + if(!path){ + + const html= await fetch("https://tira-tw.github.io/taiwan-url/"+config.theme+"/index.html") + + return new Response(await html.text(), { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + } + + const value = await LINKS.get(path); + let location ; + + if(params) { + location = value + params + } else { + location = value + } + console.log(value) + + + if (location) { + if (config.safe_browsing_api_key){ + if(!(await is_url_safe(location))){ + let warning_page = await fetch("https://xytom.github.io/Url-Shorten-Worker/safe-browsing.html") + warning_page =await warning_page.text() + warning_page = warning_page.replace(/{Replace}/gm, location) + return new Response(warning_page, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + } + } + if (config.no_ref=="on"){ + let no_ref= await fetch("https://xytom.github.io/Url-Shorten-Worker/no-ref.html") + no_ref=await no_ref.text() + no_ref=no_ref.replace(/{Replace}/gm, location) + return new Response(no_ref, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + }) + }else{ + return Response.redirect(location, 302) + } + + } + // If request not in kv, return 404 + return new Response(html404, { + headers: { + "content-type": "text/html;charset=UTF-8", + }, + status: 404 + }) +} + + + +addEventListener("fetch", async event => { + event.respondWith(handleRequest(event.request)) +}) diff --git "a/language/chinese-zh-tw/\345\246\202\344\275\225\350\250\255\345\256\232.md" "b/language/chinese-zh-tw/\345\246\202\344\275\225\350\250\255\345\256\232.md" new file mode 100644 index 00000000..ace913f9 --- /dev/null +++ "b/language/chinese-zh-tw/\345\246\202\344\275\225\350\250\255\345\256\232.md" @@ -0,0 +1,2 @@ +index.js第151中間的連結改掉以下:
+`https://tira-tw.github.io/taiwan-url/"+config.theme+"/index.html`