From 050246e21702139c01688ab94f2f6f26b6ed0c46 Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Mon, 2 Dec 2024 16:09:15 +0800 Subject: [PATCH] add oss format --- enum/sys_cfg.go | 6 ++++++ svc/svc_file_img_format.go | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/enum/sys_cfg.go b/enum/sys_cfg.go index 6960a19..19d0eef 100644 --- a/enum/sys_cfg.go +++ b/enum/sys_cfg.go @@ -50,6 +50,8 @@ const ( AliyunOssAccessKeySecret = "oss_access_key_secret" AliyunOssDomain = "oss_domain" AliyunOptions = "oss_options" + AliyunOssAccountId = "oss_account_id" + AliyunOssRoleName = "oss_role_name" ) func (gt AliyunOss) String() string { @@ -68,6 +70,10 @@ func (gt AliyunOss) String() string { return "oss域名" case AliyunOptions: return "文件上传类型" + case AliyunOssAccountId: + return "阿里云账户id" + case AliyunOssRoleName: + return "oss RAM角色名称" default: return "未知" diff --git a/svc/svc_file_img_format.go b/svc/svc_file_img_format.go index 89b15cb..6aec054 100644 --- a/svc/svc_file_img_format.go +++ b/svc/svc_file_img_format.go @@ -30,6 +30,17 @@ func ImageFormatWithBucketNew(scheme, domain, name string) string { return name } - name = strings.ReplaceAll(name, "{{host}}", "") + name = strings.ReplaceAll(name, "{{tempHost}}", "") return fmt.Sprintf("%s://%s/%s", scheme, domain, name) } + +// ImageFormatWithBucketForDataInfo is 格式化成oss 域名 (只格式化内容中的 url) +func ImageFormatWithBucketForDataInfo(scheme, domain, name string) string { + if strings.Contains(name, "http") { + return name + } + + prefix := fmt.Sprintf("%s://%s/", scheme, domain) + name = strings.ReplaceAll(name, "{{tempHost}}", prefix) + return name +}