stream-mask.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package http
  2. import (
  3. "go-common/library/ecode"
  4. bm "go-common/library/net/http/blademaster"
  5. "strconv"
  6. "strings"
  7. )
  8. // getStreamLastTime 得到流到最后推流时间
  9. func saveMaskByRoomID(c *bm.Context) {
  10. params := c.Request.URL.Query()
  11. roomid := params.Get("room_id")
  12. mask := params.Get("mask")
  13. c.Set("input_data", params)
  14. roomID, err := strconv.ParseInt(roomid, 10, 64)
  15. if err != nil || roomID <= 0 {
  16. c.Set("output_data", "room_id is not right")
  17. c.JSONMap(map[string]interface{}{"message": "room_id is not right"}, ecode.RequestErr)
  18. c.Abort()
  19. return
  20. }
  21. int64mask, err := strconv.ParseInt(mask, 10, 64)
  22. // 验证传参数
  23. if err != nil || int64mask < 0 || int64mask > 1 {
  24. c.Set("output_data", "mask is not right")
  25. c.JSONMap(map[string]interface{}{"message": "mask is not right"}, ecode.RequestErr)
  26. c.Abort()
  27. return
  28. }
  29. //直接修改数据库,更新缓存
  30. result, err := srv.ChangeMaskStreamByRoomID(c, roomID, "", int64mask)
  31. if err != nil {
  32. c.Set("output_data", err)
  33. c.JSONMap(map[string]interface{}{"message": err.Error()}, ecode.RequestErr)
  34. c.Abort()
  35. return
  36. }
  37. c.Set("output_data", result)
  38. c.JSONMap(map[string]interface{}{"data": result}, nil)
  39. }
  40. // getStreamLastTime 得到流到最后推流时间
  41. func saveMaskByStreamName(c *bm.Context) {
  42. params := c.Request.URL.Query()
  43. sname := params.Get("stream_name")
  44. mask := params.Get("mask")
  45. c.Set("input_data", params)
  46. if sname == "" {
  47. c.Set("output_data", "stream_name is not right")
  48. c.JSONMap(map[string]interface{}{"message": "stream_name is not right"}, ecode.RequestErr)
  49. c.Abort()
  50. return
  51. }
  52. int64mask, err := strconv.ParseInt(mask, 10, 64)
  53. // 验证传参数
  54. if err != nil || int64mask < 0 || int64mask > 1 {
  55. c.Set("output_data", "mask is not right")
  56. c.JSONMap(map[string]interface{}{"message": "mask is not right"}, ecode.RequestErr)
  57. c.Abort()
  58. return
  59. }
  60. var newmask int64
  61. var newsname string
  62. if len(sname) > 6 && strings.Contains(sname, "_wmask") {
  63. //设置第三位为1
  64. if int64mask == 0 {
  65. newmask = 3
  66. } else {
  67. newmask = 2
  68. }
  69. newsname = sname[0 : len(sname)-6]
  70. } else if len(sname) > 6 && strings.Contains(sname, "_mmask") {
  71. //设置第四位为1
  72. if int64mask == 0 {
  73. newmask = 5
  74. } else {
  75. newmask = 4
  76. }
  77. newsname = sname[0 : len(sname)-6]
  78. } else {
  79. c.Set("output_data", "stream_name is not right")
  80. c.JSONMap(map[string]interface{}{"message": "stream_name is not right"}, ecode.RequestErr)
  81. c.Abort()
  82. return
  83. }
  84. //直接修改数据库,更新缓存
  85. result, err := srv.ChangeMaskStreamByRoomID(c, 0, newsname, newmask)
  86. if err != nil {
  87. c.Set("output_data", err)
  88. c.JSONMap(map[string]interface{}{"message": err.Error()}, ecode.RequestErr)
  89. c.Abort()
  90. return
  91. }
  92. c.Set("output_data", result)
  93. c.JSONMap(map[string]interface{}{"data": result}, nil)
  94. }