191 lines
5.2 KiB
Go
191 lines
5.2 KiB
Go
package versionser
|
|
|
|
import (
|
|
"91porn-server/common"
|
|
"91porn-server/common/crypt"
|
|
"91porn-server/common/version"
|
|
"91porn-server/models/v/versionmod"
|
|
)
|
|
|
|
func HandleVersionForList(ver, sysType string) (verlist []*versionmod.VersionBody) {
|
|
v1, err := version.New(ver)
|
|
if v1 == nil || err != nil {
|
|
return
|
|
}
|
|
sys := common.HandleSysType(sysType)
|
|
//首次查看当前版本有没有开启 提升,如果有指定的版本,则返回指定的版本,如果没有指定版本,则返回该平台最新的版本,如果没有打开则按照正常流程走
|
|
vermod, err := versionmod.FindOneVersionByPlatVer(sys, ver)
|
|
if vermod != nil && err == nil {
|
|
if vermod.IsUpgrade {
|
|
if vermod.SpecVersion != "" {
|
|
newVersion, _ := versionmod.FindOneVersionByPlatVer(sys, vermod.SpecVersion)
|
|
if newVersion != nil {
|
|
verlist = append(verlist, &versionmod.VersionBody{
|
|
Code: newVersion.Code,
|
|
VersionName: newVersion.VersionName,
|
|
Platform: newVersion.Platform,
|
|
Description: newVersion.Description,
|
|
ForcedUpdate: true,
|
|
URL: newVersion.URL})
|
|
return
|
|
} else {
|
|
return
|
|
}
|
|
} else {
|
|
newVer, _ := versionmod.FindVersion(sys)
|
|
verlist = append(verlist, &versionmod.VersionBody{
|
|
Code: newVer.Code,
|
|
VersionName: newVer.VersionName,
|
|
Platform: newVer.Platform,
|
|
Description: newVer.Description,
|
|
ForcedUpdate: true,
|
|
URL: newVer.URL})
|
|
return
|
|
}
|
|
}
|
|
}
|
|
newVer, err := versionmod.FindVersion(sys)
|
|
if newVer.VersionName == "" || err != nil {
|
|
return
|
|
}
|
|
v2, _ := version.New(newVer.VersionName)
|
|
if v1.GTE(v2) {
|
|
return
|
|
}
|
|
if newVer.VersionRange.Major != "" {
|
|
major, _ := version.New(newVer.VersionRange.Major)
|
|
if v1.GT(major) {
|
|
return
|
|
}
|
|
}
|
|
if newVer.VersionRange.Minor != "" {
|
|
minor, _ := version.New(newVer.VersionRange.Minor)
|
|
if v1.LT(minor) {
|
|
return
|
|
}
|
|
}
|
|
verlist = append(verlist, &versionmod.VersionBody{
|
|
Code: newVer.Code,
|
|
VersionName: newVer.VersionName,
|
|
Platform: newVer.Platform,
|
|
Description: newVer.Description,
|
|
ForcedUpdate: newVer.ForcedUpdate,
|
|
URL: newVer.URL})
|
|
return
|
|
}
|
|
|
|
// 当前版本是否在更新范围
|
|
func HandleVersion(ver string, vermod *versionmod.Version) bool {
|
|
v1, err := version.New(ver)
|
|
if v1 == nil || err != nil {
|
|
return false
|
|
}
|
|
if vermod != nil {
|
|
if vermod.VersionRange.Major == "" && vermod.VersionRange.Minor == "" {
|
|
return true
|
|
}
|
|
if vermod.VersionRange.Major != "" {
|
|
major, _ := version.New(vermod.VersionRange.Major)
|
|
if v1.GT(major) {
|
|
return false
|
|
}
|
|
}
|
|
if vermod.VersionRange.Minor != "" {
|
|
minor, _ := version.New(vermod.VersionRange.Minor)
|
|
if v1.LT(minor) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func CheckVersionBaseOnBuildId(ver, sysType, buildId string) (versionBody []*versionmod.VersionBody) {
|
|
v1, err := version.New(ver)
|
|
if v1 == nil || err != nil {
|
|
return
|
|
}
|
|
sys := common.HandleSysType(sysType)
|
|
//查看当前版本有没有开启 提升,如果有指定的版本,则返回指定的版本,如果没有指定版本,则返回该平台最新的版本,如果没有打开则按照正常流程走
|
|
vermod, err := versionmod.FindOneVersionByPlatVerBuild(sys, ver, buildId)
|
|
if vermod != nil && err == nil {
|
|
if vermod.IsUpgrade {
|
|
if vermod.SpecVersion != "" {
|
|
newVersion, _ := versionmod.FindOneVersionByPlatVerBuild(sys, vermod.SpecVersion, buildId)
|
|
if newVersion != nil {
|
|
versionBody = append(versionBody, &versionmod.VersionBody{
|
|
Code: newVersion.Code,
|
|
VersionName: newVersion.VersionName,
|
|
Platform: newVersion.Platform,
|
|
Description: newVersion.Description,
|
|
ForcedUpdate: true,
|
|
URL: newVersion.URL})
|
|
return
|
|
} else {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//分为带buildId的包 和不带buildId的包
|
|
ver1, err := versionmod.FindVersionBaseOnBuildIdAndPlatForm(buildId, sys)
|
|
if ver1 == nil || err != nil {
|
|
return
|
|
}
|
|
if ver1.Origin == versionmod.TF {
|
|
ver2, err := versionmod.FindVersionBaseOnBuildId(buildId)
|
|
if ver2 == nil || err != nil {
|
|
return
|
|
}
|
|
v2, _ := version.New(ver2.VersionName)
|
|
if v1.GTE(v2) {
|
|
return
|
|
}
|
|
versionBody = append(versionBody, &versionmod.VersionBody{
|
|
Code: ver2.Code,
|
|
VersionName: ver2.VersionName,
|
|
Platform: ver2.Platform,
|
|
Description: ver2.Description,
|
|
ForcedUpdate: ver2.ForcedUpdate,
|
|
URL: GetTFUrl(ver2.URL)})
|
|
} else {
|
|
versionBody = append(versionBody, &versionmod.VersionBody{
|
|
Code: ver1.Code,
|
|
VersionName: ver1.VersionName,
|
|
Platform: ver1.Platform,
|
|
Description: ver1.Description,
|
|
ForcedUpdate: ver1.ForcedUpdate,
|
|
URL: ver1.URL})
|
|
}
|
|
return
|
|
}
|
|
|
|
func GetTFUrl(tf string) string {
|
|
if tf != "" {
|
|
type tfStc struct {
|
|
Url string `json:"url"`
|
|
Name string `json:"name"`
|
|
}
|
|
var tfArr []tfStc
|
|
_ = crypt.JSON2Struct(tf, &tfArr)
|
|
tfArrLen := len(tfArr)
|
|
if tfArrLen == 0 {
|
|
return tf
|
|
}
|
|
weight := 100 / tfArrLen
|
|
chioce := make([]common.Choice, tfArrLen)
|
|
for i := 0; i < len(tfArr); i++ {
|
|
chioce[i] = common.Choice{
|
|
Weight: weight,
|
|
Item: tfArr[i].Url,
|
|
}
|
|
}
|
|
ch, _ := common.WeightedChoice(chioce)
|
|
if v, ok := ch.Item.(string); ok {
|
|
return v
|
|
}
|
|
}
|
|
return tf
|
|
}
|