feat: 创建和编辑版本时保存文件列表到数据库
- 在 CreateVersionRequest 和 UpdateVersionRequest 中添加 Files 字段 - 创建版本时保存文件列表到 VersionFile 表 - 更新版本时删除旧文件记录并创建新的 - 前端创建和编辑版本时传递文件列表 - 修复检测更新 API 使用正确的字段名 (publish_status=published) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -260,19 +260,29 @@ 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"`
|
||||
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"`
|
||||
}
|
||||
|
||||
type VersionFileInput struct {
|
||||
FilePath string `json:"file_path"`
|
||||
FileName string `json:"file_name"`
|
||||
FileSize int64 `json:"file_size"`
|
||||
FileHash string `json:"file_hash"`
|
||||
FileType string `json:"file_type"`
|
||||
IsRequired bool `json:"is_required"`
|
||||
}
|
||||
|
||||
func handleCreateVersionGlobal(c *gin.Context) {
|
||||
@@ -409,6 +419,25 @@ func handleCreateVersionGlobal(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 保存文件列表
|
||||
if len(req.Files) > 0 {
|
||||
for i, f := range req.Files {
|
||||
versionFile := model.VersionFile{
|
||||
VersionID: version.ID,
|
||||
FilePath: f.FilePath,
|
||||
FileName: f.FileName,
|
||||
FileSize: f.FileSize,
|
||||
FileHash: f.FileHash,
|
||||
FileType: f.FileType,
|
||||
IsRequired: f.IsRequired,
|
||||
SortOrder: i,
|
||||
}
|
||||
if err := database.DB.Create(&versionFile).Error; err != nil {
|
||||
log.Printf("[WARN] Failed to create version file record: %v\n", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
userIDPtr := &userID
|
||||
versionIDPtr := &version.ID
|
||||
service.CreateLog(service.LogParams{
|
||||
@@ -426,18 +455,19 @@ 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"`
|
||||
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"`
|
||||
}
|
||||
|
||||
func handleUpdateVersionGlobal(c *gin.Context) {
|
||||
@@ -575,6 +605,28 @@ func handleUpdateVersionGlobal(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 更新文件列表
|
||||
if len(req.Files) > 0 {
|
||||
// 删除旧的文件记录
|
||||
database.DB.Where("version_id = ?", version.ID).Delete(&model.VersionFile{})
|
||||
// 创建新的文件记录
|
||||
for i, f := range req.Files {
|
||||
versionFile := model.VersionFile{
|
||||
VersionID: version.ID,
|
||||
FilePath: f.FilePath,
|
||||
FileName: f.FileName,
|
||||
FileSize: f.FileSize,
|
||||
FileHash: f.FileHash,
|
||||
FileType: f.FileType,
|
||||
IsRequired: f.IsRequired,
|
||||
SortOrder: i,
|
||||
}
|
||||
if err := database.DB.Create(&versionFile).Error; err != nil {
|
||||
log.Printf("[WARN] Failed to create version file record: %v\n", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
userIDPtr := &userID
|
||||
versionIDPtr := &version.ID
|
||||
service.CreateLog(service.LogParams{
|
||||
|
||||
Reference in New Issue
Block a user