|
|
@@ -110,6 +110,13 @@ func MenuList(c *gin.Context) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
type ImgReqUploadReq struct { |
|
|
|
FileName string `json:"file_name" binding:"required" example:"文件名"` |
|
|
|
} |
|
|
|
type ImgReqUploadResp struct { |
|
|
|
SignUrl string `json:"sign_url" example:"签名上传url"` |
|
|
|
} |
|
|
|
|
|
|
|
// GetOssUrl |
|
|
|
// @Summary 通用请求-对象存储-上传许可链接(获取) |
|
|
|
// @Tags 对象存储 |
|
|
@@ -121,6 +128,14 @@ func MenuList(c *gin.Context) { |
|
|
|
// @Failure 400 {object} md.Response "具体错误" |
|
|
|
// @Router /api/comm/getOssUrl [get] |
|
|
|
func GetOssUrl(c *gin.Context) { |
|
|
|
var args ImgReqUploadReq |
|
|
|
err := c.ShouldBindJSON(&args) |
|
|
|
if err != nil { |
|
|
|
err = svc.HandleValidateErr(err) |
|
|
|
err1 := err.(e.E) |
|
|
|
e.OutErr(c, err1.Code, err1.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
redisConn := cache.GetPool().Get() |
|
|
|
sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) |
|
|
|
sysCfgs, err := sysCfgDb.SysCfgGetAll() |
|
|
@@ -137,23 +152,27 @@ func GetOssUrl(c *gin.Context) { |
|
|
|
for _, cfg := range *sysCfgs { |
|
|
|
cfgMap[cfg.Key] = cfg.Val |
|
|
|
} |
|
|
|
endpoint := cfgMap[enum2.AliyunOss(enum2.AliyunOssEndpoint).String()] |
|
|
|
bucketName := cfgMap[enum2.AliyunOss(enum2.AliyunOssBucketName).String()] |
|
|
|
objectName := cfgMap[enum2.AliyunOss(enum2.AliyunOssBucketScheme).String()] |
|
|
|
accessKeyID := cfgMap[enum2.AliyunOss(enum2.AliyunOssAccessKeyID).String()] |
|
|
|
accessKeySecret := cfgMap[enum2.AliyunOss(enum2.AliyunOssAccessKeySecret).String()] |
|
|
|
endpoint := cfgMap[enum2.AliyunOssEndpoint] |
|
|
|
bucketName := cfgMap[enum2.AliyunOssBucketName] |
|
|
|
ossBucketScheme := cfgMap[enum2.AliyunOssBucketScheme] |
|
|
|
accessKeyID := cfgMap[enum2.AliyunOssAccessKeyID] |
|
|
|
accessKeySecret := cfgMap[enum2.AliyunOssAccessKeySecret] |
|
|
|
|
|
|
|
client, err := oss.New(endpoint, accessKeyID, accessKeySecret) |
|
|
|
// 创建OSSClient实例。 |
|
|
|
client, err := oss.New(ossBucketScheme+"://"+endpoint, accessKeyID, accessKeySecret) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_AES_ENCODE, err.Error()) |
|
|
|
e.OutErr(c, e.ERR, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 获取存储空间。 |
|
|
|
bucket, err := client.Bucket(bucketName) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_AES_ENCODE, err.Error()) |
|
|
|
e.OutErr(c, e.ERR, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
signedURL, err := bucket.SignURL(objectName, oss.HTTPPut, 60*5) |
|
|
|
|
|
|
|
signedURL, err := bucket.SignURL(args.FileName, oss.HTTPPut, 60*5) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_AES_ENCODE, err.Error()) |
|
|
|
return |
|
|
|