pull/232/head
wangchuxiao 3 years ago
parent 872f70a418
commit 7be5208daf

@ -57,7 +57,7 @@ func UploadUpdateApp(c *gin.Context) {
return return
} }
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req) 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 { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUploadAppNewName failed", err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUploadAppNewName failed", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "invalid file type" + 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()}) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "invalid file path" + err.Error()})
return 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()) log.NewError(req.OperationID, utils.GetSelfFuncName(), "UpdateAppVersion error", err.Error())
resp.ErrCode = http.StatusInternalServerError resp.ErrCode = http.StatusInternalServerError
resp.ErrMsg = err.Error() resp.ErrMsg = err.Error()
@ -107,12 +107,12 @@ func GetDownloadURL(c *gin.Context) {
return return
} }
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
fileName, yamlName, err := utils.GetUploadAppNewName(req.Type, req.Version) //fileName, yamlName, err := utils.GetUploadAppNewName(req.Type, req.Version, req.)
if err != nil { //if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUploadAppNewName failed", err.Error()) // log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUploadAppNewName failed", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "invalid file type" + err.Error()}) // c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "invalid file type" + err.Error()})
return // return
} //}
app, err := imdb.GetNewestVersion(req.Type) app, err := imdb.GetNewestVersion(req.Type)
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "getNewestVersion failed", err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), "getNewestVersion failed", err.Error())
@ -124,8 +124,8 @@ func GetDownloadURL(c *gin.Context) {
if app.ForceUpdate == true { if app.ForceUpdate == true {
resp.Data.ForceUpdate = true resp.Data.ForceUpdate = true
} }
resp.Data.YamlURL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.AppBucket + "/" + yamlName 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 + "/" + fileName resp.Data.FileURL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.AppBucket + "/" + app.FileName
c.JSON(http.StatusOK, resp) c.JSON(http.StatusOK, resp)
} else { } else {
resp.Data.HasNewVersion = false resp.Data.HasNewVersion = false

@ -278,6 +278,8 @@ type AppVersion struct {
Type int `gorm:"column:type;primary_key"` Type int `gorm:"column:type;primary_key"`
UpdateTime int `gorm:"column:update_time"` UpdateTime int `gorm:"column:update_time"`
ForceUpdate bool `gorm:"column:force_update"` ForceUpdate bool `gorm:"column:force_update"`
FileName string `gorm:"column:file_name"`
YamlName string `gorm:"column:yaml_name"`
} }
func (AppVersion) TableName() string { func (AppVersion) TableName() string {

@ -5,7 +5,7 @@ import (
"time" "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() dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil { if err != nil {
return err return err
@ -15,6 +15,8 @@ func UpdateAppVersion(appType int, version string, forceUpdate bool) error {
Type: appType, Type: appType,
UpdateTime: int(time.Now().Unix()), UpdateTime: int(time.Now().Unix()),
ForceUpdate: forceUpdate, ForceUpdate: forceUpdate,
FileName: fileName,
YamlName: yamlName,
} }
result := dbConn.Model(db.AppVersion{}).Where("app_type = ?", appType).Updates(&app) result := dbConn.Model(db.AppVersion{}).Where("app_type = ?", appType).Updates(&app)
if result.Error != nil { if result.Error != nil {

@ -39,8 +39,8 @@ func GetNewFileNameAndContentType(fileName string, fileType int) (string, string
return newName, contentType return newName, contentType
} }
func GetUploadAppNewName(appType int, version string) (string, string, error) { func GetUploadAppNewName(appType int, version, fileName, yamlName string) (string, string, error) {
var newFileName, newYamlName = "_" + version + "_app_", version + "_yaml" var newFileName, newYamlName = "_" + version + "_app", "_" + version + "_yaml"
switch appType { switch appType {
case constant.IOSPlatformID: case constant.IOSPlatformID:
newFileName = constant.IOSPlatformStr + newFileName newFileName = constant.IOSPlatformStr + newFileName
@ -66,5 +66,9 @@ func GetUploadAppNewName(appType int, version string) (string, string, error) {
default: default:
return "", "", errors.New("invalid app type") 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 return newFileName, newYamlName, nil
} }

Loading…
Cancel
Save