backup.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package http
  2. import (
  3. "encoding/json"
  4. "go-common/app/service/video/stream-mng/model"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. "io/ioutil"
  8. "strconv"
  9. )
  10. // createBackupStream 创建备用流
  11. func createBackupStream(c *bm.Context) {
  12. var bs model.BackupStream
  13. switch c.Request.Header.Get("Content-Type") {
  14. case "application/x-www-form-urlencoded":
  15. if len(c.Request.PostForm) == 0 {
  16. c.Set("output_data", "empty params")
  17. c.JSONMap(map[string]interface{}{"message": "empty params"}, ecode.RequestErr)
  18. c.Abort()
  19. return
  20. }
  21. bs.StreamName = c.Request.PostFormValue("stream_name")
  22. bs.Key = c.Request.PostFormValue("key")
  23. default_vendor := c.Request.PostFormValue("default_vendor")
  24. vendor, _ := strconv.ParseInt(default_vendor, 10, 64)
  25. bs.DefaultVendor = vendor
  26. id := c.Request.PostFormValue("room_id")
  27. rid, _ := strconv.ParseInt(id, 10, 64)
  28. bs.RoomID = rid
  29. //bs.ExpiresAt = c.Request.PostFormValue("expires_at")
  30. default:
  31. defer c.Request.Body.Close()
  32. b, err := ioutil.ReadAll(c.Request.Body)
  33. if err != nil {
  34. c.Set("output_data", err.Error())
  35. c.JSONMap(map[string]interface{}{"message": err}, ecode.RequestErr)
  36. c.Abort()
  37. return
  38. }
  39. if len(b) == 0 {
  40. c.Set("output_data", "参数不能为空")
  41. c.JSONMap(map[string]interface{}{"message": "参数不能为空"}, ecode.RequestErr)
  42. c.Abort()
  43. return
  44. }
  45. err = json.Unmarshal(b, &bs)
  46. if err != nil {
  47. c.Set("output_data", err.Error())
  48. c.JSONMap(map[string]interface{}{"message": "请确认格式是否正常"}, ecode.RequestErr)
  49. c.Abort()
  50. return
  51. }
  52. if bs.RoomID <= 0 {
  53. c.Set("output_data", "房间号不正确")
  54. c.JSONMap(map[string]interface{}{"message": "房间号不正确"}, ecode.RequestErr)
  55. c.Abort()
  56. return
  57. }
  58. }
  59. c.Set("input_params", bs)
  60. _, err := srv.CreateBackupStream(c, &bs)
  61. c.JSON(bs, err)
  62. }