feat: return latest version when no version param provided
If client doesn't provide version parameter, return latest version info instead of returning error Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -87,12 +87,6 @@ func handleAppCheckUpdate(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 客户端必须提供版本号
|
|
||||||
if clientVersion == "" {
|
|
||||||
response.Error(c, 400, "请提供客户端版本号")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 清理版本号:去除空格和前缀 v/V
|
// 清理版本号:去除空格和前缀 v/V
|
||||||
cleanVersion := func(v string) string {
|
cleanVersion := func(v string) string {
|
||||||
v = strings.TrimSpace(v)
|
v = strings.TrimSpace(v)
|
||||||
@@ -100,6 +94,47 @@ func handleAppCheckUpdate(c *gin.Context) {
|
|||||||
v = strings.TrimPrefix(v, "V")
|
v = strings.TrimPrefix(v, "V")
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果没有传入版本号,直接返回最新版本
|
||||||
|
if clientVersion == "" {
|
||||||
|
latestVersion := &allVersions[0]
|
||||||
|
|
||||||
|
// 构建文件列表
|
||||||
|
files := make([]map[string]interface{}, len(latestVersion.Files))
|
||||||
|
for i, f := range latestVersion.Files {
|
||||||
|
files[i] = map[string]interface{}{
|
||||||
|
"file_path": f.FilePath,
|
||||||
|
"file_name": f.FileName,
|
||||||
|
"file_size": f.FileSize,
|
||||||
|
"file_hash": f.FileHash,
|
||||||
|
"file_type": f.FileType,
|
||||||
|
"is_required": f.IsRequired,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确定下载地址:优先使用自定义地址
|
||||||
|
downloadURL := latestVersion.FilePath
|
||||||
|
if latestVersion.CustomDownloadURL != "" {
|
||||||
|
downloadURL = latestVersion.CustomDownloadURL
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Success(c, gin.H{
|
||||||
|
"has_update": true,
|
||||||
|
"latest_version": latestVersion.Version,
|
||||||
|
"download_url": downloadURL,
|
||||||
|
"file_size": latestVersion.FileSize,
|
||||||
|
"file_hash": latestVersion.FileHash,
|
||||||
|
"entry_file": latestVersion.EntryFile,
|
||||||
|
"update_notes": latestVersion.Description,
|
||||||
|
"update_strategy": latestVersion.UpdateStrategy,
|
||||||
|
"update_type": latestVersion.UpdateType,
|
||||||
|
"update_method": latestVersion.UpdateMethod,
|
||||||
|
"changelog": latestVersion.Changelog,
|
||||||
|
"files": files,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
clientVersionClean := cleanVersion(clientVersion)
|
clientVersionClean := cleanVersion(clientVersion)
|
||||||
|
|
||||||
// 找到客户端当前版本对应的版本记录
|
// 找到客户端当前版本对应的版本记录
|
||||||
|
|||||||
Reference in New Issue
Block a user