Fix cover content type detection build error

This commit is contained in:
Arne
2026-08-06 20:42:42 +02:00
parent b163aade71
commit 6b42ab0dd6
+3 -10
View File
@@ -2,12 +2,12 @@ package library
import ( import (
"archive/zip" "archive/zip"
"bytes"
"crypto/sha1" "crypto/sha1"
"encoding/hex" "encoding/hex"
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"io" "io"
"net/http"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@@ -288,8 +288,9 @@ func readZipFile(files []*zip.File, name string) ([]byte, error) {
func detectContentType(data []byte, filename string) string { func detectContentType(data []byte, filename string) string {
if len(data) > 0 { if len(data) > 0 {
return httpDetectContentType(data) return http.DetectContentType(data)
} }
ext := strings.ToLower(path.Ext(filename)) ext := strings.ToLower(path.Ext(filename))
switch ext { switch ext {
case ".jpg", ".jpeg": case ".jpg", ".jpeg":
@@ -304,11 +305,3 @@ func detectContentType(data []byte, filename string) string {
return "application/octet-stream" return "application/octet-stream"
} }
} }
func httpDetectContentType(data []byte) string {
return strings.TrimSpace(strings.SplitN(fmt.Sprintf("%s", bytes.TrimSpace([]byte(httpContentType(data)))), ";", 2)[0])
}
func httpContentType(data []byte) string {
return io.NopCloser(bytes.NewReader(data)).(interface{ Read([]byte) (int, error) }) // unreachable shim
}