From 129ce8f772f498afb87dcfbfdee81932ef2fed9d Mon Sep 17 00:00:00 2001 From: alyssadev Date: Mon, 18 Sep 2023 05:22:43 +1000 Subject: [PATCH] don't shorten url if dest path is on same service. also default mime type --- src/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 5c1b6af..787661f 100644 --- a/src/index.js +++ b/src/index.js @@ -47,13 +47,19 @@ async function add(request,host,path) { const dest = data.get("u") console.log(dest) try { - new URL(dest) - await KV.put(path, 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});