蛋蛋星球-客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

113 rindas
3.3 KiB

  1. package comm
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/md/comm"
  6. "applet/app/svc"
  7. "applet/app/utils/cache"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  9. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  10. enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
  11. "github.com/aliyun/aliyun-oss-go-sdk/oss"
  12. "github.com/gin-gonic/gin"
  13. "time"
  14. )
  15. // GetOssUrl
  16. // @Summary 通用请求-对象存储-上传许可链接(获取)
  17. // @Tags 对象存储
  18. // @Description 上传许可链接(获取)
  19. // @Accept json
  20. // @Produce json
  21. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  22. // @Success 200 {string} "许可链接"
  23. // @Failure 400 {object} md.Response "具体错误"
  24. // @Router /api/v1/comm/getOssUrl [get]
  25. func GetOssUrl(c *gin.Context) {
  26. redisConn := cache.GetPool().Get()
  27. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  28. sysCfgs, err := sysCfgDb.SysCfgGetAll()
  29. if err != nil {
  30. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  31. return
  32. }
  33. if sysCfgs == nil {
  34. e.OutErr(c, e.ERR_CFG_CACHE, nil)
  35. return
  36. }
  37. cfgMap := make(map[string]string, len(*sysCfgs))
  38. for _, cfg := range *sysCfgs {
  39. cfgMap[cfg.Key] = cfg.Val
  40. }
  41. endpoint := cfgMap[enum2.AliyunOss(enum2.AliyunOssEndpoint).String()]
  42. bucketName := cfgMap[enum2.AliyunOss(enum2.AliyunOssBucketName).String()]
  43. objectName := cfgMap[enum2.AliyunOss(enum2.AliyunOssBucketScheme).String()]
  44. accessKeyID := cfgMap[enum2.AliyunOss(enum2.AliyunOssAccessKeyID).String()]
  45. accessKeySecret := cfgMap[enum2.AliyunOss(enum2.AliyunOssAccessKeySecret).String()]
  46. client, err := oss.New(endpoint, accessKeyID, accessKeySecret)
  47. if err != nil {
  48. e.OutErr(c, e.ERR_AES_ENCODE, err.Error())
  49. return
  50. }
  51. bucket, err := client.Bucket(bucketName)
  52. if err != nil {
  53. e.OutErr(c, e.ERR_AES_ENCODE, err.Error())
  54. return
  55. }
  56. signedURL, err := bucket.SignURL(objectName, oss.HTTPPut, 60*5)
  57. if err != nil {
  58. e.OutErr(c, e.ERR_AES_ENCODE, err.Error())
  59. return
  60. }
  61. e.OutSuc(c, signedURL, nil)
  62. }
  63. // AccessRecords
  64. // @Summary 通用请求-访问记录-页面记录
  65. // @Tags 访问记录
  66. // @Description 页面记录
  67. // @Accept json
  68. // @Produce json
  69. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  70. // @Param req body comm.AccessRecordsReq true "页面标识"
  71. // @Success 200 {string} "success"
  72. // @Success 200 {string} "data exist"
  73. // @Failure 400 {object} md.Response "具体错误"
  74. // @Router /api/v1/comm/accessRecords [POST]
  75. func AccessRecords(c *gin.Context) {
  76. var req *comm.AccessRecordsReq
  77. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  78. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  79. return
  80. }
  81. user := svc.GetUser(c)
  82. date := time.Now().Format("2006-01-02")
  83. recordsDb := implement.NewEggAccessRecordsDb(db.Db)
  84. exist, err := recordsDb.EggAccessRecordsExist(user.Id, date, req.Index)
  85. if err != nil {
  86. e.OutErr(c, e.ERR_DB_ORM, nil)
  87. }
  88. if exist {
  89. e.OutSuc(c, "data exist", nil)
  90. return
  91. }
  92. m := model.EggAccessRecords{
  93. Uid: user.Id,
  94. PageIndex: req.Index,
  95. Date: date,
  96. }
  97. _, err = recordsDb.EggAccessRecordsInsert(&m)
  98. if err != nil {
  99. e.OutErr(c, e.ERR_DB_ORM, nil)
  100. return
  101. }
  102. e.OutSuc(c, "success", nil)
  103. }