1
0
Fork 0
mirror of https://github.com/vbatts/imgsrv.git synced 2025-01-02 18:47:08 +00:00
imgsrv/types/types.go
Vincent Batts 3c6deccbea
types: webm must not have a mimetype yet?
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2017-08-08 16:18:44 -04:00

54 lines
1 KiB
Go

package types
import (
"mime"
"path/filepath"
"strings"
"time"
)
type Info struct {
Keywords []string // tags
Ip string // who uploaded it
Random int64
TimeStamp time.Time "timestamp,omitempty"
}
type File struct {
Metadata Info ",omitempty"
Md5 string
ChunkSize int
UploadDate time.Time
Length uint64
Filename string ",omitempty"
}
// ContentType guesses the mime-type by the file's extension
func (f *File) ContentType() string {
mtype := mime.TypeByExtension(filepath.Ext(f.Filename))
if mtype == "" {
if strings.HasSuffix(f.Filename, ".webm") {
return "video/webm; charset=binary"
}
}
return mtype
}
func (f *File) IsImage() bool {
return strings.HasPrefix(f.ContentType(), "image")
}
func (f *File) IsVideo() bool {
return strings.HasPrefix(f.ContentType(), "video")
}
func (f *File) IsAudio() bool {
return strings.HasPrefix(f.ContentType(), "audio")
}
// IdCount structure used for collecting values for a tag cloud
type IdCount struct {
Id string "_id"
Value int
Root string
}