go-platform/controllers/api_software_upgrade.go
2026-04-08 20:33:02 +08:00

59 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package controllers
import (
"strings"
"server/models"
"server/services"
beego "github.com/beego/beego/v2/server/web"
)
// ApiSoftwareUpgradeController 开放接口:客户端检查更新(无需登录)
type ApiSoftwareUpgradeController struct {
beego.Controller
}
// Check GET /api/softwareupgrade/check?code=desktop-app可选 version 由客户端自行比对 latestVersion
func (c *ApiSoftwareUpgradeController) Check() {
code := strings.TrimSpace(c.GetString("code"))
if code == "" {
c.Data["json"] = map[string]interface{}{"code": 400, "msg": "缺少参数 code产品标识"}
_ = c.ServeJSON()
return
}
var row models.SystemSoftwareUpgrade
err := models.Orm.QueryTable(new(models.SystemSoftwareUpgrade)).
Filter("code", code).
Filter("status", 1).
Filter("delete_time__isnull", true).
One(&row)
if err != nil {
c.Data["json"] = map[string]interface{}{"code": 404, "msg": "产品不存在或已停用"}
_ = c.ServeJSON()
return
}
latest := strings.TrimSpace(row.LatestVersion)
if latest == "" {
latest = "0.0.0"
}
scheme, host := services.PublicRequestBaseURL(&c.Controller)
dl := services.ResolveSoftwareDownloadURL(scheme, host, row.DownloadURL, row.FileID)
data := map[string]interface{}{
"latestVersion": latest,
"downloadUrl": dl,
"forceUpdate": row.ForceUpdate == 1,
"releaseNotes": "",
}
if row.ReleaseNotes != nil {
data["releaseNotes"] = *row.ReleaseNotes
}
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success", "data": data}
_ = c.ServeJSON()
}