don't shorten url if dest path is on same service. also default mime type
This commit is contained in:
parent
0288bb6e02
commit
129ce8f772
10
src/index.js
10
src/index.js
|
@ -47,13 +47,19 @@ async function add(request,host,path) {
|
||||||
const dest = data.get("u")
|
const dest = data.get("u")
|
||||||
console.log(dest)
|
console.log(dest)
|
||||||
try {
|
try {
|
||||||
new URL(dest)
|
var u = new URL(dest)
|
||||||
await KV.put(path, dest)
|
if (u.host !== host) {
|
||||||
|
await KV.put(path, dest)
|
||||||
|
} else {
|
||||||
|
path = u.pathname.split("/")[1]
|
||||||
|
}
|
||||||
await FILES.delete(path)
|
await FILES.delete(path)
|
||||||
return new Response(`https://${host}/${path}`, {status:201})
|
return new Response(`https://${host}/${path}`, {status:201})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof TypeError) {
|
if (e instanceof TypeError) {
|
||||||
await FILES.put(path, dest)
|
await FILES.put(path, dest)
|
||||||
|
var type = dest.type
|
||||||
|
if (type === "undefined") type = "text/plain" // dammit sharex
|
||||||
await KV.put(path,dest.type)
|
await KV.put(path,dest.type)
|
||||||
return new Response(`https://${host}/${path}`, {status:201})
|
return new Response(`https://${host}/${path}`, {status:201})
|
||||||
// return new Response("No valid URL provided",{status:400});
|
// return new Response("No valid URL provided",{status:400});
|
||||||
|
|
Loading…
Reference in a new issue