Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

45 lines
2.1KB

  1. # -*-coding:utf-8 -*-
  2. from multiprocessing import Queue
  3. from fastapi import APIRouter, Depends
  4. from loguru import logger
  5. from bean.File import UploadRequest, CallbackRequest
  6. from bean.Result import JsonResult
  7. from common.Constant import get_share_queue, get_task_record
  8. from enums.HttpExceptionEnum import UploadExceptionType
  9. from exception.CustomerException import ServiceException
  10. from util.QueUtil import put_queue
  11. router = APIRouter()
  12. @router.post("/start", tags=['媒体文件上传启动接口'], response_model=JsonResult)
  13. async def startPushStream(req: UploadRequest, msg_queue: Queue = Depends(get_share_queue),
  14. task_record: dict = Depends(get_task_record)):
  15. logger.info("接收到推流启动接口调用, 请求体: {}", req.json())
  16. if task_record["upload"] is not None:
  17. raise ServiceException(code=UploadExceptionType.TASK_IS_EXECUTING.value[0],
  18. msg=UploadExceptionType.TASK_IS_EXECUTING.value[1])
  19. put_queue(msg_queue, ("upload", {"request_id": req.requestId, "command": "start",
  20. "callback_url": req.callbackUrl}), timeout=2,
  21. is_throw_ex=True)
  22. return JsonResult.success()
  23. @router.put("/stop", tags=['媒体文件上传停止接口'], response_model=JsonResult)
  24. async def stopPushStream(req: UploadRequest, msg_queue: Queue = Depends(get_share_queue),
  25. task_record: dict = Depends(get_task_record)):
  26. logger.info("接收到推流停止接口调用, 请求体: {}", req.json())
  27. if task_record["upload"] is None:
  28. raise ServiceException(code=UploadExceptionType.TASK_NOT_EXISTS.value[0],
  29. msg=UploadExceptionType.TASK_NOT_EXISTS.value[1])
  30. put_queue(msg_queue, ("upload", {"request_id": req.requestId, "command": "stop"}), timeout=2, is_throw_ex=True)
  31. return JsonResult.success()
  32. @router.post("/callback", tags=['自验证回调接口'], response_model=JsonResult)
  33. async def stopPushStream(req: CallbackRequest):
  34. print("接受回调请求, 请求体: ", req.json())
  35. return JsonResult.success()