Files
im_manager/server/internal/model/input/sysin/im_app_release.go
T

93 lines
4.3 KiB
Go

package sysin
import (
"context"
"hotgo/internal/consts"
"hotgo/internal/library/dict"
"hotgo/internal/model/input/form"
"strings"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/os/gtime"
)
type ImAppReleaseListInp struct {
form.PageReq
TenantId int64 `json:"tenantId" dc:"租户ID"`
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 {
TenantId int64 `json:"tenantId" dc:"租户ID"`
TenantName string `json:"tenantName" dc:"租户名称"`
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 {
TenantId int64 `json:"tenantId" dc:"租户ID"`
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个字符")
}
if !dict.HasOptionKey(consts.ImAppUpdateTypeOptions, in.UpdateType) {
return gerror.New("更新类型不合法")
}
if in.RemindAfterSeconds < 0 {
return gerror.New("再次提醒时间不能小于0")
}
return nil
}