64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package controllers
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"server/models"
|
|
"server/services"
|
|
|
|
beego "github.com/beego/beego/v2/server/web"
|
|
)
|
|
|
|
type ApiSoftwareUpgradeController struct {
|
|
beego.Controller
|
|
}
|
|
|
|
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)
|
|
dls := services.ResolveSoftwareDownloadURLs(scheme, host, row.DownloadURLs)
|
|
if platform := strings.ToLower(strings.TrimSpace(c.GetString("platform"))); platform != "" {
|
|
if platformURL := strings.TrimSpace(dls[platform]); platformURL != "" {
|
|
dl = platformURL
|
|
}
|
|
}
|
|
|
|
data := map[string]interface{}{
|
|
"latestVersion": latest,
|
|
"downloadUrl": dl,
|
|
"downloadUrls": dls,
|
|
"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()
|
|
}
|