Fix cover content type detection build error
This commit is contained in:
@@ -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"
|
||||||
@@ -129,18 +129,18 @@ type containerXML struct {
|
|||||||
|
|
||||||
type packageXML struct {
|
type packageXML struct {
|
||||||
Metadata struct {
|
Metadata struct {
|
||||||
Titles []string `xml:"title"`
|
Titles []string `xml:"title"`
|
||||||
Creators []string `xml:"creator"`
|
Creators []string `xml:"creator"`
|
||||||
Metas []struct {
|
Metas []struct {
|
||||||
Name string `xml:"name,attr"`
|
Name string `xml:"name,attr"`
|
||||||
Content string `xml:"content,attr"`
|
Content string `xml:"content,attr"`
|
||||||
} `xml:"meta"`
|
} `xml:"meta"`
|
||||||
} `xml:"metadata"`
|
} `xml:"metadata"`
|
||||||
Manifest struct {
|
Manifest struct {
|
||||||
Items []struct {
|
Items []struct {
|
||||||
ID string `xml:"id,attr"`
|
ID string `xml:"id,attr"`
|
||||||
Href string `xml:"href,attr"`
|
Href string `xml:"href,attr"`
|
||||||
MediaType string `xml:"media-type,attr"`
|
MediaType string `xml:"media-type,attr"`
|
||||||
Properties string `xml:"properties,attr"`
|
Properties string `xml:"properties,attr"`
|
||||||
} `xml:"item"`
|
} `xml:"item"`
|
||||||
} `xml:"manifest"`
|
} `xml:"manifest"`
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user