蛋蛋星球 后台端
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 5.8 KiB

1 month ago
1 month ago
1 week ago
1 month ago
1 month ago
1 month ago
1 month ago
4 weeks ago
1 month ago
1 month ago
1 week ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
3 weeks ago
1 month ago
1 month ago
3 weeks ago
1 month ago
1 month ago
1 month ago
4 weeks ago
1 month ago
1 month ago
1 week ago
1 month ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
3 weeks ago
1 month ago
3 weeks ago
1 month ago
1 month ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. "applet/app/utils/logx"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/dao"
  9. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  10. enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
  11. "github.com/gin-gonic/gin"
  12. )
  13. // GetBasic
  14. // @Summary 设置中心-对象存储-对象存储设置(获取)
  15. // @Tags 对象存储
  16. // @Description 对象存储设置(获取)
  17. // @Accept json
  18. // @Produce json
  19. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  20. // @Success 200 {object} md.GetBasicResp "设置列表"
  21. // @Failure 400 {object} md.Response "具体错误"
  22. // @Router /api/settCenter/oss/aliYun/getBasic [get]
  23. func GetBasic(c *gin.Context) {
  24. redisConn := cache.GetPool().Get()
  25. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  26. defer func(sysCfgDb dao.SysCfgDao) {
  27. err := sysCfgDb.Close()
  28. if err != nil {
  29. logx.Error("redis close err:" + err.Error()) // 记录错误信息
  30. }
  31. }(sysCfgDb)
  32. sysCfg, err := sysCfgDb.SysCfgGetAll()
  33. if err != nil {
  34. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  35. return
  36. }
  37. cfgMap := make(map[string]string, len(*sysCfg))
  38. for _, cfg := range *sysCfg {
  39. cfgMap[cfg.Key] = cfg.Val
  40. }
  41. endpoint, ok := cfgMap[enum2.AliyunOssEndpoint]
  42. if !ok {
  43. sysCfgDb.SysCfgInsert(enum2.AliyunOssEndpoint, "", enum2.AliyunOss(enum2.AliyunOssEndpoint).String())
  44. endpoint = ""
  45. }
  46. bucketName, ok := cfgMap[enum2.AliyunOssBucketName]
  47. if !ok {
  48. sysCfgDb.SysCfgInsert(enum2.AliyunOssBucketName, "", enum2.AliyunOss(enum2.AliyunOssBucketName).String())
  49. bucketName = ""
  50. }
  51. bucketScheme, ok := cfgMap[enum2.AliyunOssBucketScheme]
  52. if !ok {
  53. sysCfgDb.SysCfgInsert(enum2.AliyunOssBucketScheme, "", enum2.AliyunOss(enum2.AliyunOssBucketScheme).String())
  54. bucketScheme = ""
  55. }
  56. accessKeyID, ok := cfgMap[enum2.AliyunOssAccessKeyID]
  57. if !ok {
  58. sysCfgDb.SysCfgInsert(enum2.AliyunOssAccessKeyID, "", enum2.AliyunOss(enum2.AliyunOssAccessKeyID).String())
  59. accessKeyID = ""
  60. }
  61. accessKeySecret, ok := cfgMap[enum2.AliyunOssAccessKeySecret]
  62. if !ok {
  63. sysCfgDb.SysCfgInsert(enum2.AliyunOssAccessKeySecret, "", enum2.AliyunOss(enum2.AliyunOssAccessKeySecret).String())
  64. accessKeySecret = ""
  65. }
  66. domain, ok := cfgMap[enum2.AliyunOssDomain]
  67. if !ok {
  68. sysCfgDb.SysCfgInsert(enum2.AliyunOssDomain, "", enum2.AliyunOss(enum2.AliyunOssDomain).String())
  69. domain = ""
  70. }
  71. options, ok := cfgMap[enum2.AliyunOptions]
  72. if !ok {
  73. sysCfgDb.SysCfgInsert(enum2.AliyunOptions, "", enum2.AliyunOss(enum2.AliyunOptions).String())
  74. }
  75. assumeRoleARN, ok := cfgMap[enum2.AliyunOssAssumeRoleARN]
  76. if !ok {
  77. sysCfgDb.SysCfgInsert(enum2.AliyunOssAssumeRoleARN, "", enum2.AliyunOss(enum2.AliyunOssAssumeRoleARN).String())
  78. }
  79. assumeRoleAccessKeySecret, ok := cfgMap[enum2.AliyunOssAssumeRoleAccessKeySecret]
  80. if !ok {
  81. sysCfgDb.SysCfgInsert(enum2.AliyunOssAssumeRoleAccessKeySecret, "", enum2.AliyunOss(enum2.AliyunOssAssumeRoleAccessKeySecret).String())
  82. }
  83. assumeRoleAccessKeyID, ok := cfgMap[enum2.AliyunOssAssumeRoleAccessKeyID]
  84. if !ok {
  85. sysCfgDb.SysCfgInsert(enum2.AliyunOssAssumeRoleAccessKeyID, "", enum2.AliyunOss(enum2.AliyunOssAssumeRoleAccessKeyID).String())
  86. }
  87. resp := md.GetBasicResp{
  88. OssEndpoint: endpoint,
  89. OssBucketName: bucketName,
  90. OssBucketScheme: bucketScheme,
  91. OssAccessKeyId: accessKeyID,
  92. OssAccessKeySecret: accessKeySecret,
  93. OssObjectDomain: domain,
  94. OssOption: options,
  95. OssAssumeRoleAccessKeyID: assumeRoleAccessKeyID,
  96. OssAssumeRoleAccessKeySecret: assumeRoleAccessKeySecret,
  97. OssAssumeRoleARN: assumeRoleARN,
  98. }
  99. e.OutSuc(c, resp, nil)
  100. }
  101. // SetBasic
  102. // @Summary 设置中心-对象存储-对象存储设置(更新)
  103. // @Tags 对象存储
  104. // @Description 对象存储设置(更新)
  105. // @Accept json
  106. // @Produce json
  107. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  108. // @param req body md.SetBasicReq true "上传需要修改的信息"
  109. // @Success 200 {string} "success"
  110. // @Failure 400 {object} md.Response "具体错误"
  111. // @Router /api/settCenter/oss/aliYun/setBasic [post]
  112. func SetBasic(c *gin.Context) {
  113. var req *md.SetBasicReq
  114. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  115. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  116. return
  117. }
  118. redisConn := cache.GetPool().Get()
  119. cfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  120. defer func(cfgDb dao.SysCfgDao) {
  121. err := cfgDb.Close()
  122. if err != nil {
  123. logx.Error("redis close err:" + err.Error()) // 记录错误信息
  124. }
  125. }(cfgDb)
  126. if req.OssAccessKeyId != "" {
  127. cfgDb.SysCfgUpdate(enum2.AliyunOssAccessKeyID, req.OssAccessKeyId)
  128. }
  129. if req.OssAccessKeySecret != "" {
  130. cfgDb.SysCfgUpdate(enum2.AliyunOssAccessKeySecret, req.OssAccessKeySecret)
  131. }
  132. if req.OssBucketScheme != "" {
  133. cfgDb.SysCfgUpdate(enum2.AliyunOssBucketScheme, req.OssBucketScheme)
  134. }
  135. if req.OssObjectDomain != "" {
  136. cfgDb.SysCfgUpdate(enum2.AliyunOssDomain, req.OssObjectDomain)
  137. }
  138. if req.OssBucketName != "" {
  139. cfgDb.SysCfgUpdate(enum2.AliyunOssBucketName, req.OssBucketName)
  140. }
  141. if req.OssEndpoint != "" {
  142. cfgDb.SysCfgUpdate(enum2.AliyunOssEndpoint, req.OssEndpoint)
  143. }
  144. if req.OssOption != "" {
  145. cfgDb.SysCfgUpdate(enum2.AliyunOptions, req.OssOption)
  146. }
  147. if req.OssAssumeRoleAccessKeyID != "" {
  148. cfgDb.SysCfgUpdate(enum2.AliyunOssAssumeRoleAccessKeyID, req.OssAssumeRoleAccessKeyID)
  149. }
  150. if req.OssAssumeRoleAccessKeySecret != "" {
  151. cfgDb.SysCfgUpdate(enum2.AliyunOssAssumeRoleAccessKeySecret, req.OssAssumeRoleAccessKeySecret)
  152. }
  153. if req.OssAssumeRoleARN != "" {
  154. cfgDb.SysCfgUpdate(enum2.AliyunOssAssumeRoleARN, req.OssAssumeRoleARN)
  155. }
  156. e.OutSuc(c, "success", nil)
  157. }