chore: seed migration objects batch 5
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
package sysin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/dict"
|
||||
"hotgo/internal/model/input/form"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
type ImAppReleaseListInp struct {
|
||||
form.PageReq
|
||||
Platform string `json:"platform" dc:"平台"`
|
||||
Channel string `json:"channel" dc:"渠道"`
|
||||
}
|
||||
|
||||
func (in *ImAppReleaseListInp) Filter(ctx context.Context) (err error) {
|
||||
in.Platform = strings.TrimSpace(in.Platform)
|
||||
in.Channel = strings.TrimSpace(in.Channel)
|
||||
if in.Platform != "" && !dict.HasOptionKey(consts.ImAppPlatformOptions, in.Platform) {
|
||||
return gerror.New("客户端平台不合法")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ImAppReleaseModel struct {
|
||||
Id int64 `json:"id" dc:"ID"`
|
||||
Platform string `json:"platform" dc:"平台"`
|
||||
Channel string `json:"channel" dc:"渠道"`
|
||||
LatestVersion string `json:"latestVersion" dc:"最新版本"`
|
||||
MinSupportedVersion string `json:"minSupportedVersion" dc:"最低支持版本"`
|
||||
UpdateType string `json:"updateType" dc:"更新类型"`
|
||||
ReleaseNotes string `json:"releaseNotes" dc:"更新说明"`
|
||||
StoreUrl string `json:"storeUrl" dc:"商店地址"`
|
||||
PackageUrl string `json:"packageUrl" dc:"安装包地址"`
|
||||
Checksum string `json:"checksum" dc:"校验值"`
|
||||
RemindAfterSeconds int `json:"remindAfterSeconds" dc:"再次提醒秒数"`
|
||||
PublishedAt *gtime.Time `json:"publishedAt" dc:"发布时间"`
|
||||
CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间"`
|
||||
UpdatedAt *gtime.Time `json:"updatedAt" dc:"更新时间"`
|
||||
}
|
||||
|
||||
type ImAppReleaseEditInp struct {
|
||||
Id int64 `json:"id" dc:"ID"`
|
||||
Platform string `json:"platform" v:"required#平台不能为空" dc:"平台"`
|
||||
Channel string `json:"channel" v:"required#渠道不能为空" dc:"渠道"`
|
||||
LatestVersion string `json:"latestVersion" v:"required#最新版本不能为空" dc:"最新版本"`
|
||||
MinSupportedVersion string `json:"minSupportedVersion" v:"required#最低支持版本不能为空" dc:"最低支持版本"`
|
||||
UpdateType string `json:"updateType" v:"required#更新类型不能为空" dc:"更新类型"`
|
||||
ReleaseNotes string `json:"releaseNotes" dc:"更新说明"`
|
||||
StoreUrl string `json:"storeUrl" dc:"商店地址"`
|
||||
PackageUrl string `json:"packageUrl" dc:"安装包地址"`
|
||||
Checksum string `json:"checksum" dc:"校验值"`
|
||||
RemindAfterSeconds int `json:"remindAfterSeconds" dc:"再次提醒秒数"`
|
||||
}
|
||||
|
||||
func (in *ImAppReleaseEditInp) Filter(ctx context.Context) (err error) {
|
||||
in.Platform = strings.TrimSpace(in.Platform)
|
||||
in.Channel = strings.TrimSpace(in.Channel)
|
||||
in.LatestVersion = strings.TrimSpace(in.LatestVersion)
|
||||
in.MinSupportedVersion = strings.TrimSpace(in.MinSupportedVersion)
|
||||
in.UpdateType = strings.TrimSpace(in.UpdateType)
|
||||
in.StoreUrl = strings.TrimSpace(in.StoreUrl)
|
||||
in.PackageUrl = strings.TrimSpace(in.PackageUrl)
|
||||
in.Checksum = strings.TrimSpace(in.Checksum)
|
||||
if !dict.HasOptionKey(consts.ImAppPlatformOptions, in.Platform) {
|
||||
return gerror.New("客户端平台不合法")
|
||||
}
|
||||
if in.Channel == "" || strings.ContainsAny(in.Channel, " \t\r\n/") || len([]rune(in.Channel)) > 32 {
|
||||
return gerror.New("渠道不能为空,且不能包含空格或斜杠")
|
||||
}
|
||||
if in.LatestVersion == "" || len([]rune(in.LatestVersion)) > 64 {
|
||||
return gerror.New("最新版本不能为空且不能超过64个字符")
|
||||
}
|
||||
if in.MinSupportedVersion == "" || len([]rune(in.MinSupportedVersion)) > 64 {
|
||||
return gerror.New("最低支持版本不能为空且不能超过64个字符")
|
||||
}
|
||||
latest, err := parseAppVersion(in.LatestVersion)
|
||||
if err != nil {
|
||||
return gerror.New("最新版本号格式不正确,请使用数字点分版本号")
|
||||
}
|
||||
minimum, err := parseAppVersion(in.MinSupportedVersion)
|
||||
if err != nil {
|
||||
return gerror.New("最低支持版本号格式不正确,请使用数字点分版本号")
|
||||
}
|
||||
if compareAppVersion(latest, minimum) < 0 {
|
||||
return gerror.New("最新版本不能低于最低支持版本")
|
||||
}
|
||||
if !dict.HasOptionKey(consts.ImAppUpdateTypeOptions, in.UpdateType) {
|
||||
return gerror.New("更新类型不合法")
|
||||
}
|
||||
if in.RemindAfterSeconds < 0 {
|
||||
return gerror.New("再次提醒时间不能小于0")
|
||||
}
|
||||
if in.Platform == consts.ImAppPlatformIos && in.UpdateType != consts.ImAppUpdateTypeNone {
|
||||
storeURL, parseErr := url.Parse(in.StoreUrl)
|
||||
if parseErr != nil || storeURL.Scheme != "https" || !strings.EqualFold(storeURL.Hostname(), "apps.apple.com") {
|
||||
return gerror.New("iOS更新策略需要配置 apps.apple.com 的 HTTPS 商店地址")
|
||||
}
|
||||
in.PackageUrl = ""
|
||||
in.Checksum = ""
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseAppVersion(raw string) ([]uint64, error) {
|
||||
raw = strings.TrimPrefix(strings.ToLower(strings.TrimSpace(raw)), "v")
|
||||
parts := strings.Split(raw, ".")
|
||||
if len(parts) == 0 || len(parts) > 8 {
|
||||
return nil, gerror.New("版本号格式不正确")
|
||||
}
|
||||
result := make([]uint64, len(parts))
|
||||
for i, part := range parts {
|
||||
if part == "" {
|
||||
return nil, gerror.New("版本号格式不正确")
|
||||
}
|
||||
value, err := strconv.ParseUint(part, 10, 32)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result[i] = value
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func compareAppVersion(left, right []uint64) int {
|
||||
length := len(left)
|
||||
if len(right) > length {
|
||||
length = len(right)
|
||||
}
|
||||
for i := 0; i < length; i++ {
|
||||
var l, r uint64
|
||||
if i < len(left) {
|
||||
l = left[i]
|
||||
}
|
||||
if i < len(right) {
|
||||
r = right[i]
|
||||
}
|
||||
if l < r {
|
||||
return -1
|
||||
}
|
||||
if l > r {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
Reference in New Issue
Block a user