蛋蛋星球-客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hdl_comm.go 1.9 KiB

2 週之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package comm
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/utils/cache"
  6. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  7. enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
  8. "github.com/aliyun/aliyun-oss-go-sdk/oss"
  9. "github.com/gin-gonic/gin"
  10. )
  11. // GetOssUrl
  12. // @Summary 通用请求-对象存储-上传许可链接(获取)
  13. // @Tags 对象存储
  14. // @Description 上传许可链接(获取)
  15. // @Accept json
  16. // @Produce json
  17. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  18. // @Success 200 {string} "许可链接"
  19. // @Failure 400 {object} md.Response "具体错误"
  20. // @Router /api/comm/getOssUrl [get]
  21. func GetOssUrl(c *gin.Context) {
  22. redisConn := cache.GetPool().Get()
  23. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  24. sysCfgs, err := sysCfgDb.SysCfgGetAll()
  25. if err != nil {
  26. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  27. return
  28. }
  29. if sysCfgs == nil {
  30. e.OutErr(c, e.ERR_CFG_CACHE, nil)
  31. return
  32. }
  33. cfgMap := make(map[string]string, len(*sysCfgs))
  34. for _, cfg := range *sysCfgs {
  35. cfgMap[cfg.Key] = cfg.Val
  36. }
  37. endpoint := cfgMap[enum2.AliyunOss(enum2.AliyunOssEndpoint).String()]
  38. bucketName := cfgMap[enum2.AliyunOss(enum2.AliyunOssBucketName).String()]
  39. objectName := cfgMap[enum2.AliyunOss(enum2.AliyunOssBucketScheme).String()]
  40. accessKeyID := cfgMap[enum2.AliyunOss(enum2.AliyunOssAccessKeyID).String()]
  41. accessKeySecret := cfgMap[enum2.AliyunOss(enum2.AliyunOssAccessKeySecret).String()]
  42. client, err := oss.New(endpoint, accessKeyID, accessKeySecret)
  43. if err != nil {
  44. e.OutErr(c, e.ERR_AES_ENCODE, err.Error())
  45. return
  46. }
  47. bucket, err := client.Bucket(bucketName)
  48. if err != nil {
  49. e.OutErr(c, e.ERR_AES_ENCODE, err.Error())
  50. return
  51. }
  52. signedURL, err := bucket.SignURL(objectName, oss.HTTPPut, 60*5)
  53. if err != nil {
  54. e.OutErr(c, e.ERR_AES_ENCODE, err.Error())
  55. return
  56. }
  57. e.OutSuc(c, signedURL, nil)
  58. }