2020-02-05 02:44:54 +01:00
|
|
|
package consts
|
2016-03-03 19:43:57 +01:00
|
|
|
|
2021-07-08 17:38:29 +02:00
|
|
|
import (
|
|
|
|
"mime"
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
)
|
2016-03-03 19:43:57 +01:00
|
|
|
|
2021-07-08 17:38:29 +02:00
|
|
|
type format struct {
|
|
|
|
typ string
|
|
|
|
lossless bool
|
2021-04-07 04:18:48 +02:00
|
|
|
}
|
|
|
|
|
2021-07-08 17:38:29 +02:00
|
|
|
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},
|
2021-10-27 21:00:32 +02:00
|
|
|
".mka": {typ: "audio/x-matroska"},
|
2021-07-08 17:38:29 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
|
|
2020-02-05 02:44:54 +01:00
|
|
|
func init() {
|
2021-07-08 17:38:29 +02:00
|
|
|
for ext, fmt := range audioFormats {
|
|
|
|
_ = mime.AddExtensionType(ext, fmt.typ)
|
|
|
|
if fmt.lossless {
|
|
|
|
LosslessFormats = append(LosslessFormats, strings.TrimPrefix(ext, "."))
|
|
|
|
}
|
2016-03-03 19:43:57 +01:00
|
|
|
}
|
2021-07-08 17:38:29 +02:00
|
|
|
sort.Strings(LosslessFormats)
|
|
|
|
for ext, typ := range imageFormats {
|
2020-01-08 16:25:23 +01:00
|
|
|
_ = mime.AddExtensionType(ext, typ)
|
2016-03-03 19:43:57 +01:00
|
|
|
}
|
2022-02-08 21:17:35 +01:00
|
|
|
|
|
|
|
// In some circumstances, Windows sets JS mime-type to `text/plain`!
|
|
|
|
_ = mime.AddExtensionType(".js", "text/javascript")
|
|
|
|
_ = mime.AddExtensionType(".css", "text/css")
|
2016-03-03 19:43:57 +01:00
|
|
|
}
|