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 {
|
type CreateVersionRequest struct {
|
||||||
ApplicationID uint `json:"application_id"`
|
ApplicationID uint `json:"application_id"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
FilePath string `json:"file_path"`
|
FilePath string `json:"file_path"`
|
||||||
FileSize int64 `json:"file_size"`
|
FileSize int64 `json:"file_size"`
|
||||||
FileHash string `json:"file_hash"`
|
FileHash string `json:"file_hash"`
|
||||||
EntryFile string `json:"entry_file"`
|
EntryFile string `json:"entry_file"`
|
||||||
UpdateStrategy string `json:"update_strategy"`
|
UpdateStrategy string `json:"update_strategy"`
|
||||||
UpdateType string `json:"update_type"`
|
UpdateType string `json:"update_type"`
|
||||||
UpdateMethod string `json:"update_method"`
|
UpdateMethod string `json:"update_method"`
|
||||||
CustomDownloadURL string `json:"custom_download_url"`
|
CustomDownloadURL string `json:"custom_download_url"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Changelog string `json:"changelog"`
|
Changelog string `json:"changelog"`
|
||||||
BaseVersionID *uint `json:"base_version_id"`
|
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) {
|
func handleCreateVersionGlobal(c *gin.Context) {
|
||||||
@@ -409,6 +419,25 @@ func handleCreateVersionGlobal(c *gin.Context) {
|
|||||||
return
|
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
|
userIDPtr := &userID
|
||||||
versionIDPtr := &version.ID
|
versionIDPtr := &version.ID
|
||||||
service.CreateLog(service.LogParams{
|
service.CreateLog(service.LogParams{
|
||||||
@@ -426,18 +455,19 @@ func handleCreateVersionGlobal(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UpdateVersionRequest struct {
|
type UpdateVersionRequest struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
FilePath string `json:"file_path"`
|
FilePath string `json:"file_path"`
|
||||||
FileSize int64 `json:"file_size"`
|
FileSize int64 `json:"file_size"`
|
||||||
FileHash string `json:"file_hash"`
|
FileHash string `json:"file_hash"`
|
||||||
EntryFile string `json:"entry_file"`
|
EntryFile string `json:"entry_file"`
|
||||||
UpdateStrategy string `json:"update_strategy"`
|
UpdateStrategy string `json:"update_strategy"`
|
||||||
UpdateType string `json:"update_type"`
|
UpdateType string `json:"update_type"`
|
||||||
UpdateMethod string `json:"update_method"`
|
UpdateMethod string `json:"update_method"`
|
||||||
CustomDownloadURL string `json:"custom_download_url"`
|
CustomDownloadURL string `json:"custom_download_url"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Changelog string `json:"changelog"`
|
Changelog string `json:"changelog"`
|
||||||
BaseVersionID *uint `json:"base_version_id"`
|
BaseVersionID *uint `json:"base_version_id"`
|
||||||
|
Files []VersionFileInput `json:"files"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleUpdateVersionGlobal(c *gin.Context) {
|
func handleUpdateVersionGlobal(c *gin.Context) {
|
||||||
@@ -575,6 +605,28 @@ func handleUpdateVersionGlobal(c *gin.Context) {
|
|||||||
return
|
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
|
userIDPtr := &userID
|
||||||
versionIDPtr := &version.ID
|
versionIDPtr := &version.ID
|
||||||
service.CreateLog(service.LogParams{
|
service.CreateLog(service.LogParams{
|
||||||
|
|||||||
@@ -287,6 +287,7 @@ async function handleSubmit() {
|
|||||||
payload.file_path = uploadedData.value.file_path
|
payload.file_path = uploadedData.value.file_path
|
||||||
payload.file_size = uploadedData.value.file_size
|
payload.file_size = uploadedData.value.file_size
|
||||||
payload.file_hash = uploadedData.value.file_hash
|
payload.file_hash = uploadedData.value.file_hash
|
||||||
|
payload.files = uploadedData.value.files || []
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await api.put(`/dev/versions/${versionId.value}`, payload)
|
const response = await api.put(`/dev/versions/${versionId.value}`, payload)
|
||||||
|
|||||||
@@ -263,6 +263,7 @@ async function handleSubmit() {
|
|||||||
file_path: uploadedData.value.file_path,
|
file_path: uploadedData.value.file_path,
|
||||||
file_size: uploadedData.value.file_size,
|
file_size: uploadedData.value.file_size,
|
||||||
file_hash: uploadedData.value.file_hash,
|
file_hash: uploadedData.value.file_hash,
|
||||||
|
files: uploadedData.value.files || [],
|
||||||
}
|
}
|
||||||
// 如果是补丁版本,添加基础版本ID
|
// 如果是补丁版本,添加基础版本ID
|
||||||
if (formData.value.update_type === 'patch' && formData.value.base_version_id) {
|
if (formData.value.update_type === 'patch' && formData.value.base_version_id) {
|
||||||
|
|||||||
Reference in New Issue
Block a user