refactor: 移除min_version/base_version_id,后端自动确定基础版本
This commit is contained in:
@@ -226,7 +226,6 @@ func handleGetVersionByID(c *gin.Context) {
|
||||
"force_update": version.ForceUpdate,
|
||||
"update_strategy": version.UpdateStrategy,
|
||||
"update_method": version.UpdateMethod,
|
||||
"min_version": version.MinVersion,
|
||||
"changelog": version.Changelog,
|
||||
"status": computedStatus,
|
||||
"base_version_id": version.BaseVersionID,
|
||||
@@ -246,10 +245,8 @@ type CreateVersionRequest struct {
|
||||
ForceUpdate bool `json:"force_update"`
|
||||
UpdateStrategy string `json:"update_strategy"`
|
||||
UpdateMethod string `json:"update_method"`
|
||||
MinVersion string `json:"min_version"`
|
||||
Description string `json:"description"`
|
||||
Changelog string `json:"changelog"`
|
||||
BaseVersionID *uint `json:"base_version_id"`
|
||||
}
|
||||
|
||||
func handleCreateVersionGlobal(c *gin.Context) {
|
||||
@@ -288,11 +285,9 @@ func handleCreateVersionGlobal(c *gin.Context) {
|
||||
ForceUpdate: req.ForceUpdate,
|
||||
UpdateStrategy: req.UpdateStrategy,
|
||||
UpdateMethod: req.UpdateMethod,
|
||||
MinVersion: req.MinVersion,
|
||||
Description: req.Description,
|
||||
Changelog: req.Changelog,
|
||||
Status: "active",
|
||||
BaseVersionID: req.BaseVersionID,
|
||||
}
|
||||
|
||||
if version.UpdateStrategy == "" {
|
||||
@@ -302,6 +297,18 @@ func handleCreateVersionGlobal(c *gin.Context) {
|
||||
version.UpdateMethod = "manual"
|
||||
}
|
||||
|
||||
if version.UpdateStrategy == "forced" {
|
||||
version.ForceUpdate = true
|
||||
}
|
||||
|
||||
if version.UpdateMethod == "hot" {
|
||||
var lastFullVersion model.Version
|
||||
if err := database.DB.Where("application_id = ? AND update_method = ?", req.ApplicationID, "full").
|
||||
Order("id DESC").First(&lastFullVersion).Error; err == nil {
|
||||
version.BaseVersionID = &lastFullVersion.ID
|
||||
}
|
||||
}
|
||||
|
||||
if err := database.DB.Create(&version).Error; err != nil {
|
||||
response.Error(c, 500, "创建版本失败")
|
||||
return
|
||||
@@ -325,13 +332,10 @@ func handleCreateVersionGlobal(c *gin.Context) {
|
||||
|
||||
type UpdateVersionRequest struct {
|
||||
Version string `json:"version"`
|
||||
ForceUpdate bool `json:"force_update"`
|
||||
UpdateStrategy string `json:"update_strategy"`
|
||||
UpdateMethod string `json:"update_method"`
|
||||
MinVersion string `json:"min_version"`
|
||||
Description string `json:"description"`
|
||||
Changelog string `json:"changelog"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
func handleUpdateVersionGlobal(c *gin.Context) {
|
||||
@@ -381,22 +385,21 @@ func handleUpdateVersionGlobal(c *gin.Context) {
|
||||
}
|
||||
if req.UpdateStrategy != "" {
|
||||
updates["update_strategy"] = req.UpdateStrategy
|
||||
if req.UpdateStrategy == "forced" {
|
||||
updates["force_update"] = true
|
||||
} else {
|
||||
updates["force_update"] = false
|
||||
}
|
||||
}
|
||||
if req.UpdateMethod != "" {
|
||||
updates["update_method"] = req.UpdateMethod
|
||||
}
|
||||
if req.MinVersion != "" {
|
||||
updates["min_version"] = req.MinVersion
|
||||
}
|
||||
if req.Description != "" {
|
||||
updates["description"] = req.Description
|
||||
}
|
||||
if req.Changelog != "" {
|
||||
updates["changelog"] = req.Changelog
|
||||
}
|
||||
if req.Status != "" {
|
||||
updates["status"] = req.Status
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Updates map: %+v\n", updates)
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ func handleAppCheckUpdate(c *gin.Context) {
|
||||
}
|
||||
|
||||
hasUpdate := clientVersion != latestVersion.Version
|
||||
if latestVersion.ForceUpdate {
|
||||
if latestVersion.UpdateStrategy == "forced" {
|
||||
hasUpdate = true
|
||||
}
|
||||
|
||||
@@ -104,7 +104,6 @@ func handleAppCheckUpdate(c *gin.Context) {
|
||||
"update_notes": latestVersion.Description,
|
||||
"update_strategy": latestVersion.UpdateStrategy,
|
||||
"update_method": latestVersion.UpdateMethod,
|
||||
"min_version": latestVersion.MinVersion,
|
||||
"changelog": latestVersion.Changelog,
|
||||
"files": files,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user