Skip to content
Snippets Groups Projects
Commit 3391f257 authored by Jiwon Sheen's avatar Jiwon Sheen
Browse files

edit short-url code

parent 4ce7ca96
No related branches found
No related tags found
No related merge requests found
Pipeline #11114 passed
......@@ -37,9 +37,15 @@ export default {
console.log(`search: ${search}`);
if (search[0] === '?') {
let key = generateRandomString(6);
let key;
if (pathname.length >= 2) {
key = pathname.substr(1);
}
else {
key = generateRandomString(6);
while (await env.KV_STORAGE.get(key) !== null)
key = generateRandomString(6);
}
await env.KV_STORAGE.put(key, search.substr(1));
return new Response(`<a href=${protocol}//${host}/${key}>${protocol}//${host}/${key}</a>`, { headers: { 'Content-Type': 'text/html'}});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment