Commit 631aea93 authored by Benjamin Rokseth's avatar Benjamin Rokseth
Browse files

A more random randomId

parent 0f267d2a
...@@ -13,6 +13,7 @@ import ( ...@@ -13,6 +13,7 @@ import (
"net/http" "net/http"
"os" "os"
"regexp" "regexp"
"time"
"github.com/go-chi/chi" "github.com/go-chi/chi"
"github.com/go-chi/chi/middleware" "github.com/go-chi/chi/middleware"
...@@ -150,7 +151,7 @@ func (s *server) uploadImage(w http.ResponseWriter, r *http.Request) { ...@@ -150,7 +151,7 @@ func (s *server) uploadImage(w http.ResponseWriter, r *http.Request) {
http.Error(w, "INVALID_FILE_TYPE", http.StatusBadRequest) http.Error(w, "INVALID_FILE_TYPE", http.StatusBadRequest)
return return
} }
uid := randID(12) uid := randID(6)
fileEndings, err := mime.ExtensionsByType(filetype) fileEndings, err := mime.ExtensionsByType(filetype)
if err != nil { if err != nil {
http.Error(w, "INVALID_FILE_TYPE", http.StatusBadRequest) http.Error(w, "INVALID_FILE_TYPE", http.StatusBadRequest)
...@@ -224,9 +225,10 @@ func (s *server) deleteImage(w http.ResponseWriter, r *http.Request) { ...@@ -224,9 +225,10 @@ func (s *server) deleteImage(w http.ResponseWriter, r *http.Request) {
} }
func randID(l int) string { func randID(l int) string {
t := time.Now().UTC().UnixNano()
b := make([]byte, l) b := make([]byte, l)
rand.Read(b) rand.Read(b)
return fmt.Sprintf("%x", b) return fmt.Sprintf("%d%x", t, b)
} }
func isValidBucketName(b string) error { func isValidBucketName(b string) error {
...@@ -243,6 +245,7 @@ func main() { ...@@ -243,6 +245,7 @@ func main() {
listen = flag.String("l", ":1666", "server listeing address") listen = flag.String("l", ":1666", "server listeing address")
) )
flag.Parse() flag.Parse()
rand.Seed(time.Now().UTC().UnixNano())
m, err := minio.New(*minioURL, os.Getenv("MINIO_ACCESS_KEY"), os.Getenv("MINIO_SECRET_KEY"), *minioSsl) m, err := minio.New(*minioURL, os.Getenv("MINIO_ACCESS_KEY"), os.Getenv("MINIO_SECRET_KEY"), *minioSsl)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment