diff --git a/enum/sys_cfg.go b/enum/sys_cfg.go index c113c71..7e6b3e8 100644 --- a/enum/sys_cfg.go +++ b/enum/sys_cfg.go @@ -40,31 +40,31 @@ func (gt VideoReward) String() string { } // AliyunOss 阿里云对象存储枚举类 -type AliyunOss int32 +type AliyunOss string const ( - AliyunOssEndpoint = 1 - AliyunOssBucketName = 2 - AliyunOssBucketScheme = 3 - AliyunOssAccessKeyID = 4 - AliyunOssAccessKeySecret = 5 - AliyunOssDomain = 6 + AliyunOssEndpoint = "oss_endpoint" + AliyunOssBucketName = "oss_bucket_name" + AliyunOssBucketScheme = "oss_bucket_scheme" + AliyunOssAccessKeyID = "oss_access_key_id" + AliyunOssAccessKeySecret = "oss_access_key_secret" + AliyunOssDomain = "oss_domain" ) func (gt AliyunOss) String() string { switch gt { case AliyunOssEndpoint: - return "oss_endpoint" + return "oss地域节点" case AliyunOssBucketName: - return "oss_bucket_name" + return "oss存储桶名称" case AliyunOssBucketScheme: - return "oss_bucket_scheme" + return "oss上传方式" case AliyunOssAccessKeyID: - return "oss_access_key_id" + return "oss访问秘钥id" case AliyunOssAccessKeySecret: - return "oss_access_key_secret" + return "oss访问秘钥" case AliyunOssDomain: - return "oss_domain" + return "oss域名" default: return "未知" diff --git a/svc/svc_file_img_format.go b/svc/svc_file_img_format.go new file mode 100644 index 0000000..89b15cb --- /dev/null +++ b/svc/svc_file_img_format.go @@ -0,0 +1,35 @@ +package svc + +import ( + "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" + "fmt" + "github.com/gomodule/redigo/redis" + "strings" + "xorm.io/xorm" +) + +// ImageBucket is 获取域名 +func ImageBucket(engine *xorm.Engine, conn redis.Conn) (string, string) { + sysCfgDb := implement.NewSysCfgDb(engine, conn) + res := sysCfgDb.SysCfgFindWithDb(enum.AliyunOssBucketScheme, enum.AliyunOssDomain) + return res[enum.AliyunOssBucketScheme], res[enum.AliyunOssDomain] +} + +// ImageFormatWithBucket is 格式化成oss 域名 +func ImageFormatWithBucket(scheme, domain, name string) string { + if strings.Contains(name, "http") || name == "" { + return name + } + return fmt.Sprintf("%s://%s/%s", scheme, domain, name) +} + +// ImageFormatWithBucketNew is 格式化成oss 域名 +func ImageFormatWithBucketNew(scheme, domain, name string) string { + if strings.Contains(name, "http") { + return name + } + + name = strings.ReplaceAll(name, "{{host}}", "") + return fmt.Sprintf("%s://%s/%s", scheme, domain, name) +}