Share links now use .pdf extension and Content-Disposition header for Android compatibility

This commit is contained in:
James 2026-02-10 00:33:13 -05:00
parent a77a31f4c9
commit 5445b294cb
1 changed files with 8 additions and 1 deletions

View File

@ -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
} }