39 lines
657 B
Go
39 lines
657 B
Go
package fs
|
|
|
|
import (
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/h2non/filetype"
|
|
)
|
|
|
|
type File struct {
|
|
Name string `json:"name"`
|
|
Url string `json:"url"`
|
|
Path string `json:"-"`
|
|
RelativePath string `json:"-"`
|
|
Head []byte `json:"-"`
|
|
ContentType string `json:"-"`
|
|
Date int64 `json:"-"`
|
|
}
|
|
|
|
type Files []File
|
|
|
|
func (f Files) Empty() bool {
|
|
return len(f) == 0
|
|
}
|
|
|
|
func (f *File) GenerateHeadAndContentType() {
|
|
fo, _ := os.Open(f.Path)
|
|
head := make([]byte, 261)
|
|
fo.Read(head)
|
|
|
|
f.Head = head
|
|
f.ContentType = http.DetectContentType(head)
|
|
|
|
fo.Close()
|
|
}
|
|
|
|
func (f File) IsSupported() bool {
|
|
return filetype.IsVideo(f.Head)
|
|
}
|