Skip to content

🎧 Your Personal Streaming Service

Refactor mime-types configuration

Deluan334068c8bf8f
diff --git a/consts/mime_types.go b/consts/mime_types.go
index d97f21a3f..98f91d62b 100644
--- a/consts/mime_types.go
+++ b/consts/mime_types.go
@@ -1,43 +1,59 @@
package consts
-import "mime"
+import (
+ "mime"
+ "sort"
+ "strings"
+)
-var LosslessFormats = []string{
- "flac", "wav", "alac", "ape", "dsf", "wav", "shn", "wv", "wvp",
+type format struct {
+ typ string
+ lossless bool
}
+var audioFormats = map[string]format{
+ ".mp3": {typ: "audio/mpeg"},
+ ".ogg": {typ: "audio/ogg"},
+ ".oga": {typ: "audio/ogg"},
+ ".opus": {typ: "audio/ogg"},
+ ".aac": {typ: "audio/mp4"},
+ ".alac": {typ: "audio/mp4", lossless: true},
+ ".m4a": {typ: "audio/mp4"},
+ ".m4b": {typ: "audio/mp4"},
+ ".flac": {typ: "audio/flac", lossless: true},
+ ".wav": {typ: "audio/x-wav", lossless: true},
+ ".wma": {typ: "audio/x-ms-wma"},
+ ".ape": {typ: "audio/x-monkeys-audio", lossless: true},
+ ".mpc": {typ: "audio/x-musepack"},
+ ".shn": {typ: "audio/x-shn", lossless: true},
+ ".aif": {typ: "audio/x-aiff"},
+ ".aiff": {typ: "audio/x-aiff"},
+ ".m3u": {typ: "audio/x-mpegurl"},
+ ".pls": {typ: "audio/x-scpls"},
+ ".dsf": {typ: "audio/dsd", lossless: true},
+ ".wv": {typ: "audio/x-wavpack", lossless: true},
+ ".wvp": {typ: "audio/x-wavpack", lossless: true},
+}
+var imageFormats = map[string]string{
+ ".gif": "image/gif",
+ ".jpg": "image/jpeg",
+ ".jpeg": "image/jpeg",
+ ".webp": "image/webp",
+ ".png": "image/png",
+ ".bmp": "image/bmp",
+}
+
+var LosslessFormats []string
+
func init() {
- mt := map[string]string{
- ".mp3": "audio/mpeg",
- ".ogg": "audio/ogg",
- ".oga": "audio/ogg",
- ".opus": "audio/ogg",
- ".aac": "audio/mp4",
- ".alac": "audio/mp4",
- ".m4a": "audio/mp4",
- ".m4b": "audio/mp4",
- ".flac": "audio/flac",
- ".wav": "audio/x-wav",
- ".wma": "audio/x-ms-wma",
- ".ape": "audio/x-monkeys-audio",
- ".mpc": "audio/x-musepack",
- ".shn": "audio/x-shn",
- ".aif": "audio/x-aiff",
- ".aiff": "audio/x-aiff",
- ".m3u": "audio/x-mpegurl",
- ".pls": "audio/x-scpls",
- ".dsf": "audio/dsd",
- ".wv": "audio/x-wavpack",
- ".wvp": "audio/x-wavpack",
- ".gif": "image/gif",
- ".jpg": "image/jpeg",
- ".jpeg": "image/jpeg",
- ".webp": "image/webp",
- ".png": "image/png",
- ".bmp": "image/bmp",
+ for ext, fmt := range audioFormats {
+ _ = mime.AddExtensionType(ext, fmt.typ)
+ if fmt.lossless {
+ LosslessFormats = append(LosslessFormats, strings.TrimPrefix(ext, "."))
+ }
}
-
- for ext, typ := range mt {
+ sort.Strings(LosslessFormats)
+ for ext, typ := range imageFormats {
_ = mime.AddExtensionType(ext, typ)
}
}