|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- package aliyun
-
- import (
- "applet/app/db"
- "applet/app/e"
- md "applet/app/md/setCenter/oss/aliyun"
- "applet/app/utils/cache"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- "github.com/gin-gonic/gin"
- )
-
- // GetBasic
- // @Summary 设置中心-对象存储-对象存储设置(获取)
- // @Tags 对象存储
- // @Description 对象存储设置(获取)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Success 200 {object} md.GetBasicResp "设置列表"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/comm/oss/getOssUrl [get]
- func GetBasic(c *gin.Context) {
- redisConn := cache.GetPool().Get()
- sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
- sysCfg, err := sysCfgDb.SysCfgGetAll()
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- cfgMap := make(map[string]string, len(*sysCfg))
- for _, cfg := range *sysCfg {
- cfgMap[cfg.Key] = cfg.Val
- }
- endpoint, ok := cfgMap["oss_endpoint"]
- if !ok {
- sysCfgDb.SysCfgInsert("oss_endpoint", "", "oss地域节点")
- endpoint = ""
- }
- bucketName, ok := cfgMap["oss_bucket_name"]
- if !ok {
- sysCfgDb.SysCfgInsert("oss_bucket_name", "", "oss存储桶名称")
- bucketName = ""
- }
- objectScheme, ok := cfgMap["oss_object_scheme"]
- if !ok {
- sysCfgDb.SysCfgInsert("oss_object_scheme", "", "oss上传方式")
- objectScheme = ""
- }
- accessKeyID, ok := cfgMap["oss_access_key_id"]
- if !ok {
- sysCfgDb.SysCfgInsert("oss_access_key_id", "", "oss访问秘钥id")
- accessKeyID = ""
- }
- accessKeySecret, ok := cfgMap["oss_access_key_secret"]
- if !ok {
- sysCfgDb.SysCfgInsert("oss_access_key_secret", "", "oss访问秘钥")
- accessKeySecret = ""
- }
- domain, ok := cfgMap["oss_object_domain"]
- if !ok {
- sysCfgDb.SysCfgInsert("oss_object_domain", "", "oss域名")
- domain = ""
- }
-
- resp := md.GetBasicResp{
- OssEndpoint: endpoint,
- OssBucketName: bucketName,
- OssObjectScheme: objectScheme,
- OssAccessKeyId: accessKeyID,
- OssAccessKeySecret: accessKeySecret,
- OssObjectDomain: domain,
- }
-
- e.OutSuc(c, resp, nil)
- }
-
- // SetBasic
- // @Summary 设置中心-对象存储-对象存储设置(更新)
- // @Tags 对象存储
- // @Description 对象存储设置(更新)
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @param req body md.SetBasicReq true "上传需要修改的信息"
- // @Success 200 {string} "success"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/comm/oss/getOssUrl [get]
- func SetBasic(c *gin.Context) {
- var req *md.SetBasicReq
- if err1 := c.ShouldBindJSON(&req); err1 != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
- return
- }
-
- redisConn := cache.GetPool().Get()
- cfgDb := implement.NewSysCfgDb(db.Db, redisConn)
-
- if req.OssAccessKeyId != "" {
- cfgDb.SysCfgUpdate("oss_access_key_id", req.OssAccessKeyId)
- }
- if req.OssAccessKeySecret != "" {
- cfgDb.SysCfgUpdate("oss_access_key_secret", req.OssAccessKeySecret)
- }
- if req.OssObjectScheme != "" {
- cfgDb.SysCfgUpdate("oss_object_scheme", req.OssObjectScheme)
- }
- if req.OssObjectDomain != "" {
- cfgDb.SysCfgUpdate("oss_object_domain", req.OssObjectDomain)
- }
- if req.OssBucketName != "" {
- cfgDb.SysCfgUpdate("oss_bucket_name", req.OssBucketName)
- }
- if req.OssEndpoint != "" {
- cfgDb.SysCfgUpdate("oss_endpoint", req.OssEndpoint)
- }
- e.OutSuc(c, "success", nil)
- }
|