1
0
Fork 0
mirror of https://github.com/vbatts/imgsrv.git synced 2024-11-27 10:35:41 +00:00

moved types out to a package

This commit is contained in:
Vincent Batts 2013-05-09 12:13:46 -04:00
parent d80427788d
commit 967daf48b2
4 changed files with 21 additions and 18 deletions

View file

@ -2,12 +2,13 @@ package main
import (
"github.com/vbatts/imgsrv/hash"
"github.com/vbatts/imgsrv/types"
"labix.org/v2/mgo/bson"
)
/* gfs is a *mgo.GridFS defined in imgsrv.go */
func GetFileByFilename(filename string) (this_file File, err error) {
func GetFileByFilename(filename string) (this_file types.File, err error) {
err = gfs.Find(bson.M{"filename": filename}).One(&this_file)
if err != nil {
return this_file, err
@ -15,7 +16,7 @@ func GetFileByFilename(filename string) (this_file File, err error) {
return this_file, nil
}
func GetFileRandom() (this_file File, err error) {
func GetFileRandom() (this_file types.File, err error) {
r := hash.Rand64()
err = gfs.Find(bson.M{"random": bson.M{"$gt": r}}).One(&this_file)
if err != nil {
@ -30,7 +31,7 @@ func GetFileRandom() (this_file File, err error) {
return this_file, nil
}
/* Check whether this File filename is on Mongo */
/* Check whether this types.File filename is on Mongo */
func HasFileByFilename(filename string) (exists bool, err error) {
c, err := gfs.Find(bson.M{"filename": filename}).Count()
if err != nil {

View file

@ -2,6 +2,7 @@ package main
import (
"fmt"
"github.com/vbatts/imgsrv/types"
"io"
"text/template"
)
@ -196,7 +197,7 @@ func UploadPage(w io.Writer) (err error) {
return
}
func ImageViewPage(w io.Writer, file File) (err error) {
func ImageViewPage(w io.Writer, file types.File) (err error) {
err = headTemplate.Execute(w, map[string]string{"title": "FileSrv"})
if err != nil {
return err
@ -222,7 +223,7 @@ func ImageViewPage(w io.Writer, file File) (err error) {
return
}
func ListFilesPage(w io.Writer, files []File) (err error) {
func ListFilesPage(w io.Writer, files []types.File) (err error) {
err = headTemplate.Execute(w, map[string]string{"title": "FileSrv"})
if err != nil {
return err

View file

@ -3,6 +3,7 @@ package main
import (
"fmt"
"github.com/vbatts/imgsrv/hash"
"github.com/vbatts/imgsrv/types"
"io"
"labix.org/v2/mgo"
"labix.org/v2/mgo/bson"
@ -123,7 +124,7 @@ func routeViewsGET(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
if len(uriChunks) == 2 && len(uriChunks[1]) > 0 {
var file File
var file types.File
err := gfs.Find(bson.M{"filename": uriChunks[1]}).One(&file)
if err != nil {
serverErr(w, r, err)
@ -209,7 +210,7 @@ func routeFilesPOST(w http.ResponseWriter, r *http.Request) {
}
var filename string
info := Info{
info := types.Info{
Ip: r.RemoteAddr,
Random: hash.Rand64(),
TimeStamp: time.Now(),
@ -286,7 +287,7 @@ func routeFilesPOST(w http.ResponseWriter, r *http.Request) {
return
}
var mInfo Info
var mInfo types.Info
err = file.GetMeta(&mInfo)
if err != nil {
log.Printf("ERROR: failed to get metadata for %s. %s\n", filename, err)
@ -383,7 +384,7 @@ func routeRoot(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
//iter := gfs.Find(bson.M{"uploadDate": bson.M{"$gt": time.Now().Add(-time.Hour)}}).Limit(defaultPageLimit).Iter()
var files []File
var files []types.File
err := gfs.Find(nil).Sort("-metadata.timestamp").Limit(defaultPageLimit).All(&files)
if err != nil {
serverErr(w, r, err)
@ -406,7 +407,7 @@ func routeAll(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
// Show a page of all the images
var files []File
var files []types.File
err := gfs.Find(nil).All(&files)
if err != nil {
serverErr(w, r, err)
@ -454,7 +455,7 @@ func routeKeywords(w http.ResponseWriter, r *http.Request) {
iter = gfs.Find(bson.M{"metadata.keywords": uriChunks[1]}).Sort("-metadata.timestamp").Limit(defaultPageLimit).Iter()
}
var files []File
var files []types.File
err := iter.All(&files)
if err != nil {
serverErr(w, r, err)
@ -481,7 +482,7 @@ func routeMD5s(w http.ResponseWriter, r *http.Request) {
return
}
var files []File
var files []types.File
err := gfs.Find(bson.M{"md5": uriChunks[1]}).Sort("-metadata.timestamp").Limit(defaultPageLimit).All(&files)
if err != nil {
serverErr(w, r, err)
@ -537,10 +538,10 @@ func routeGetFromUrl(w http.ResponseWriter, r *http.Request) {
stored_filename string
local_filename string
useRandName bool = false
info Info
info types.Info
)
info = Info{
info = types.Info{
Ip: r.RemoteAddr,
Random: hash.Rand64(),
TimeStamp: time.Now(),
@ -637,7 +638,7 @@ func routeUpload(w http.ResponseWriter, r *http.Request) {
}
if r.Method == "POST" {
info := Info{
info := types.Info{
Ip: r.RemoteAddr,
Random: hash.Rand64(),
TimeStamp: time.Now(),

View file

@ -1,4 +1,4 @@
package main
package types
import (
"mime"