mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
update app
This commit is contained in:
parent
872f70a418
commit
7be5208daf
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user