fix: 版本编辑时UpdateType变化自动更新全量包,禁止选择自身作为基础版本
This commit is contained in:
@@ -542,6 +542,87 @@ func handleUpdateVersionGlobal(c *gin.Context) {
|
||||
updates["changelog"] = req.Changelog
|
||||
}
|
||||
|
||||
// 验证 BaseVersionID 不能是自身
|
||||
if req.BaseVersionID != nil && *req.BaseVersionID == version.ID {
|
||||
response.Error(c, 400, "基础版本不能选择自身")
|
||||
return
|
||||
}
|
||||
|
||||
// 处理 UpdateType 变化时的全量包更新
|
||||
newUpdateType := req.UpdateType
|
||||
if newUpdateType == "" {
|
||||
newUpdateType = version.UpdateType
|
||||
}
|
||||
|
||||
// 如果 UpdateType 从 full 改为 patch,需要重新生成全量包
|
||||
if version.UpdateType == "full" && newUpdateType == "patch" {
|
||||
// 需要有 BaseVersionID
|
||||
baseVersionID := req.BaseVersionID
|
||||
if baseVersionID == nil {
|
||||
baseVersionID = version.BaseVersionID
|
||||
}
|
||||
if baseVersionID == nil {
|
||||
response.Error(c, 400, "补丁包必须指定基础版本")
|
||||
return
|
||||
}
|
||||
|
||||
var baseVersion model.Version
|
||||
if err := database.DB.First(&baseVersion, *baseVersionID).Error; err != nil {
|
||||
response.Error(c, 400, "基础版本不存在")
|
||||
return
|
||||
}
|
||||
|
||||
baseFullPackagePath := baseVersion.FullPackagePath
|
||||
if baseFullPackagePath == "" {
|
||||
baseFullPackagePath = baseVersion.FilePath
|
||||
}
|
||||
|
||||
// 使用当前 FilePath 作为补丁包
|
||||
patchPath := req.FilePath
|
||||
if patchPath == "" {
|
||||
patchPath = version.FilePath
|
||||
}
|
||||
|
||||
fullPkgPath, fullPkgSize, fullPkgHash, err := MergePatchWithFullPackage(
|
||||
baseFullPackagePath,
|
||||
patchPath,
|
||||
version.ApplicationID,
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] Failed to merge patch with full package: %v\n", err)
|
||||
response.Error(c, 500, "合并补丁包失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
updates["base_version_id"] = baseVersionID
|
||||
updates["full_package_path"] = fullPkgPath
|
||||
updates["full_package_size"] = fullPkgSize
|
||||
updates["full_package_hash"] = fullPkgHash
|
||||
log.Printf("[INFO] Regenerated full package for patch type change: %s, size: %d\n", fullPkgPath, fullPkgSize)
|
||||
}
|
||||
|
||||
// 如果 UpdateType 从 patch 改为 full,全量包就是 FilePath 本身
|
||||
if version.UpdateType == "patch" && newUpdateType == "full" {
|
||||
filePath := req.FilePath
|
||||
if filePath == "" {
|
||||
filePath = version.FilePath
|
||||
}
|
||||
fileSize := req.FileSize
|
||||
if fileSize == 0 {
|
||||
fileSize = version.FileSize
|
||||
}
|
||||
fileHash := req.FileHash
|
||||
if fileHash == "" {
|
||||
fileHash = version.FileHash
|
||||
}
|
||||
|
||||
updates["full_package_path"] = filePath
|
||||
updates["full_package_size"] = fileSize
|
||||
updates["full_package_hash"] = fileHash
|
||||
updates["base_version_id"] = nil
|
||||
log.Printf("[INFO] Set full package to file itself for full type change: %s\n", filePath)
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Updates map: %+v\n", updates)
|
||||
|
||||
// 如果文件被更新,删除旧文件
|
||||
|
||||
Reference in New Issue
Block a user