mirror of
https://github.com/vbatts/imgsrv.git
synced 2024-12-25 23:36:30 +00:00
Vincent Batts
5eab319c6c
for your mongo db set, run: db.fs.files.find().forEach( function(e) { e.filename = e.filename.toLowerCase(); db.fs.files.save(e); } )
52 lines
970 B
Go
52 lines
970 B
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 int64
|
|
Filename string ",omitempty"
|
|
ContentType string "contentType,omitempty"
|
|
}
|
|
|
|
func (f *File) SetContentType() {
|
|
f.ContentType = mime.TypeByExtension(filepath.Ext(f.Filename))
|
|
}
|
|
|
|
func (f *File) IsImage() bool {
|
|
f.SetContentType()
|
|
return strings.HasPrefix(f.ContentType, "image")
|
|
}
|
|
|
|
func (f *File) IsVideo() bool {
|
|
f.SetContentType()
|
|
return strings.HasPrefix(f.ContentType, "video")
|
|
}
|
|
|
|
func (f *File) IsAudio() bool {
|
|
f.SetContentType()
|
|
return strings.HasPrefix(f.ContentType, "audio")
|
|
}
|
|
|
|
/*
|
|
Structure used for collecting values from mongo for a tag cloud
|
|
*/
|
|
type IdCount struct {
|
|
Id string "_id"
|
|
Value int
|
|
}
|