summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Hurst <julian.hurst@digdash.com>2025-01-23 16:09:39 +0100
committerJulian Hurst <julian.hurst@digdash.com>2025-01-23 16:09:39 +0100
commit6ababe78852e5e2398fe5cb125cba7a0c9e6b44e (patch)
tree8a9cb59f54c13ad0000181e1cb365d025b4fa58a
parent634a9911e6828a20ed898aabce1f6302ebcf2f54 (diff)
downloadbox-6ababe78852e5e2398fe5cb125cba7a0c9e6b44e.tar.gz
Add metadata support for specifying the extension
-rw-r--r--main.go3
-rw-r--r--templates/index.html6
2 files changed, 7 insertions, 2 deletions
diff --git a/main.go b/main.go
index ce9a0ab..68037e8 100644
--- a/main.go
+++ b/main.go
@@ -86,6 +86,7 @@ func (handler BoxHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusUnauthorized)
return
}
+ ext := r.Header.Get("X-ResourceMeta-Extension")
u, err := uuid.NewRandom()
if err != nil {
log.Println(err)
@@ -93,7 +94,7 @@ func (handler BoxHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
return
}
- filename := filepath.Join(handler.filesPath, u.String())
+ filename := filepath.Join(handler.filesPath, u.String()) + ext
log.Printf("Boxing %s...\n", filename)
f, err := os.Create(filename)
if err != nil {
diff --git a/templates/index.html b/templates/index.html
index 3291d8e..0186d89 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -37,7 +37,11 @@
}
}
xhr.open("POST", "/upload", true);
- xhr.setRequestHeader("X-Token", token)
+ xhr.setRequestHeader("X-Token", token);
+ ldot = f.name.lastIndexOf(".");
+ if (ldot > -1) {
+ xhr.setRequestHeader("X-ResourceMeta-Extension", f.name.substring(ldot))
+ }
xhr.send(f)
}
</script>