|
- # -*-coding:utf-8 -*-
- from multiprocessing import Queue
-
- from fastapi import APIRouter, Depends
- from loguru import logger
-
- from bean.File import UploadRequest, CallbackRequest
- from bean.Result import JsonResult
- from common.Constant import get_share_queue, get_task_record
- from enums.HttpExceptionEnum import UploadExceptionType
- from exception.CustomerException import ServiceException
- from util.QueUtil import put_queue
-
- router = APIRouter()
-
-
- @router.post("/start", tags=['媒体文件上传启动接口'], response_model=JsonResult)
- async def startPushStream(req: UploadRequest, msg_queue: Queue = Depends(get_share_queue),
- task_record: dict = Depends(get_task_record)):
- logger.info("接收到推流启动接口调用, 请求体: {}", req.json())
- if task_record["upload"] is not None:
- raise ServiceException(code=UploadExceptionType.TASK_IS_EXECUTING.value[0],
- msg=UploadExceptionType.TASK_IS_EXECUTING.value[1])
- put_queue(msg_queue, ("upload", {"request_id": req.requestId, "command": "start",
- "callback_url": req.callbackUrl}), timeout=2,
- is_throw_ex=True)
- return JsonResult.success()
-
-
- @router.put("/stop", tags=['媒体文件上传停止接口'], response_model=JsonResult)
- async def stopPushStream(req: UploadRequest, msg_queue: Queue = Depends(get_share_queue),
- task_record: dict = Depends(get_task_record)):
- logger.info("接收到推流停止接口调用, 请求体: {}", req.json())
- if task_record["upload"] is None:
- raise ServiceException(code=UploadExceptionType.TASK_NOT_EXISTS.value[0],
- msg=UploadExceptionType.TASK_NOT_EXISTS.value[1])
- put_queue(msg_queue, ("upload", {"request_id": req.requestId, "command": "stop"}), timeout=2, is_throw_ex=True)
- return JsonResult.success()
-
-
- @router.post("/callback", tags=['自验证回调接口'], response_model=JsonResult)
- async def stopPushStream(req: CallbackRequest):
- print("接受回调请求, 请求体: ", req.json())
- return JsonResult.success()
|