import { FastifySchema , Response , ResponseError } from "../../../../../types/Server" ; import { Status } from "../../../../../constants/Project" ; import { ErrorCode } from "../../../../../ErrorCode" ; import { RoomDAO , RoomRecordDAO } from "../../../../../dao" ; import { roomNotRunning } from "../../utils/RoomStatus" ; import { AgoraCloudRecordParamsType , AgoraCloudRecordStoppedResponse as ResponseType , } from "../../../../utils/request/agora/Types" ; import { agoraCloudRecordStoppedRequest } from "../../../../utils/request/agora/Agora" ; import { getConnection } from "typeorm" ; import { getCloudRecordData } from "../../utils/Agora" ; import { AbstractController } from "../../../../../abstract/controller" ; import { Controller } from "../../../../../decorator/Controller" ; import { timeExceedRedundancyOneMinute } from "../../utils/CheckTime" ; @ Controller < RequestType , ResponseType > ( { method : "post" , path : "room/record/agora/stopped" , auth : true , } ) export class RecordAgoraStopped extends AbstractController < RequestType , ResponseType > { public static readonly schema : FastifySchema < RequestType > = { body : { type : "object" , required : [ "roomUUID" , "agoraParams" ] , properties : { roomUUID : { type : "string" , format : "uuid-v4" , } , agoraParams : { type : "object" , required : [ "resourceid" , "mode" , "sid" ] , resourceid : { type : "string" , } , mode : { type : "string" , } , sid : { type : "string" , } , } , } , } , } ; public async execute ( ) { const { roomUUID , agoraParams } = this . body ; const userUUID = this . userUUID ; const roomInfo = await RoomDAO ( ) . findOne ( [ "room_status" , "updated_at" ] , { room_uuid : roomUUID , owner_uuid : userUUID , } ) ; if ( roomInfo === undefined ) { return { status : Status . Failed , code : ErrorCode . RoomNotFound , } ; } if ( roomNotRunning ( roomInfo . room_status ) && timeExceedRedundancyOneMinute ( roomInfo . updated_at . valueOf ( ) ) ) { return { status : Status . Failed , code : ErrorCode . RoomNotIsRunning , } ; } let agoraResponse ; await getConnection ( ) . transaction ( async ( t ) => { await RoomRecordDAO ( t ) . update ( { end_time : new Date ( ) , } , { agora_sid : agoraParams . sid , } ) ; const { uid , cname } = await getCloudRecordData ( roomUUID , false ) ; agoraResponse = await agoraCloudRecordStoppedRequest ( agoraParams , { uid , cname , clientRequest : { } , } ) ; } ) ; return { status : Status . Success , data : agoraResponse , } ; } public errorHandler ( error ) { return this . autoHandlerError ( error ) ; } } interface RequestType { body : { roomUUID : string ; agoraParams : AgoraCloudRecordParamsType ; } ; }