蛋蛋星球-客户端
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

129 rader
3.5 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. // @Param req body comm.ImgReqUploadReq true "签名上传url"
  23. // @Success 200 {string} "许可链接"
  24. // @Failure 400 {object} md.Response "具体错误"
  25. // @Router /api/v1/comm/getOssUrl [POST]
  26. func GetOssUrl(c *gin.Context) {
  27. var args comm.ImgReqUploadReq
  28. err := c.ShouldBindJSON(&args)
  29. if err != nil {
  30. err = svc.HandleValidateErr(err)
  31. err1 := err.(e.E)
  32. e.OutErr(c, err1.Code, err1.Error())
  33. return
  34. }
  35. redisConn := cache.GetPool().Get()
  36. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  37. sysCfgs, err := sysCfgDb.SysCfgGetAll()
  38. if err != nil {
  39. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  40. return
  41. }
  42. if sysCfgs == nil {
  43. e.OutErr(c, e.ERR_CFG_CACHE, nil)
  44. return
  45. }
  46. cfgMap := make(map[string]string, len(*sysCfgs))
  47. for _, cfg := range *sysCfgs {
  48. cfgMap[cfg.Key] = cfg.Val
  49. }
  50. endpoint := cfgMap[enum2.AliyunOssEndpoint]
  51. bucketName := cfgMap[enum2.AliyunOssBucketName]
  52. ossBucketScheme := cfgMap[enum2.AliyunOssBucketScheme]
  53. accessKeyID := cfgMap[enum2.AliyunOssAccessKeyID]
  54. accessKeySecret := cfgMap[enum2.AliyunOssAccessKeySecret]
  55. // 创建OSSClient实例。
  56. client, err := oss.New(ossBucketScheme+"://"+endpoint, accessKeyID, accessKeySecret)
  57. if err != nil {
  58. e.OutErr(c, e.ERR, err.Error())
  59. return
  60. }
  61. // 获取存储空间。
  62. bucket, err := client.Bucket(bucketName)
  63. if err != nil {
  64. e.OutErr(c, e.ERR, err.Error())
  65. return
  66. }
  67. options := []oss.Option{
  68. oss.ContentType(args.ContentType),
  69. }
  70. signedURL, err := bucket.SignURL(args.FileName, oss.HTTPPut, 60*5, options...)
  71. if err != nil {
  72. e.OutErr(c, e.ERR_AES_ENCODE, err.Error())
  73. return
  74. }
  75. e.OutSuc(c, signedURL, nil)
  76. }
  77. // AccessRecords
  78. // @Summary 通用请求-访问记录-页面记录
  79. // @Tags 访问记录
  80. // @Description 页面记录
  81. // @Accept json
  82. // @Produce json
  83. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  84. // @Param req body comm.AccessRecordsReq true "页面标识"
  85. // @Success 200 {string} "success"
  86. // @Success 200 {string} "data exist"
  87. // @Failure 400 {object} md.Response "具体错误"
  88. func AccessRecords(c *gin.Context) {
  89. var req *comm.AccessRecordsReq
  90. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  91. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  92. return
  93. }
  94. user := svc.GetUser(c)
  95. date := time.Now().Format("2006-01-02")
  96. recordsDb := implement.NewEggAccessRecordsDb(db.Db)
  97. exist, err := recordsDb.EggAccessRecordsExist(user.Id, date, req.Index)
  98. if err != nil {
  99. e.OutErr(c, e.ERR_DB_ORM, nil)
  100. }
  101. if exist {
  102. e.OutSuc(c, "data exist", nil)
  103. return
  104. }
  105. m := model.EggAccessRecords{
  106. Uid: user.Id,
  107. PageIndex: req.Index,
  108. Date: date,
  109. }
  110. _, err = recordsDb.EggAccessRecordsInsert(&m)
  111. if err != nil {
  112. e.OutErr(c, e.ERR_DB_ORM, nil)
  113. return
  114. }
  115. e.OutSuc(c, "success", nil)
  116. }