fixed bug with case sensitivity

This commit is contained in:
alyssadev 2023-09-17 05:34:04 +10:00
parent df82248ecf
commit 94eb26fa59
2 changed files with 5 additions and 2 deletions

View file

@ -23,6 +23,6 @@ EOF
linkie/path => http://example.comhttp//example.com?2 linkie/path => http://example.comhttp//example.com?2
``` ```
`curl -n -d u=http://example.com linkie/_`, if you provide an underscore as the path linkie will generate a four character path from a-zA-Z. if it has a collision five times in a row it'll return 500.. at that point i'd probably increase the length of the random ids in the function at the top of index.js to 5 or something, and also i should get off the internet because i've generated 52^4 short urls with this service and that's insane `curl -n -d u=http://example.com linkie/_`, if you provide an underscore as the path linkie will generate a four character path from a-z0-9. if it has a collision five times in a row it'll return 500.. at that point i'd probably increase the length of the random ids in the function at the top of index.js to 5 or something, and also i should get off the internet because i've generated 36^4 short urls with this service and that's insane
See test.py for more usage and test cases See test.py for more usage and test cases

View file

@ -2,7 +2,7 @@
function makeid(length) { function makeid(length) {
let result = ''; let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length; const charactersLength = characters.length;
let counter = 0; let counter = 0;
while (counter < length) { while (counter < length) {
@ -45,12 +45,14 @@ async function add(host,path,request) {
x += 1 x += 1
} }
} }
path = path.toLowerCase()
await KV.put(path, dest) await KV.put(path, dest)
return new Response(`https://${host}/${path}`, {status:201}) return new Response(`https://${host}/${path}`, {status:201})
} }
async function remove(host,path) { async function remove(host,path) {
if (!path) return new Response("No path provided",{status:400}) if (!path) return new Response("No path provided",{status:400})
path = path.toLowerCase()
await KV.delete(path) await KV.delete(path)
return new Response(`DELETE https://${host}/${path}`, {status:200}) return new Response(`DELETE https://${host}/${path}`, {status:200})
} }
@ -63,6 +65,7 @@ async function get(host,path,auth) {
return new Response(paths,{status:200}) return new Response(paths,{status:200})
} }
if (!path) return Response.redirect("https://aly-smith.carrd.co",301) if (!path) return Response.redirect("https://aly-smith.carrd.co",301)
path = path.toLowerCase()
const dest = await KV.get(path) const dest = await KV.get(path)
if (dest) return Response.redirect(dest, 302) if (dest) return Response.redirect(dest, 302)
return new Response("Path not found", {status:404}) return new Response("Path not found", {status:404})