Share links now use .pdf extension and Content-Disposition header for Android compatibility
This commit is contained in:
parent
a77a31f4c9
commit
5445b294cb
9
main.go
9
main.go
|
|
@ -576,7 +576,7 @@ func createShareHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(map[string]string{
|
json.NewEncoder(w).Encode(map[string]string{
|
||||||
"token": token,
|
"token": token,
|
||||||
"url": "/s/" + token,
|
"url": "/s/" + token + ".pdf",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -602,6 +602,7 @@ func listSharesHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func publicShareHandler(w http.ResponseWriter, r *http.Request) {
|
func publicShareHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
token := chi.URLParam(r, "token")
|
token := chi.URLParam(r, "token")
|
||||||
|
token = strings.TrimSuffix(token, ".pdf")
|
||||||
doc, err := GetShare(token)
|
doc, err := GetShare(token)
|
||||||
if err != nil || doc == nil {
|
if err != nil || doc == nil {
|
||||||
http.Error(w, "Not found", http.StatusNotFound)
|
http.Error(w, "Not found", http.StatusNotFound)
|
||||||
|
|
@ -617,6 +618,12 @@ func publicShareHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
} else {
|
} else {
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
w.Header().Set("Content-Type", "text/plain")
|
||||||
}
|
}
|
||||||
|
// Set filename so Android/browsers handle it properly
|
||||||
|
filename := strings.ReplaceAll(doc.Title, " ", "-") + ext
|
||||||
|
if ext == "" {
|
||||||
|
filename += ".pdf"
|
||||||
|
}
|
||||||
|
w.Header().Set("Content-Disposition", fmt.Sprintf(`inline; filename="%s"`, filename))
|
||||||
http.ServeFile(w, r, path)
|
http.ServeFile(w, r, path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue