diff --git a/mimeul b/mimeul new file mode 100644 index 0000000..7f70e71 --- /dev/null +++ b/mimeul @@ -0,0 +1,3 @@ +#!/bin/bash +MIME=$(file -i "$1" | cut -f1 -d" " --complement) +curl -H "Authorization: $AUTH_KEY" $DEPLOY_HOST/$2 -F "u=@$1;type=$MIME" diff --git a/src/index.js b/src/index.js index 7953917..a72289a 100644 --- a/src/index.js +++ b/src/index.js @@ -58,8 +58,8 @@ async function add(request,host,path) { } catch (e) { if (e instanceof TypeError) { if (!dest) return new Response("No file provided", {status:400}) - await FILES.put(path, dest) - await KV.put(path,dest.type) + await FILES.put(path, dest, { httpMetadata: {contentType: dest.type}}) + await KV.delete(path) return new Response(`https://${host}/${path}`, {status:201}) } else throw e; @@ -92,16 +92,9 @@ async function get(request,host,path) { const dest_file = await FILES.get(path) if (dest_file) { - const mime = await KV.get(path) const headers = new Headers() dest_file.writeHttpMetadata(headers) headers.set("etag", dest_file.httpEtag) - if (mime.startsWith("text/")) { - headers.set("content-type", "text/plain") - headers.set("x-content-type", mime) - } else { - headers.set("content-type", mime) - } return new Response(dest_file.body, { headers, } ) } const dest = await KV.get(path)