广告平台(站长下代理使用)
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.
 
 
 
 
 
 

112 lines
3.1 KiB

  1. package hdl
  2. import (
  3. "applet/app/db/implement"
  4. "applet/app/e"
  5. "applet/app/lib/validate"
  6. "applet/app/md"
  7. "applet/app/svc"
  8. "applet/app/utils"
  9. "applet/app/utils/logx"
  10. md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md"
  11. qiniu "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/qiniuyun"
  12. "fmt"
  13. "github.com/gin-gonic/gin"
  14. )
  15. // ImgReqUpload
  16. // @Summary 七牛云上传
  17. // @Tags 七牛云
  18. // @Description 七牛云-七牛云上传
  19. // @param Authorization header string false "验证参数Bearer和token空格拼接"
  20. // @Accept json
  21. // @Produce json
  22. // @Param args body md.ImgReqUpload true "请求参数"
  23. // @Success 200 {string} "success"
  24. // @Failure 400 {object} md.Response "具体错误"
  25. // @Router /api/qiniuyun/upload [POST]
  26. func ImgReqUpload(c *gin.Context) {
  27. var args md.ImgReqUpload
  28. err := c.ShouldBindJSON(&args)
  29. if err != nil {
  30. err = validate.HandleValidateErr(err)
  31. err1 := err.(e.E)
  32. e.OutErr(c, err1.Code, err1.Error())
  33. return
  34. }
  35. // 文件名名称
  36. if args.FileSize < 1 || args.FileName == "" {
  37. logx.Warn(err)
  38. e.OutErr(c, e.ERR_INVALID_ARGS)
  39. return
  40. }
  41. scheme := "http"
  42. if c.Request.TLS != nil {
  43. scheme = "https"
  44. }
  45. // 拼装回调地址
  46. callbackUrl := scheme + "://" + c.Request.Host + "/api/qiniuyun/callback?master_id=" + c.GetString("mid")
  47. NewSysCfgDb := implement.NewSysCfgDb(svc.MasterDb(c), c.GetString("mid"))
  48. stgInfo := NewSysCfgDb.SysCfgFindWithDb(
  49. md2.KEY_CFG_FILE_BUCKET,
  50. md2.KEY_CFG_FILE_HOST,
  51. md2.KEY_CFG_FILE_AK,
  52. md2.KEY_CFG_FILE_SK,
  53. md2.KEY_CFG_FILE_PVD,
  54. md2.KEY_CFG_FILE_REGION,
  55. md2.KEY_CFG_FILE_MAX_SIZE,
  56. md2.KEY_CFG_FILE_EXT,
  57. md2.KEY_CFG_FILE_SCHEME,
  58. md2.KEY_CFG_FILE_AVATAR_THUMBNAIL,
  59. )
  60. if stgInfo == nil {
  61. e.OutErr(c, 400, e.NewErr(400, "配置未设置"))
  62. return
  63. }
  64. res, err := qiniu.ImgReqUpload(stgInfo, "", args.Dir, args.FileName, callbackUrl, args.FileSize)
  65. if err != nil {
  66. e.OutErr(c, 400, err.Error())
  67. return
  68. }
  69. my := utils.SerializeStr(res)
  70. var my1 map[string]interface{}
  71. utils.Unserialize([]byte(my), &my1)
  72. e.OutSuc(c, my1, nil)
  73. return
  74. }
  75. func FileImgCallback(c *gin.Context) {
  76. masterID := c.Query("master_id")
  77. c.Set("mid", masterID)
  78. var args md2.FileCallback
  79. err := c.ShouldBindJSON(&args)
  80. if err != nil {
  81. fmt.Println("七牛云上传回调参数错误:>>>>>>>>>>", err)
  82. e.OutErr(c, 200, e.ERR_INVALID_ARGS)
  83. return
  84. }
  85. res := map[string]interface{}{
  86. "name": args.FileName,
  87. "fname": getFileNameURL(c, args.FileName),
  88. "fsize": args.FileSize,
  89. "provider": args.Provider,
  90. "uid": args.Uid,
  91. "dir_id": args.DirId,
  92. "w": args.Width,
  93. "h": args.Height,
  94. }
  95. e.OutSuc(c, &res, nil)
  96. }
  97. func getFileNameURL(c *gin.Context, filename string) string {
  98. NewSysCfgDb := implement.NewSysCfgDb(svc.MasterDb(c), c.GetString("mid"))
  99. protocol := NewSysCfgDb.SysCfgGetWithDb("file_bucket_scheme")
  100. domain := NewSysCfgDb.SysCfgGetWithDb("file_bucket_host")
  101. if protocol != "" && domain != "" {
  102. return protocol + "://" + domain + "/" + filename
  103. }
  104. return filename
  105. }