From 1afa0bedf932456a5fd4de75ab445b17fa066662 Mon Sep 17 00:00:00 2001 From: dengbiao Date: Tue, 26 Nov 2024 21:02:01 +0800 Subject: [PATCH] updaste --- app/hdl/comm/hdl_comm.go | 37 ++++++++++++++++++++++++++++--------- app/svc/im/svc_group.go | 8 ++++---- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/app/hdl/comm/hdl_comm.go b/app/hdl/comm/hdl_comm.go index 68dd38c..6c2ad69 100644 --- a/app/hdl/comm/hdl_comm.go +++ b/app/hdl/comm/hdl_comm.go @@ -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 diff --git a/app/svc/im/svc_group.go b/app/svc/im/svc_group.go index c0952b3..a41e468 100644 --- a/app/svc/im/svc_group.go +++ b/app/svc/im/svc_group.go @@ -13,8 +13,8 @@ func GroupList(req md.GroupListReq) (err error, resp md.GroupListResp) { var groupIds []int64 if req.GroupAdmin != "" { var user model.User - has, err := db.DbIm.Where("`phone_number`=?", req.GroupAdmin).Get(&user) - if err != nil { + has, err1 := db.DbIm.Where("`phone_number`=?", req.GroupAdmin).Get(&user) + if err1 != nil { return } if !has { @@ -67,8 +67,8 @@ func GroupList(req md.GroupListReq) (err error, resp md.GroupListResp) { UpdateTime: v.UpdateTime, } var groupUser model.GroupUser - has, err := db.DbIm.Where("`group_id`=? and member_type= 1", v.Id).Get(&groupUser) - if err != nil { + has, err1 := db.DbIm.Where("`group_id`=? and member_type= 1", v.Id).Get(&groupUser) + if err1 != nil { return } if has {