mirror of
https://github.com/vbatts/imgsrv.git
synced 2025-01-12 23:20:06 +00:00
beginning to move sub functions into there own import paths
This commit is contained in:
parent
75ee3c520c
commit
8aa7278da8
4 changed files with 13 additions and 11 deletions
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/vbatts/imgsrv/hash"
|
||||||
"labix.org/v2/mgo/bson"
|
"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) {
|
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)
|
err = gfs.Find(bson.M{"random": bson.M{"$gt": r}}).One(&this_file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return this_file, err
|
return this_file, err
|
||||||
|
|
21
server.go
21
server.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/vbatts/imgsrv/hash"
|
||||||
"io"
|
"io"
|
||||||
"labix.org/v2/mgo"
|
"labix.org/v2/mgo"
|
||||||
"labix.org/v2/mgo/bson"
|
"labix.org/v2/mgo/bson"
|
||||||
|
@ -210,7 +211,7 @@ func routeFilesPOST(w http.ResponseWriter, r *http.Request) {
|
||||||
var filename string
|
var filename string
|
||||||
info := Info{
|
info := Info{
|
||||||
Ip: r.RemoteAddr,
|
Ip: r.RemoteAddr,
|
||||||
Random: Rand64(),
|
Random: hash.Rand64(),
|
||||||
TimeStamp: time.Now(),
|
TimeStamp: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +244,7 @@ func routeFilesPOST(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(filename) == 0 {
|
if len(filename) == 0 {
|
||||||
str := GetSmallHash()
|
str := hash.GetSmallHash()
|
||||||
if len(p_ext) == 0 {
|
if len(p_ext) == 0 {
|
||||||
filename = fmt.Sprintf("%s.jpg", str)
|
filename = fmt.Sprintf("%s.jpg", str)
|
||||||
} else {
|
} else {
|
||||||
|
@ -524,7 +525,7 @@ func routeGetFromUrl(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method == "POST" {
|
if r.Method == "POST" {
|
||||||
info := Info{
|
info := Info{
|
||||||
Ip: r.RemoteAddr,
|
Ip: r.RemoteAddr,
|
||||||
Random: Rand64(),
|
Random: hash.Rand64(),
|
||||||
TimeStamp: time.Now(),
|
TimeStamp: time.Now(),
|
||||||
}
|
}
|
||||||
log.Println(info)
|
log.Println(info)
|
||||||
|
@ -620,7 +621,7 @@ func routeUpload(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method == "POST" {
|
if r.Method == "POST" {
|
||||||
info := Info{
|
info := Info{
|
||||||
Ip: r.RemoteAddr,
|
Ip: r.RemoteAddr,
|
||||||
Random: Rand64(),
|
Random: hash.Rand64(),
|
||||||
TimeStamp: time.Now(),
|
TimeStamp: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -630,13 +631,13 @@ func routeUpload(w http.ResponseWriter, r *http.Request) {
|
||||||
serverErr(w, r, err)
|
serverErr(w, r, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
useRandName := false
|
useRandName := false
|
||||||
log.Printf("%q", r.MultipartForm.Value)
|
log.Printf("%q", r.MultipartForm.Value)
|
||||||
for k, v := range r.MultipartForm.Value {
|
for k, v := range r.MultipartForm.Value {
|
||||||
if k == "keywords" {
|
if k == "keywords" {
|
||||||
info.Keywords = append(info.Keywords, strings.Split(v[0], ",")...)
|
info.Keywords = append(info.Keywords, strings.Split(v[0], ",")...)
|
||||||
} else if k == "rand" {
|
} else if k == "rand" {
|
||||||
useRandName = true
|
useRandName = true
|
||||||
} else {
|
} else {
|
||||||
log.Printf("WARN: not sure what to do with param [%s = %s]", k, v)
|
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)
|
serverErr(w, r, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if exists || useRandName {
|
if exists || useRandName {
|
||||||
ext := filepath.Ext(filename)
|
ext := filepath.Ext(filename)
|
||||||
str := GetSmallHash()
|
str := hash.GetSmallHash()
|
||||||
filename = fmt.Sprintf("%s%s", str, ext)
|
filename = fmt.Sprintf("%s%s", str, ext)
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := gfs.Create(filename)
|
file, err := gfs.Create(filename)
|
||||||
|
|
Loading…
Reference in a new issue