diff --git a/server/public/handle_streams.go b/server/public/handle_streams.go index c7b8a4d4f..01552464e 100644 --- a/server/public/handle_streams.go +++ b/server/public/handle_streams.go @@ -2,10 +2,13 @@ package public import ( "errors" + "fmt" "net/http" "strconv" + "strings" "time" + "github.com/navidrome/navidrome/conf" "github.com/navidrome/navidrome/core/auth" streampkg "github.com/navidrome/navidrome/core/stream" "github.com/navidrome/navidrome/log" @@ -72,6 +75,10 @@ func (pub *Router) handleStream(w http.ResponseWriter, r *http.Request) { w.Header().Set("X-Content-Type-Options", "nosniff") w.Header().Set("X-Content-Duration", strconv.FormatFloat(float64(stream.Duration()), 'G', -1, 32)) + if conf.Server.EnableDownloads && p.BoolOr("download", false) { + w.Header().Set("Content-Disposition", "attachment; filename=\""+downloadFilename(mf, info.format)+"\"") + } + n, err := stream.Serve(ctx, w, r) if err != nil || n == 0 { http.Error(w, "internal error", http.StatusInternalServerError) @@ -100,3 +107,15 @@ func decodeStreamInfo(tokenString string) (shareTrackInfo, error) { shareID: c.ShareID, }, nil } + +func sanitizeName(target string) string { + return strings.ReplaceAll(target, "/", "_") +} + +func downloadFilename(mf *model.MediaFile, format string) string { + ext := mf.Suffix + if format != "" && format != "raw" { + ext = format + } + return fmt.Sprintf("%s - %s.%s", sanitizeName(mf.Artist), sanitizeName(mf.Title), ext) +} diff --git a/server/serve_index.go b/server/serve_index.go index 13fa4a9ce..e0a62a997 100644 --- a/server/serve_index.go +++ b/server/serve_index.go @@ -160,6 +160,9 @@ func addShareData(r *http.Request, data map[string]any, shareInfo *model.Share) Description: shareInfo.Description, Downloadable: shareInfo.Downloadable, } + if sd.Description == "" { + sd.Description = shareInfo.Contents + } sd.Tracks = slice.Map(shareInfo.Tracks, func(mf model.MediaFile) shareTrack { return shareTrack{ ID: mf.ID, diff --git a/ui/index.html b/ui/index.html index 827751856..55a6fc572 100644 --- a/ui/index.html +++ b/ui/index.html @@ -26,7 +26,7 @@ -