improved opening images
This commit is contained in:
parent
1ee9916970
commit
f31f1bbf02
@ -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)
|
||||
}
|
||||
|
@ -37,7 +37,7 @@
|
||||
|
||||
{#if !notFound}
|
||||
<div class="dl">
|
||||
<a href="/s/{slug}">Download ({sizeToReadable(fileSize)})</a>
|
||||
<a download href="/s/{slug}">Download ({sizeToReadable(fileSize)})</a>
|
||||
</div>
|
||||
{/if}
|
||||
<main>
|
||||
|
@ -2,9 +2,11 @@
|
||||
export let contentType: string;
|
||||
export let filename: string;
|
||||
export let slug: string;
|
||||
|
||||
let ext = filename.split('.').pop();
|
||||
</script>
|
||||
|
||||
<img src="/s/{slug}" alt="shared" />
|
||||
<img src="/s/{slug}.{ext}" alt="shared" />
|
||||
|
||||
<style>
|
||||
img {
|
||||
|
Loading…
Reference in New Issue
Block a user