diff --git a/db_fileutil.go b/db_fileutil.go index a5f7806..c17a070 100644 --- a/db_fileutil.go +++ b/db_fileutil.go @@ -1,6 +1,7 @@ package main import ( + "github.com/vbatts/imgsrv/hash" "labix.org/v2/mgo/bson" ) @@ -15,7 +16,7 @@ func GetFileByFilename(filename string) (this_file File, err error) { } func GetFileRandom() (this_file File, err error) { - r := Rand64() + r := hash.Rand64() err = gfs.Find(bson.M{"random": bson.M{"$gt": r}}).One(&this_file) if err != nil { return this_file, err diff --git a/hash.go b/hash/hash.go similarity index 100% rename from hash.go rename to hash/hash.go diff --git a/hash_test.go b/hash/hash_test.go similarity index 100% rename from hash_test.go rename to hash/hash_test.go diff --git a/server.go b/server.go index 9b27aa4..469d4ae 100644 --- a/server.go +++ b/server.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/vbatts/imgsrv/hash" "io" "labix.org/v2/mgo" "labix.org/v2/mgo/bson" @@ -210,7 +211,7 @@ func routeFilesPOST(w http.ResponseWriter, r *http.Request) { var filename string info := Info{ Ip: r.RemoteAddr, - Random: Rand64(), + Random: hash.Rand64(), TimeStamp: time.Now(), } @@ -243,7 +244,7 @@ func routeFilesPOST(w http.ResponseWriter, r *http.Request) { } if len(filename) == 0 { - str := GetSmallHash() + str := hash.GetSmallHash() if len(p_ext) == 0 { filename = fmt.Sprintf("%s.jpg", str) } else { @@ -524,7 +525,7 @@ func routeGetFromUrl(w http.ResponseWriter, r *http.Request) { if r.Method == "POST" { info := Info{ Ip: r.RemoteAddr, - Random: Rand64(), + Random: hash.Rand64(), TimeStamp: time.Now(), } log.Println(info) @@ -620,7 +621,7 @@ func routeUpload(w http.ResponseWriter, r *http.Request) { if r.Method == "POST" { info := Info{ Ip: r.RemoteAddr, - Random: Rand64(), + Random: hash.Rand64(), TimeStamp: time.Now(), } @@ -630,13 +631,13 @@ func routeUpload(w http.ResponseWriter, r *http.Request) { serverErr(w, r, err) return } - useRandName := false + useRandName := false log.Printf("%q", r.MultipartForm.Value) for k, v := range r.MultipartForm.Value { if k == "keywords" { info.Keywords = append(info.Keywords, strings.Split(v[0], ",")...) } else if k == "rand" { - useRandName = true + useRandName = true } else { log.Printf("WARN: not sure what to do with param [%s = %s]", k, v) } @@ -649,10 +650,10 @@ func routeUpload(w http.ResponseWriter, r *http.Request) { serverErr(w, r, err) return } - if exists || useRandName { - ext := filepath.Ext(filename) - str := GetSmallHash() - filename = fmt.Sprintf("%s%s", str, ext) + if exists || useRandName { + ext := filepath.Ext(filename) + str := hash.GetSmallHash() + filename = fmt.Sprintf("%s%s", str, ext) } file, err := gfs.Create(filename)