feat: 为应用版本查询增加appCode参数支持

新增应用版本类型的AppCode字段,修改相关接口和实现以支持通过appCode查询指定应用的最新版本,增加appCode合法性校验,完善缓存键以区分不同应用的版本信息
This commit is contained in:
Austin
2026-10-12 14:59:23 +08:00
parent 0a33d21eb8
commit 6be7796049
4 changed files with 32 additions and 8 deletions
+22 -1
View File
@@ -2287,10 +2287,18 @@ func serveIMAppReleaseLatest(wrt http.ResponseWriter, req *http.Request) {
}
platform := strings.ToLower(strings.TrimSpace(req.URL.Query().Get("platform")))
channel := strings.ToLower(strings.TrimSpace(req.URL.Query().Get("channel")))
appCode := strings.ToLower(strings.TrimSpace(req.URL.Query().Get("app_code")))
currentVersion := strings.TrimSpace(req.URL.Query().Get("current_version"))
if channel == "" {
channel = "stable"
}
if appCode == "" {
appCode = "im"
}
if !isValidAppCode(appCode) {
writeIMError(wrt, req, http.StatusBadRequest, 30000, imReasonMalformedRequest, "malformed request", map[string]any{"field": "app_code"})
return
}
if platform != "ios" && platform != "android" && platform != "web" {
writeIMError(wrt, req, http.StatusBadRequest, 30000, imReasonMalformedRequest, "malformed request", map[string]any{"field": "platform"})
return
@@ -2300,7 +2308,7 @@ func serveIMAppReleaseLatest(wrt http.ResponseWriter, req *http.Request) {
writeIMError(wrt, req, http.StatusBadRequest, 30000, imReasonMalformedRequest, "malformed request", map[string]any{"field": "current_version"})
return
}
release, err := store.AppReleases.Latest(platform, channel)
release, err := store.AppReleases.Latest(appCode, platform, channel)
if err != nil {
if platform == "web" {
logs.Warn.Println("im app release latest: using web fallback", err)
@@ -8782,6 +8790,19 @@ func appReleasePayload(release *types.AppRelease, currentVersion string, hasUpda
}
}
func isValidAppCode(raw string) bool {
if raw == "" || len(raw) > 32 {
return false
}
for _, r := range raw {
if (r >= 'a' && r <= 'z') || (r >= '0' && r <= '9') || r == '-' || r == '_' {
continue
}
return false
}
return true
}
func parseNumericAppVersion(raw string) ([]uint64, error) {
raw = strings.TrimPrefix(strings.ToLower(strings.TrimSpace(raw)), "v")
parts := strings.Split(raw, ".")