diff --git a/core/api.go b/core/api.go index 179c51e..a5ea1d2 100644 --- a/core/api.go +++ b/core/api.go @@ -18,7 +18,7 @@ import ( "time" "unsafe" - common "repositories.action2quare.com/ayo/gocommon" + "repositories.action2quare.com/ayo/gocommon" "repositories.action2quare.com/ayo/gocommon/logger" "go.mongodb.org/mongo-driver/bson" @@ -66,9 +66,9 @@ func (fd *FileDocumentDesc) Save() error { if fd.Extract { switch path.Ext(destFile) { case ".zip": - err = common.Unzip(destFile) + err = gocommon.Unzip(destFile) case ".tar": - err = common.Untar(destFile) + err = gocommon.Untar(destFile) } } return err @@ -435,9 +435,9 @@ func (mg *Maingate) api(w http.ResponseWriter, r *http.Request) { ptr := atomic.LoadPointer(&mg.admins) adminsptr := (*globalAdmins)(ptr) - if adminsptr.modtime != common.ConfigModTime() { + if adminsptr.modtime != gocommon.ConfigModTime() { var config globalAdmins - if err := common.LoadConfig(&config); err == nil { + if err := gocommon.LoadConfig(&config); err == nil { config.parse() adminsptr = &config atomic.StorePointer(&mg.admins, unsafe.Pointer(adminsptr)) diff --git a/core/service.go b/core/service.go index 3127cbb..56b0d46 100644 --- a/core/service.go +++ b/core/service.go @@ -2,20 +2,18 @@ package core import ( "context" - "crypto/md5" "encoding/hex" "encoding/json" "errors" "fmt" "io" "net/http" - "path" "strings" "sync/atomic" "time" "unsafe" - common "repositories.action2quare.com/ayo/gocommon" + "repositories.action2quare.com/ayo/gocommon" "repositories.action2quare.com/ayo/gocommon/logger" "go.mongodb.org/mongo-driver/bson" @@ -139,9 +137,9 @@ type serviceDescription struct { ServerApiTokens []primitive.ObjectID `bson:"api_tokens" json:"api_tokens"` Admins []string `bson:"admins" json:"admins"` - auths *common.AuthCollection + auths *gocommon.AuthCollection wl *whitelist - mongoClient common.MongoClient + mongoClient gocommon.MongoClient sessionTTL time.Duration MaximumNumLinkAccount int64 @@ -238,11 +236,16 @@ func (sh *serviceDescription) prepare(mg *Maingate) error { } else if strings.HasPrefix(div.Maintenance.Notice, "http") { div.Maintenance.link = div.Maintenance.Notice } else { - hasher := md5.New() - hasher.Write(sh.Id[:]) - subfolder := hex.EncodeToString(hasher.Sum(nil))[:8] + var fd FileDocumentDesc + if err := sh.mongoClient.FindOneAs(CollectionFile, bson.M{ + "key": div.Maintenance.Notice, + }, &fd, options.FindOne().SetProjection(bson.M{"link": 1})); err != nil { + logger.Println(err) + return err + } - div.Maintenance.link = path.Join("static", subfolder, div.Maintenance.Notice) + div.Maintenance.link = fd.Link + logger.Println("div.Maintenance.link :", fd.Link) } } } else { @@ -687,7 +690,7 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request) newsession := primitive.NewObjectID() expired := primitive.NewDateTimeFromTime(time.Now().UTC().Add(sh.sessionTTL)) - newauth := common.Authinfo{ + newauth := gocommon.Authinfo{ Accid: accid, ServiceCode: sh.ServiceCode, Platform: authtype, diff --git a/core/watch.go b/core/watch.go index 42b23cc..3e6c30e 100644 --- a/core/watch.go +++ b/core/watch.go @@ -10,7 +10,7 @@ import ( "time" "unsafe" - common "repositories.action2quare.com/ayo/gocommon" + "repositories.action2quare.com/ayo/gocommon" "repositories.action2quare.com/ayo/gocommon/logger" "go.mongodb.org/mongo-driver/bson" @@ -24,7 +24,7 @@ type authPipelineDocument struct { DocumentKey struct { Id primitive.ObjectID `bson:"_id"` } `bson:"documentKey"` - Authinfo *common.Authinfo `bson:"fullDocument"` + Authinfo *gocommon.Authinfo `bson:"fullDocument"` } type servicePipelineDocument struct { @@ -289,7 +289,7 @@ func (mg *Maingate) watchServiceCollection(parentctx context.Context, serveMux * logger.Println("service is on the board! :", data.Service) atomic.StorePointer(&mg.serviceptr, unsafe.Pointer(data.Service)) if !already { - serveMux.Handle(common.MakeHttpHandlerPattern(prefix, data.Service.ServiceCode, "/"), mg.service()) + serveMux.Handle(gocommon.MakeHttpHandlerPattern(prefix, data.Service.ServiceCode, "/"), mg.service()) } } @@ -321,7 +321,7 @@ func (mg *Maingate) watchServiceCollection(parentctx context.Context, serveMux * } } -func watchAuthCollection(parentctx context.Context, ac *common.AuthCollection, mongoClient common.MongoClient) { +func watchAuthCollection(parentctx context.Context, ac *gocommon.AuthCollection, mongoClient gocommon.MongoClient) { defer func() { s := recover() if s != nil { diff --git a/main.go b/main.go index 195cf96..7de2944 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,7 @@ import ( "net/http" "time" - common "repositories.action2quare.com/ayo/gocommon" + "repositories.action2quare.com/ayo/gocommon" "repositories.action2quare.com/ayo/gocommon/flagx" "repositories.action2quare.com/ayo/gocommon/logger" "repositories.action2quare.com/ayo/maingate/core" @@ -36,7 +36,7 @@ func main() { panic(err) } - server := common.NewHTTPServer(serveMux) + server := gocommon.NewHTTPServer(serveMux) logger.Println("maingate is started") if err := server.Start(); err != nil { logger.Error("maingate is stopped with error :", err)