diff --git a/internal/cms_api/admin/admin.go b/internal/cms_api/admin/admin.go index 56248f080..ec93d8346 100644 --- a/internal/cms_api/admin/admin.go +++ b/internal/cms_api/admin/admin.go @@ -57,7 +57,7 @@ func UploadUpdateApp(c *gin.Context) { return } log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req) - newFileName, newYamlName, err := utils.GetUploadAppNewName(req.Type, req.Version) + newFileName, newYamlName, err := utils.GetUploadAppNewName(req.Type, req.Version, req.File.Filename, req.Yaml.Filename) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUploadAppNewName failed", err.Error()) c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "invalid file type" + err.Error()}) @@ -82,7 +82,7 @@ func UploadUpdateApp(c *gin.Context) { c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "invalid file path" + err.Error()}) return } - if err := imdb.UpdateAppVersion(req.Type, req.Version, req.ForceUpdate); err != nil { + if err := imdb.UpdateAppVersion(req.Type, req.Version, req.ForceUpdate, newFileName, newYamlName); err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "UpdateAppVersion error", err.Error()) resp.ErrCode = http.StatusInternalServerError resp.ErrMsg = err.Error() @@ -107,12 +107,12 @@ func GetDownloadURL(c *gin.Context) { return } log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req) - fileName, yamlName, err := utils.GetUploadAppNewName(req.Type, req.Version) - if err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUploadAppNewName failed", err.Error()) - c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "invalid file type" + err.Error()}) - return - } + //fileName, yamlName, err := utils.GetUploadAppNewName(req.Type, req.Version, req.) + //if err != nil { + // log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUploadAppNewName failed", err.Error()) + // c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "invalid file type" + err.Error()}) + // return + //} app, err := imdb.GetNewestVersion(req.Type) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "getNewestVersion failed", err.Error()) @@ -124,8 +124,8 @@ func GetDownloadURL(c *gin.Context) { if app.ForceUpdate == true { resp.Data.ForceUpdate = true } - resp.Data.YamlURL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.AppBucket + "/" + yamlName - resp.Data.FileURL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.AppBucket + "/" + fileName + resp.Data.YamlURL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.AppBucket + "/" + app.YamlName + resp.Data.FileURL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.AppBucket + "/" + app.FileName c.JSON(http.StatusOK, resp) } else { resp.Data.HasNewVersion = false diff --git a/pkg/common/db/model_struct.go b/pkg/common/db/model_struct.go index eae008542..6eb18630d 100644 --- a/pkg/common/db/model_struct.go +++ b/pkg/common/db/model_struct.go @@ -278,6 +278,8 @@ type AppVersion struct { Type int `gorm:"column:type;primary_key"` UpdateTime int `gorm:"column:update_time"` ForceUpdate bool `gorm:"column:force_update"` + FileName string `gorm:"column:file_name"` + YamlName string `gorm:"column:yaml_name"` } func (AppVersion) TableName() string { diff --git a/pkg/common/db/mysql_model/im_mysql_model/file_model.go b/pkg/common/db/mysql_model/im_mysql_model/file_model.go index 8265ee9de..7d6144633 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/file_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/file_model.go @@ -5,7 +5,7 @@ import ( "time" ) -func UpdateAppVersion(appType int, version string, forceUpdate bool) error { +func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, yamlName string) error { dbConn, err := db.DB.MysqlDB.DefaultGormDB() if err != nil { return err @@ -15,6 +15,8 @@ func UpdateAppVersion(appType int, version string, forceUpdate bool) error { Type: appType, UpdateTime: int(time.Now().Unix()), ForceUpdate: forceUpdate, + FileName: fileName, + YamlName: yamlName, } result := dbConn.Model(db.AppVersion{}).Where("app_type = ?", appType).Updates(&app) if result.Error != nil { diff --git a/pkg/utils/file.go b/pkg/utils/file.go index b852098b8..d09b105ef 100644 --- a/pkg/utils/file.go +++ b/pkg/utils/file.go @@ -39,8 +39,8 @@ func GetNewFileNameAndContentType(fileName string, fileType int) (string, string return newName, contentType } -func GetUploadAppNewName(appType int, version string) (string, string, error) { - var newFileName, newYamlName = "_" + version + "_app_", version + "_yaml" +func GetUploadAppNewName(appType int, version, fileName, yamlName string) (string, string, error) { + var newFileName, newYamlName = "_" + version + "_app", "_" + version + "_yaml" switch appType { case constant.IOSPlatformID: newFileName = constant.IOSPlatformStr + newFileName @@ -66,5 +66,9 @@ func GetUploadAppNewName(appType int, version string) (string, string, error) { default: return "", "", errors.New("invalid app type") } + suffixFile := path.Ext(fileName) + suffixYaml := path.Ext(yamlName) + newFileName = fmt.Sprintf("%s.%s", newFileName, suffixFile) + newYamlName = fmt.Sprintf("%s.%s", newYamlName, suffixYaml) return newFileName, newYamlName, nil }