feat: auto-generate full package when uploading patch

- Add FullPackagePath, FullPackageSize, FullPackageHash to Version model
- When uploading patch, merge with base full package to create new full package
- Check update API returns full package info for download
- Add package_util.go with merge functions

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-01 11:43:58 +08:00
parent fd98c0dcc4
commit 551f4f1576
4 changed files with 217 additions and 22 deletions
+28 -1
View File
@@ -336,11 +336,38 @@ func handleCreateVersionGlobal(c *gin.Context) {
version.UpdateMethod = "auto"
}
if version.UpdateType == "patch" {
// 处理全量包和补丁包
if version.UpdateType == "full" {
// 全量包:full_package 就是自己
version.FullPackagePath = version.FilePath
version.FullPackageSize = version.FileSize
version.FullPackageHash = version.FileHash
} else if version.UpdateType == "patch" {
// 补丁包:需要找到基础全量包并合并
var lastFullVersion model.Version
if err := database.DB.Where("application_id = ? AND update_type = ?", req.ApplicationID, "full").
Order("id DESC").First(&lastFullVersion).Error; err == nil {
version.BaseVersionID = &lastFullVersion.ID
// 合并生成新的全量包
fullPkgPath, fullPkgSize, fullPkgHash, err := MergePatchWithFullPackage(
lastFullVersion.FullPackagePath,
req.FilePath,
req.ApplicationID,
userID,
)
if err != nil {
log.Printf("[ERROR] Failed to merge patch with full package: %v\n", err)
response.Error(c, 500, "合并补丁包失败: "+err.Error())
return
}
version.FullPackagePath = fullPkgPath
version.FullPackageSize = fullPkgSize
version.FullPackageHash = fullPkgHash
} else {
response.Error(c, 400, "找不到基础全量包,无法创建补丁版本")
return
}
}