Fix cover content type detection build error
This commit is contained in:
@@ -2,12 +2,12 @@ package library
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@@ -129,18 +129,18 @@ type containerXML struct {
|
||||
|
||||
type packageXML struct {
|
||||
Metadata struct {
|
||||
Titles []string `xml:"title"`
|
||||
Titles []string `xml:"title"`
|
||||
Creators []string `xml:"creator"`
|
||||
Metas []struct {
|
||||
Metas []struct {
|
||||
Name string `xml:"name,attr"`
|
||||
Content string `xml:"content,attr"`
|
||||
} `xml:"meta"`
|
||||
} `xml:"metadata"`
|
||||
Manifest struct {
|
||||
Items []struct {
|
||||
ID string `xml:"id,attr"`
|
||||
Href string `xml:"href,attr"`
|
||||
MediaType string `xml:"media-type,attr"`
|
||||
ID string `xml:"id,attr"`
|
||||
Href string `xml:"href,attr"`
|
||||
MediaType string `xml:"media-type,attr"`
|
||||
Properties string `xml:"properties,attr"`
|
||||
} `xml:"item"`
|
||||
} `xml:"manifest"`
|
||||
@@ -288,8 +288,9 @@ func readZipFile(files []*zip.File, name string) ([]byte, error) {
|
||||
|
||||
func detectContentType(data []byte, filename string) string {
|
||||
if len(data) > 0 {
|
||||
return httpDetectContentType(data)
|
||||
return http.DetectContentType(data)
|
||||
}
|
||||
|
||||
ext := strings.ToLower(path.Ext(filename))
|
||||
switch ext {
|
||||
case ".jpg", ".jpeg":
|
||||
@@ -304,11 +305,3 @@ func detectContentType(data []byte, filename string) string {
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user