2 Star 0 Fork 0

BOBO/创想视频核心服务

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
attachment.go 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
zhouyp 提交于 2024-07-16 14:51 . init:初始化内框代码
package validate
import (
"context"
"gitee.com/bobo-rs/creative-framework/pkg/utils"
"gitee.com/bobo-rs/innovideo-services/framework/dao"
"gitee.com/bobo-rs/innovideo-services/framework/service"
"gitee.com/bobo-rs/innovideo-services/library/exception"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gvalid"
)
// RuleRegisterAttachment 注册附件规则
func RuleRegisterAttachment() {
gvalid.RegisterRuleByMap(map[string]gvalid.RuleFunc{
`attach-id-exists`: RuleAttachIdExists,
`attach-exists-url`: RuleAttachExistsUrl,
})
}
// RuleAttachIdExists 通过附件ID检测附件是否存在
func RuleAttachIdExists(ctx context.Context, in gvalid.RuleFuncInput) error {
if in.Value.IsEmpty() {
return nil
}
// 附件ID是否存在
if len(in.Value.String()) != 32 || !utils.AlphaNum(in.Value.String()) {
return gerror.New(`附件ID格式错误`)
}
// 附件是否存在
if ok := service.Attachment().CheckAttachmentExistsByAttachId(ctx, in.Value.String()); !ok {
return gerror.New(`附件不存在`)
}
return nil
}
// RuleAttachExistsUrl 通过URL地址检测附件是否存在
func RuleAttachExistsUrl(ctx context.Context, in gvalid.RuleFuncInput) error {
if in.Value.IsEmpty() {
return nil
}
// 附件URL是否存在
if b, _ := service.Attachment().CheckAttachmentExists(ctx, g.Map{
dao.Attachment.Columns().AttUrl: in.Value.String(),
}); !b {
return exception.Newf(`附件URl地址不存在,%s`, in.Message)
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/bobo-rs/innovideo-services.git
git@gitee.com:bobo-rs/innovideo-services.git
bobo-rs
innovideo-services
创想视频核心服务
v1.0.12

搜索帮助