From e3afb58634337eddc6ab5b46a35bf82f595b5fcc Mon Sep 17 00:00:00 2001 From: mountain Date: Tue, 22 Aug 2023 18:06:14 +0900 Subject: [PATCH] =?UTF-8?q?file=20=EA=B2=BD=EB=A1=9C=EC=97=90=EC=84=9C=20s?= =?UTF-8?q?ervicecode=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/api.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/core/api.go b/core/api.go index dab0709..e2c0b95 100644 --- a/core/api.go +++ b/core/api.go @@ -2,9 +2,7 @@ package core import ( "bytes" - "crypto/md5" "encoding/binary" - "encoding/hex" "encoding/json" "errors" "fmt" @@ -109,10 +107,6 @@ var seq = uint32(0) func (caller apiCaller) uploadAPI(w http.ResponseWriter, r *http.Request) error { if r.Method == "PUT" { - hasher := md5.New() - hasher.Write(caller.mg.service().serviceCodeBytes) - subfolder := hex.EncodeToString(hasher.Sum(nil))[:8] - infile, header, err := r.FormFile("file") if err != nil { w.WriteHeader(http.StatusBadRequest) @@ -128,17 +122,16 @@ func (caller apiCaller) uploadAPI(w http.ResponseWriter, r *http.Request) error var b [5]byte binary.BigEndian.PutUint32(b[0:4], uint32(time.Now().Unix())) b[4] = byte(atomic.AddUint32(&seq, 1) % 255) - rf := hex.EncodeToString(b[1:]) - newidstr := subfolder + rf - newidbt, _ := hex.DecodeString(newidstr) - newidobj := primitive.NewObjectID() - copy(newidobj[:], newidbt[:8]) + newidobj := primitive.NewObjectID() + copy(newidobj[:], b[1:]) + + rf := newidobj.Hex() var link string if extract { - link = path.Join("static", subfolder, rf) + link = path.Join("static", rf) } else { - link = path.Join("static", subfolder, rf, header.Filename) + link = path.Join("static", rf, header.Filename) } newdoc := FileDocumentDesc{