refactor(coverart): one image Content-Type table for /api and Subsonic (#8002)

api/media.go and subsonic/stream.go each had imageContentType, the
same map in a different order, serving the same files.
coverart.ImageContentType is now the one copy, with its test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 12:45:50 -05:00
co-authored by Claude Opus 5.5
parent 074d9ffb0e
commit 55a290cf4d
6 changed files with 47 additions and 67 deletions
+1 -17
View File
@@ -63,22 +63,6 @@ func audioContentType(format string) string {
return "application/octet-stream"
}
// imageContentType maps a file extension to a MIME type for cover art.
// Unknown extensions fall back to octet-stream.
func imageContentType(path string) string {
switch strings.ToLower(filepath.Ext(path)) {
case ".jpg", ".jpeg":
return "image/jpeg"
case ".png":
return "image/png"
case ".webp":
return "image/webp"
case ".gif":
return "image/gif"
}
return "application/octet-stream"
}
// handleGetCover implements GET /api/albums/{id}/cover. Resolves the cover
// path (explicit column, else sidecar next to first track), then delegates
// byte-serving to http.ServeContent so clients get Range / If-Modified-Since
@@ -131,7 +115,7 @@ func (h *handlers) serveArt(w http.ResponseWriter, r *http.Request, path string)
writeErr(w, apierror.InternalMsg("server error", err))
return
}
w.Header().Set("Content-Type", imageContentType(path))
w.Header().Set("Content-Type", coverart.ImageContentType(path))
// Art changes rarely (cover-source enrichment, manual rescan, rare
// MBID-driven re-fetch). One-day max-age + must-revalidate means
// clients skip the conditional GET for the bulk of a session, but