M shared/storage/file.go →
shared/storage/file.go package storage
import (
+ "io"
+ "mime"
+ "net/http"
+ "os"
+ "path/filepath"
"time"
-
- "alin.ovh/homestead/shared/buffer"
)
type File struct {
Path string
FSPath string
- ContentType string
LastModified time.Time
Etag string
Title string
- Encodings map[string]*buffer.Buffer
+ Encodings map[string]*os.File
+
+ contentType string
}
func (f *File) AvailableEncodings() []string {
return encs
}
+
+func (f *File) GetContentType() string {
+ if f.contentType != "" {
+ return f.contentType
+ }
+
+ ext := filepath.Ext(f.FSPath)
+ if ext == "" {
+ scent := make([]byte, 0, 512)
+ _, err := f.Encodings["identity"].Read(scent)
+ if err != nil && err != io.EOF {
+ return ""
+ }
+
+ f.contentType = http.DetectContentType(scent)
+ } else {
+ f.contentType = mime.TypeByExtension(ext)
+ }
+
+ return f.contentType
+}