don't shorten url if dest path is on same service. also default mime type

This commit is contained in:
alyssadev 2023-09-18 05:22:43 +10:00
parent 0288bb6e02
commit 129ce8f772

View file

@ -47,13 +47,19 @@ async function add(request,host,path) {
const dest = data.get("u")
console.log(dest)
try {
new URL(dest)
var u = new URL(dest)
if (u.host !== host) {
await KV.put(path, dest)
} else {
path = u.pathname.split("/")[1]
}
await FILES.delete(path)
return new Response(`https://${host}/${path}`, {status:201})
} catch (e) {
if (e instanceof TypeError) {
await FILES.put(path, dest)
var type = dest.type
if (type === "undefined") type = "text/plain" // dammit sharex
await KV.put(path,dest.type)
return new Response(`https://${host}/${path}`, {status:201})
// return new Response("No valid URL provided",{status:400});