Browse Source

update

master
dengbiao 1 month ago
parent
commit
1b1d0a2602
2 changed files with 48 additions and 13 deletions
  1. +13
    -13
      enum/sys_cfg.go
  2. +35
    -0
      svc/svc_file_img_format.go

+ 13
- 13
enum/sys_cfg.go View File

@@ -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 "未知"


+ 35
- 0
svc/svc_file_img_format.go View File

@@ -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)
}

Loading…
Cancel
Save