upload.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package http
  2. import (
  3. "go-common/app/admin/main/upload/model"
  4. "go-common/library/ecode"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/binding"
  8. )
  9. // ping check server ok.
  10. func ping(c *bm.Context) {
  11. if err := uaSvc.Ping(c); err != nil {
  12. c.Error = err
  13. c.AbortWithStatus(503)
  14. }
  15. }
  16. func add(c *bm.Context) {
  17. var err error
  18. ap := &model.AddParam{}
  19. if err = c.BindWith(ap, binding.FormPost); err != nil {
  20. return
  21. }
  22. c.JSON(nil, uaSvc.Add(c, ap))
  23. }
  24. func list(c *bm.Context) {
  25. var (
  26. err error
  27. )
  28. lp := &model.ListParam{}
  29. if err = c.Bind(lp); err != nil {
  30. return
  31. }
  32. c.JSON(uaSvc.List(c, lp))
  33. }
  34. func deleteFile(c *bm.Context) {
  35. var (
  36. err error
  37. ok bool
  38. adminID interface{}
  39. )
  40. dp := new(model.DeleteParam)
  41. if adminID, ok = c.Get("uid"); !ok {
  42. c.JSON(nil, ecode.UserNotExist)
  43. return
  44. }
  45. dp.AdminID = adminID.(int64)
  46. if err = c.Bind(dp); err != nil {
  47. return
  48. }
  49. c.JSON(nil, uaSvc.Delete(c, dp))
  50. }
  51. func deleteRawFile(c *bm.Context) {
  52. var (
  53. err error
  54. )
  55. dp := new(model.DeleteRawParam)
  56. if err = c.Bind(dp); err != nil {
  57. return
  58. }
  59. c.JSON(nil, uaSvc.DeleteRaw(c, dp))
  60. }
  61. func deleteFileV2(c *bm.Context) {
  62. var (
  63. adminID interface{}
  64. err error
  65. ok bool
  66. )
  67. dp := new(model.DeleteV2Param)
  68. if adminID, ok = c.Get("uid"); !ok {
  69. c.JSON(nil, ecode.UserNotExist)
  70. return
  71. }
  72. dp.AdminID = adminID.(int64)
  73. if err = c.Bind(dp); err != nil {
  74. return
  75. }
  76. if err = uaSvc.DeleteV2(c, dp); err != nil {
  77. log.Error("deleteFileV2 error(%v)", err)
  78. }
  79. c.JSON(nil, err)
  80. }
  81. func multiList(c *bm.Context) {
  82. var (
  83. err error
  84. )
  85. lp := &model.MultiListParam{}
  86. if err = c.Bind(lp); err != nil {
  87. return
  88. }
  89. c.JSON(uaSvc.MultiList(c, lp))
  90. }