feat: 版本管理支持多入口文件、安装选项(桌面快捷方式/开始菜单/自动运行/默认安装目录)

This commit is contained in:
Trae AI
2026-06-18 18:15:51 +08:00
parent 9ea0ef4536
commit 77a2dd468f
6 changed files with 364 additions and 176 deletions
+5
View File
@@ -227,6 +227,11 @@ type Version struct {
FileSize int64 `json:"file_size"`
FileHash string `gorm:"size:64" json:"file_hash"`
EntryFile string `gorm:"size:255" json:"entry_file"`
EntryFiles string `gorm:"type:text" json:"entry_files"` // JSON数组,多入口文件
CreateDesktopShortcut bool `gorm:"default:false" json:"create_desktop_shortcut"` // 是否创建桌面快捷方式
CreateStartMenu bool `gorm:"default:false" json:"create_start_menu"` // 是否创建开始菜单
AutoRun bool `gorm:"default:false" json:"auto_run"` // 是否自动运行
DefaultInstallDir string `gorm:"size:500" json:"default_install_dir"` // 默认安装目录
UpdateStrategy string `gorm:"size:20;default:optional" json:"update_strategy"`
UpdateType string `gorm:"size:20;default:full" json:"update_type"`
UpdateMethod string `gorm:"size:20;default:auto" json:"update_method"`
+60 -40
View File
@@ -260,20 +260,25 @@ func handleGetVersionByID(c *gin.Context) {
}
type CreateVersionRequest struct {
ApplicationID uint `json:"application_id"`
Version string `json:"version"`
FilePath string `json:"file_path"`
FileSize int64 `json:"file_size"`
FileHash string `json:"file_hash"`
EntryFile string `json:"entry_file"`
UpdateStrategy string `json:"update_strategy"`
UpdateType string `json:"update_type"`
UpdateMethod string `json:"update_method"`
CustomDownloadURL string `json:"custom_download_url"`
Description string `json:"description"`
Changelog string `json:"changelog"`
BaseVersionID *uint `json:"base_version_id"`
Files []VersionFileInput `json:"files"`
ApplicationID uint `json:"application_id"`
Version string `json:"version"`
FilePath string `json:"file_path"`
FileSize int64 `json:"file_size"`
FileHash string `json:"file_hash"`
EntryFile string `json:"entry_file"`
EntryFiles string `json:"entry_files"`
CreateDesktopShortcut bool `json:"create_desktop_shortcut"`
CreateStartMenu bool `json:"create_start_menu"`
AutoRun bool `json:"auto_run"`
DefaultInstallDir string `json:"default_install_dir"`
UpdateStrategy string `json:"update_strategy"`
UpdateType string `json:"update_type"`
UpdateMethod string `json:"update_method"`
CustomDownloadURL string `json:"custom_download_url"`
Description string `json:"description"`
Changelog string `json:"changelog"`
BaseVersionID *uint `json:"base_version_id"`
Files []VersionFileInput `json:"files"`
}
type VersionFileInput struct {
@@ -312,19 +317,24 @@ func handleCreateVersionGlobal(c *gin.Context) {
}
version := model.Version{
ApplicationID: req.ApplicationID,
Version: req.Version,
FilePath: req.FilePath,
FileSize: req.FileSize,
FileHash: req.FileHash,
EntryFile: req.EntryFile,
UpdateStrategy: req.UpdateStrategy,
UpdateType: req.UpdateType,
UpdateMethod: req.UpdateMethod,
CustomDownloadURL: req.CustomDownloadURL,
Description: req.Description,
Changelog: req.Changelog,
PublishStatus: "draft",
ApplicationID: req.ApplicationID,
Version: req.Version,
FilePath: req.FilePath,
FileSize: req.FileSize,
FileHash: req.FileHash,
EntryFile: req.EntryFile,
EntryFiles: req.EntryFiles,
CreateDesktopShortcut: req.CreateDesktopShortcut,
CreateStartMenu: req.CreateStartMenu,
AutoRun: req.AutoRun,
DefaultInstallDir: req.DefaultInstallDir,
UpdateStrategy: req.UpdateStrategy,
UpdateType: req.UpdateType,
UpdateMethod: req.UpdateMethod,
CustomDownloadURL: req.CustomDownloadURL,
Description: req.Description,
Changelog: req.Changelog,
PublishStatus: "draft",
}
if version.UpdateStrategy == "" {
@@ -455,19 +465,24 @@ func handleCreateVersionGlobal(c *gin.Context) {
}
type UpdateVersionRequest struct {
Version string `json:"version"`
FilePath string `json:"file_path"`
FileSize int64 `json:"file_size"`
FileHash string `json:"file_hash"`
EntryFile string `json:"entry_file"`
UpdateStrategy string `json:"update_strategy"`
UpdateType string `json:"update_type"`
UpdateMethod string `json:"update_method"`
CustomDownloadURL string `json:"custom_download_url"`
Description string `json:"description"`
Changelog string `json:"changelog"`
BaseVersionID *uint `json:"base_version_id"`
Files []VersionFileInput `json:"files"`
Version string `json:"version"`
FilePath string `json:"file_path"`
FileSize int64 `json:"file_size"`
FileHash string `json:"file_hash"`
EntryFile string `json:"entry_file"`
EntryFiles string `json:"entry_files"`
CreateDesktopShortcut bool `json:"create_desktop_shortcut"`
CreateStartMenu bool `json:"create_start_menu"`
AutoRun bool `json:"auto_run"`
DefaultInstallDir string `json:"default_install_dir"`
UpdateStrategy string `json:"update_strategy"`
UpdateType string `json:"update_type"`
UpdateMethod string `json:"update_method"`
CustomDownloadURL string `json:"custom_download_url"`
Description string `json:"description"`
Changelog string `json:"changelog"`
BaseVersionID *uint `json:"base_version_id"`
Files []VersionFileInput `json:"files"`
}
func handleUpdateVersionGlobal(c *gin.Context) {
@@ -525,6 +540,11 @@ func handleUpdateVersionGlobal(c *gin.Context) {
updates["file_hash"] = req.FileHash
}
updates["entry_file"] = req.EntryFile
updates["entry_files"] = req.EntryFiles
updates["create_desktop_shortcut"] = req.CreateDesktopShortcut
updates["create_start_menu"] = req.CreateStartMenu
updates["auto_run"] = req.AutoRun
updates["default_install_dir"] = req.DefaultInstallDir
if req.UpdateStrategy != "" {
updates["update_strategy"] = req.UpdateStrategy
}
+33 -23
View File
@@ -114,17 +114,22 @@ func handleAppCheckUpdate(c *gin.Context) {
}
result := gin.H{
"has_update": true,
"latest_version": latestVersion.Version,
"download_url": downloadURL,
"file_size": downloadSize,
"file_hash": downloadHash,
"entry_file": latestVersion.EntryFile,
"update_notes": latestVersion.Description,
"update_strategy": latestVersion.UpdateStrategy,
"update_type": latestVersion.UpdateType,
"update_method": latestVersion.UpdateMethod,
"changelog": latestVersion.Changelog,
"has_update": true,
"latest_version": latestVersion.Version,
"download_url": downloadURL,
"file_size": downloadSize,
"file_hash": downloadHash,
"entry_file": latestVersion.EntryFile,
"entry_files": latestVersion.EntryFiles,
"create_desktop_shortcut": latestVersion.CreateDesktopShortcut,
"create_start_menu": latestVersion.CreateStartMenu,
"auto_run": latestVersion.AutoRun,
"default_install_dir": latestVersion.DefaultInstallDir,
"update_notes": latestVersion.Description,
"update_strategy": latestVersion.UpdateStrategy,
"update_type": latestVersion.UpdateType,
"update_method": latestVersion.UpdateMethod,
"changelog": latestVersion.Changelog,
}
// 同时返回补丁包信息(如果有),供客户端增量更新使用
@@ -250,18 +255,23 @@ func handleAppCheckUpdate(c *gin.Context) {
// 构建返回结果
result := map[string]interface{}{
"has_update": true,
"current_version": clientVersion,
"latest_version": latestVersion.Version,
"download_url": downloadURL,
"file_size": downloadSize,
"file_hash": downloadHash,
"entry_file": latestVersion.EntryFile,
"update_notes": latestVersion.Description,
"update_strategy": updateStrategy,
"update_type": latestVersion.UpdateType,
"update_method": latestVersion.UpdateMethod,
"changelog": latestVersion.Changelog,
"has_update": true,
"current_version": clientVersion,
"latest_version": latestVersion.Version,
"download_url": downloadURL,
"file_size": downloadSize,
"file_hash": downloadHash,
"entry_file": latestVersion.EntryFile,
"entry_files": latestVersion.EntryFiles,
"create_desktop_shortcut": latestVersion.CreateDesktopShortcut,
"create_start_menu": latestVersion.CreateStartMenu,
"auto_run": latestVersion.AutoRun,
"default_install_dir": latestVersion.DefaultInstallDir,
"update_notes": latestVersion.Description,
"update_strategy": updateStrategy,
"update_type": latestVersion.UpdateType,
"update_method": latestVersion.UpdateMethod,
"changelog": latestVersion.Changelog,
}
// 如果是补丁更新,添加补丁信息