|
|
@@ -1,6 +1,7 @@ |
|
|
|
package comm |
|
|
|
|
|
|
|
import ( |
|
|
|
"applet/app/cfg" |
|
|
|
"applet/app/db" |
|
|
|
"applet/app/e" |
|
|
|
"applet/app/enum" |
|
|
@@ -15,6 +16,7 @@ import ( |
|
|
|
sts20150401 "github.com/alibabacloud-go/sts-20150401/v2/client" |
|
|
|
"github.com/aliyun/aliyun-oss-go-sdk/oss" |
|
|
|
"github.com/gin-gonic/gin" |
|
|
|
"os" |
|
|
|
"strings" |
|
|
|
) |
|
|
|
|
|
|
@@ -202,6 +204,60 @@ func CommOss(c *gin.Context, args ImgReqUploadReq) { |
|
|
|
|
|
|
|
e.OutSuc(c, signedURL, nil) |
|
|
|
} |
|
|
|
func NewCommOss(c *gin.Context, args ImgReqUploadReq) { |
|
|
|
sysCfgDb := sys_cfg.NewSysCfgDb(db.Db) |
|
|
|
sysCfgs, err := sysCfgDb.SysCfgGetAll() |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
if sysCfgs == nil { |
|
|
|
e.OutErr(c, e.ERR_CFG_CACHE, nil) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
cfgMap := make(map[string]string, len(*sysCfgs)) |
|
|
|
for _, cfg := range *sysCfgs { |
|
|
|
cfgMap[cfg.Key] = cfg.Val |
|
|
|
} |
|
|
|
endpoint := cfgMap[enum2.AliyunOssEndpoint] |
|
|
|
bucketName := cfgMap[enum2.AliyunOssBucketName] |
|
|
|
ossBucketScheme := cfgMap[enum2.AliyunOssBucketScheme] |
|
|
|
accessKeyID := cfgMap[enum2.AliyunOssAccessKeyID] |
|
|
|
accessKeySecret := cfgMap[enum2.AliyunOssAccessKeySecret] |
|
|
|
if cfg.Prd { |
|
|
|
accessKeyID = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID") |
|
|
|
accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET") |
|
|
|
} |
|
|
|
fmt.Println("ALIBABA_CLOUD_ACCESS_KEY_ID>>>>>>>>", accessKeyID) |
|
|
|
fmt.Println("ALIBABA_CLOUD_ACCESS_KEY_SECRET>>>>>>>>", accessKeySecret) |
|
|
|
|
|
|
|
// 创建OSSClient实例。 |
|
|
|
client, err := oss.New(ossBucketScheme+"://"+endpoint, accessKeyID, accessKeySecret) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 获取存储空间。 |
|
|
|
bucket, err := client.Bucket(bucketName) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
options := []oss.Option{ |
|
|
|
oss.ContentType(args.ContentType), |
|
|
|
} |
|
|
|
|
|
|
|
signedURL, err := bucket.SignURL(args.FileName, oss.HTTPPut, 60*5, options...) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_AES_ENCODE, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
e.OutSuc(c, signedURL, nil) |
|
|
|
} |
|
|
|
|
|
|
|
const STSVoucherRedisKey = "STS_Voucher_Cache_Key" |
|
|
|
|
|
|
|