diff --git a/internal/web/web.go b/internal/web/web.go index 2945104..a227152 100644 --- a/internal/web/web.go +++ b/internal/web/web.go @@ -32,7 +32,7 @@ func StartWebserver(addr string, client client.Client, username, password string http.ServeFile(w, r, "./public/index.html") }) - r.HandleFunc("/s/{slug:[a-zA-Z0-9]{6}}", func(w http.ResponseWriter, r *http.Request) { + r.HandleFunc("/s/{path:.{6,}}", func(w http.ResponseWriter, r *http.Request) { share := getShareHead(client, w, r) if share == nil { return @@ -48,12 +48,12 @@ func StartWebserver(addr string, client client.Client, username, password string _, err = io.Copy(w, obj) if err != nil { - w.WriteHeader(http.StatusInternalServerError) + logrus.Error(err.Error()) return } }) - r.HandleFunc("/s/{slug:[a-zA-Z0-9]{6}}", func(w http.ResponseWriter, r *http.Request) { + r.HandleFunc("/s/{path:.{6,}}", func(w http.ResponseWriter, r *http.Request) { getShareHead(client, w, r) }).Methods("HEAD") @@ -119,8 +119,8 @@ func StartWebserver(addr string, client client.Client, username, password string func getShareHead(client client.Client, w http.ResponseWriter, r *http.Request) *types.Share { vars := mux.Vars(r) - - share, err := client.GetShare(r.Context(), vars["slug"]) + slug := vars["path"][0:6] + share, err := client.GetShare(r.Context(), slug) if err != nil { logrus.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -139,9 +139,12 @@ func getShareHead(client client.Client, w http.ResponseWriter, r *http.Request) return nil } - w.Header().Set("Content-Type", metadata.ContentType) + // Prevent using the default Content-Type. Can cause some confusion when the browser tries to open images in a new tab. + if metadata.ContentType != "application/octet-stream" { + w.Header().Set("Content-Type", metadata.ContentType) + } w.Header().Set("Content-Length", strconv.FormatInt(metadata.Size, 10)) - w.Header().Set("Content-Disposition", "attachment; filename=\""+metadata.Filename+"\"") + w.Header().Set("Content-Disposition", "inline; filename=\""+metadata.Filename+"\"") if metadata.ETag != "" { w.Header().Set("ETag", metadata.ETag) } diff --git a/web/App.svelte b/web/App.svelte index c62a50d..60c3e69 100644 --- a/web/App.svelte +++ b/web/App.svelte @@ -37,7 +37,7 @@ {#if !notFound}
{/if}