mirror of
https://github.com/vbatts/imgsrv.git
synced 2024-11-23 16:45:39 +00:00
dbutil: abstract out the last mongo type
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
efa8ac6511
commit
b80d34f423
3 changed files with 31 additions and 23 deletions
|
@ -1,8 +1,9 @@
|
|||
package dbutil
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/vbatts/imgsrv/types"
|
||||
"labix.org/v2/mgo"
|
||||
)
|
||||
|
||||
// Handles are all the register backing Handlers
|
||||
|
@ -13,8 +14,8 @@ type Handler interface {
|
|||
Init(config interface{}) error
|
||||
Close() error
|
||||
|
||||
Open(filename string) (*mgo.GridFile, error)
|
||||
Create(filename string) (*mgo.GridFile, error)
|
||||
Open(filename string) (File, error)
|
||||
Create(filename string) (File, error)
|
||||
Remove(filename string) error
|
||||
|
||||
//HasFileByMd5(md5 string) (exists bool, err error)
|
||||
|
@ -31,3 +32,15 @@ type Handler interface {
|
|||
GetExtensions() (kp []types.IdCount, err error)
|
||||
GetKeywords() (kp []types.IdCount, err error)
|
||||
}
|
||||
|
||||
type MetaDataer interface {
|
||||
GetMeta(result interface{}) (err error)
|
||||
SetMeta(metadata interface{})
|
||||
}
|
||||
|
||||
type File interface {
|
||||
io.Reader
|
||||
io.Writer
|
||||
io.Closer
|
||||
MetaDataer
|
||||
}
|
||||
|
|
|
@ -59,12 +59,12 @@ func (h mongoHandle) Close() error {
|
|||
}
|
||||
|
||||
// pass through for GridFs
|
||||
func (h mongoHandle) Open(filename string) (file *mgo.GridFile, err error) {
|
||||
func (h mongoHandle) Open(filename string) (file dbutil.File, err error) {
|
||||
return h.Gfs.Open(strings.ToLower(filename))
|
||||
}
|
||||
|
||||
// pass through for GridFs
|
||||
func (h mongoHandle) Create(filename string) (file *mgo.GridFile, err error) {
|
||||
func (h mongoHandle) Create(filename string) (file dbutil.File, err error) {
|
||||
return h.Gfs.Create(strings.ToLower(filename))
|
||||
}
|
||||
|
||||
|
|
|
@ -15,37 +15,32 @@ type Info struct {
|
|||
}
|
||||
|
||||
type File struct {
|
||||
Metadata Info ",omitempty"
|
||||
Md5 string
|
||||
ChunkSize int
|
||||
UploadDate time.Time
|
||||
Length int64
|
||||
Filename string ",omitempty"
|
||||
ContentType string "contentType,omitempty"
|
||||
Metadata Info ",omitempty"
|
||||
Md5 string
|
||||
ChunkSize int
|
||||
UploadDate time.Time
|
||||
Length int64
|
||||
Filename string ",omitempty"
|
||||
}
|
||||
|
||||
func (f *File) SetContentType() {
|
||||
f.ContentType = mime.TypeByExtension(filepath.Ext(f.Filename))
|
||||
// ContentType guesses the mime-type by the file's extension
|
||||
func (f *File) ContentType() string {
|
||||
return mime.TypeByExtension(filepath.Ext(f.Filename))
|
||||
}
|
||||
|
||||
func (f *File) IsImage() bool {
|
||||
f.SetContentType()
|
||||
return strings.HasPrefix(f.ContentType, "image")
|
||||
return strings.HasPrefix(f.ContentType(), "image")
|
||||
}
|
||||
|
||||
func (f *File) IsVideo() bool {
|
||||
f.SetContentType()
|
||||
return strings.HasPrefix(f.ContentType, "video")
|
||||
return strings.HasPrefix(f.ContentType(), "video")
|
||||
}
|
||||
|
||||
func (f *File) IsAudio() bool {
|
||||
f.SetContentType()
|
||||
return strings.HasPrefix(f.ContentType, "audio")
|
||||
return strings.HasPrefix(f.ContentType(), "audio")
|
||||
}
|
||||
|
||||
/*
|
||||
Structure used for collecting values from mongo for a tag cloud
|
||||
*/
|
||||
// IdCount structure used for collecting values for a tag cloud
|
||||
type IdCount struct {
|
||||
Id string "_id"
|
||||
Value int
|
||||
|
|
Loading…
Reference in a new issue