蛋蛋星球 后台端
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_basic.go 4.1 KiB

1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package aliyun
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. md "applet/app/md/setCenter/oss/aliyun"
  6. "applet/app/utils/cache"
  7. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  8. enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
  9. "github.com/gin-gonic/gin"
  10. )
  11. // GetBasic
  12. // @Summary 设置中心-对象存储-对象存储设置(获取)
  13. // @Tags 对象存储
  14. // @Description 对象存储设置(获取)
  15. // @Accept json
  16. // @Produce json
  17. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  18. // @Success 200 {object} md.GetBasicResp "设置列表"
  19. // @Failure 400 {object} md.Response "具体错误"
  20. // @Router /api/comm/oss/getOssUrl [get]
  21. func GetBasic(c *gin.Context) {
  22. redisConn := cache.GetPool().Get()
  23. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  24. sysCfg, err := sysCfgDb.SysCfgGetAll()
  25. if err != nil {
  26. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  27. return
  28. }
  29. cfgMap := make(map[string]string, len(*sysCfg))
  30. for _, cfg := range *sysCfg {
  31. cfgMap[cfg.Key] = cfg.Val
  32. }
  33. endpoint, ok := cfgMap[enum2.AliyunOss(enum2.AliyunOssEndpoint).String()]
  34. if !ok {
  35. sysCfgDb.SysCfgInsert(enum2.AliyunOss(enum2.AliyunOssEndpoint).String(), "", "oss地域节点")
  36. endpoint = ""
  37. }
  38. bucketName, ok := cfgMap[enum2.AliyunOss(enum2.AliyunOssBucketName).String()]
  39. if !ok {
  40. sysCfgDb.SysCfgInsert(enum2.AliyunOss(enum2.AliyunOssBucketName).String(), "", "oss存储桶名称")
  41. bucketName = ""
  42. }
  43. bucketScheme, ok := cfgMap[enum2.AliyunOss(enum2.AliyunOssBucketScheme).String()]
  44. if !ok {
  45. sysCfgDb.SysCfgInsert(enum2.AliyunOss(enum2.AliyunOssBucketScheme).String(), "", "oss上传方式")
  46. bucketScheme = ""
  47. }
  48. accessKeyID, ok := cfgMap[enum2.AliyunOss(enum2.AliyunOssAccessKeyID).String()]
  49. if !ok {
  50. sysCfgDb.SysCfgInsert(enum2.AliyunOss(enum2.AliyunOssAccessKeyID).String(), "", "oss访问秘钥id")
  51. accessKeyID = ""
  52. }
  53. accessKeySecret, ok := cfgMap[enum2.AliyunOss(enum2.AliyunOssAccessKeySecret).String()]
  54. if !ok {
  55. sysCfgDb.SysCfgInsert(enum2.AliyunOss(enum2.AliyunOssAccessKeySecret).String(), "", "oss访问秘钥")
  56. accessKeySecret = ""
  57. }
  58. domain, ok := cfgMap[enum2.AliyunOss(enum2.AliyunOssDomain).String()]
  59. if !ok {
  60. sysCfgDb.SysCfgInsert(enum2.AliyunOss(enum2.AliyunOssDomain).String(), "", "oss域名")
  61. domain = ""
  62. }
  63. resp := md.GetBasicResp{
  64. OssEndpoint: endpoint,
  65. OssBucketName: bucketName,
  66. OssBucketScheme: bucketScheme,
  67. OssAccessKeyId: accessKeyID,
  68. OssAccessKeySecret: accessKeySecret,
  69. OssObjectDomain: domain,
  70. }
  71. e.OutSuc(c, resp, nil)
  72. }
  73. // SetBasic
  74. // @Summary 设置中心-对象存储-对象存储设置(更新)
  75. // @Tags 对象存储
  76. // @Description 对象存储设置(更新)
  77. // @Accept json
  78. // @Produce json
  79. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  80. // @param req body md.SetBasicReq true "上传需要修改的信息"
  81. // @Success 200 {string} "success"
  82. // @Failure 400 {object} md.Response "具体错误"
  83. // @Router /api/comm/oss/getOssUrl [get]
  84. func SetBasic(c *gin.Context) {
  85. var req *md.SetBasicReq
  86. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  87. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  88. return
  89. }
  90. redisConn := cache.GetPool().Get()
  91. cfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  92. if req.OssAccessKeyId != "" {
  93. cfgDb.SysCfgUpdate(enum2.AliyunOss(enum2.AliyunOssAccessKeyID).String(), req.OssAccessKeyId)
  94. }
  95. if req.OssAccessKeySecret != "" {
  96. cfgDb.SysCfgUpdate(enum2.AliyunOss(enum2.AliyunOssAccessKeySecret).String(), req.OssAccessKeySecret)
  97. }
  98. if req.OssBucketScheme != "" {
  99. cfgDb.SysCfgUpdate(enum2.AliyunOss(enum2.AliyunOssBucketScheme).String(), req.OssBucketScheme)
  100. }
  101. if req.OssObjectDomain != "" {
  102. cfgDb.SysCfgUpdate(enum2.AliyunOss(enum2.AliyunOssDomain).String(), req.OssObjectDomain)
  103. }
  104. if req.OssBucketName != "" {
  105. cfgDb.SysCfgUpdate(enum2.AliyunOss(enum2.AliyunOssBucketName).String(), req.OssBucketName)
  106. }
  107. if req.OssEndpoint != "" {
  108. cfgDb.SysCfgUpdate(enum2.AliyunOss(enum2.AliyunOssEndpoint).String(), req.OssEndpoint)
  109. }
  110. e.OutSuc(c, "success", nil)
  111. }