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:
@@ -157,25 +157,10 @@ func serveImage(w http.ResponseWriter, r *http.Request, path string) {
|
||||
WriteFail(w, r, ErrGeneric, "Failed to stat cover art")
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", imageContentType(path))
|
||||
w.Header().Set("Content-Type", coverart.ImageContentType(path))
|
||||
http.ServeContent(w, r, filepath.Base(path), info.ModTime(), f)
|
||||
}
|
||||
|
||||
func imageContentType(path string) string {
|
||||
switch strings.ToLower(filepath.Ext(path)) {
|
||||
case ".jpg", ".jpeg":
|
||||
return "image/jpeg"
|
||||
case ".png":
|
||||
return "image/png"
|
||||
case ".gif":
|
||||
return "image/gif"
|
||||
case ".webp":
|
||||
return "image/webp"
|
||||
default:
|
||||
return "application/octet-stream"
|
||||
}
|
||||
}
|
||||
|
||||
// handleScrobble translates Subsonic scrobble calls into native play_events.
|
||||
//
|
||||
// submission=false (now playing) opens a play, leaving ended_at NULL.
|
||||
|
||||
@@ -37,19 +37,3 @@ func TestFindSidecarCover(t *testing.T) {
|
||||
t.Errorf("cover.jpg priority = %q, want %q", got, cover)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageContentType(t *testing.T) {
|
||||
cases := map[string]string{
|
||||
"cover.jpg": "image/jpeg",
|
||||
"cover.JPEG": "image/jpeg",
|
||||
"art.png": "image/png",
|
||||
"thumb.gif": "image/gif",
|
||||
"square.webp": "image/webp",
|
||||
"unknown.tiff": "application/octet-stream",
|
||||
}
|
||||
for in, want := range cases {
|
||||
if got := imageContentType(in); got != want {
|
||||
t.Errorf("imageContentType(%q) = %q, want %q", in, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user