upload.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package service
  2. import (
  3. "dsbqj-admin/model/mysql"
  4. "dsbqj-admin/pkg/cache"
  5. "errors"
  6. "fmt"
  7. "github.com/aliyun/credentials-go/credentials/utils"
  8. "github.com/goccy/go-json"
  9. "time"
  10. )
  11. /*
  12. oss 层级规范
  13. |- 主目录 [models]|[maps]|[musics]|[effects] ....
  14. |- 子目录 uuid为目录名
  15. |- 子目录 [source] 源数据
  16. |- 源数据结构
  17. |- 文件1 perviewImage.jpg // 源数据预览图
  18. |- 文件2 renderImage.jpg // 源数据渲染图
  19. |- 文件
  20. */
  21. // UploadTokenService 获得上传oss token的服务
  22. type UploadReportService struct {
  23. Message string `form:"message" json:"message"`
  24. Source string `form:"source" json:"source"`
  25. Line string `form:"line" json:"line"`
  26. Colno string `form:"colno" json:"colno"`
  27. Err string `form:"err" json:"err"`
  28. Aid string `form:"aid" json:"aid"`
  29. Sid string `form:"sid" json:"sid"`
  30. Uid string `form:"uid" json:"uid"`
  31. Channel string `form:"channel" json:"channel"`
  32. Path string `form:"path" json:"path"`
  33. }
  34. func (service *UploadReportService) Create() error {
  35. buf, _ := json.Marshal(service)
  36. str := utils.GetMD5Base64(buf)
  37. key := fmt.Sprintf("%s:%s", "ClientErrReport", service.Aid)
  38. // 检查数据是否冗余
  39. success, err := cache.RedisReport.SetNX(key, str, 60*time.Second).Result()
  40. if !success {
  41. return errors.New("请勿重复提交")
  42. }
  43. fmt.Println(str, success)
  44. var report = new(mysql.Report)
  45. report.Message = service.Message
  46. report.Err = service.Err
  47. report.Source = service.Source
  48. report.Line = service.Line
  49. report.Colno = service.Colno
  50. report.Aid = service.Aid
  51. report.Sid = service.Sid
  52. report.Uid = service.Uid
  53. report.Channel = service.Channel
  54. report.Path = service.Path
  55. err = report.Create()
  56. if err != nil {
  57. return err
  58. }
  59. return nil
  60. }