diff --git a/packages/server/src/controllers/index.controller.ts b/packages/server/src/controllers/index.controller.ts index 363589bfd..34087b682 100644 --- a/packages/server/src/controllers/index.controller.ts +++ b/packages/server/src/controllers/index.controller.ts @@ -1,27 +1,27 @@ -import { IStandardResponse, SendApiResponse } from '@utils/api.response'; +import { HttpException } from '@exceptions/HttpException'; +import { LivepeerEvent } from '@interfaces/livepeer.interface'; +import { ClippingStatus } from '@interfaces/session.interface'; +import { StateStatus, StateType } from '@interfaces/state.interface'; +import SessionService from '@services/session.service'; +import StageService from '@services/stage.service'; +import StateService from '@services/state.service'; +import { type IStandardResponse, SendApiResponse } from '@utils/api.response'; +import { updateEventVideoById } from '@utils/firebase'; +import { getAsset, getDownloadUrl } from '@utils/livepeer'; +import StorageService from '@utils/s3'; +import { validateWebhook } from '@utils/validateWebhook'; import { + Body, Controller, + FormField, Get, + Header, + Post, Route, + Security, Tags, - Body, - Post, - Header, UploadedFile, - FormField, - Security, } from 'tsoa'; -import startAITools from '@aitools/main'; -import { validateWebhook } from '@utils/validateWebhook'; -import StageService from '@services/stage.service'; -import { LivepeerEvent } from '@interfaces/livepeer.interface'; -import SessionService from '@services/session.service'; -import { getAsset, getDownloadUrl } from '@utils/livepeer'; -import StateService from '@services/state.service'; -import { StateStatus } from '@interfaces/state.interface'; -import StorageService from '@utils/s3'; -import { HttpException } from '@exceptions/HttpException'; -import { updateEventVideoById } from '@utils/firebase'; @Tags('Index') @Route('') @@ -96,18 +96,12 @@ export class IndexController extends Controller { private async assetReady(id: string) { const asset = await getAsset(id); - const session = await this.sessionService.findOne({ - assetId: asset.id, - }); - - if (!session) { - return SendApiResponse('No session found', null, '400'); - } - // const ipfs = await uploadToIpfs(id); + const session = await this.sessionService.findOne({ assetId: asset.id }); + if (!session) throw new HttpException(404, 'No session found'); await this.sessionService.update(session._id.toString(), { - // ipfsURI: ipfs, videoUrl: asset.playbackUrl, playbackId: asset.playbackId, + clippingStatus: ClippingStatus.completed, } as any); if (session.firebaseId && asset.playbackUrl) { @@ -116,19 +110,14 @@ export class IndexController extends Controller { mp4Url: await getDownloadUrl(asset.id), }); } - - const state = await this.stateService.getAll({ - sessionId: session._id.toString(), + const state = await this.stateService.findOne({ + _id: session._id.toString(), + type: StateType.video }); - - if (!state || state.length === 0) { - return SendApiResponse('No state found', null, '400'); - } - await this.stateService.update(state[0]._id.toString(), { + if (!state) throw new HttpException(404, 'No state found'); + await this.stateService.update(state._id.toString(), { status: StateStatus.completed, }); - - // await startAITools(payload.payload.id); } private async assetFailed(id: string) { @@ -137,20 +126,20 @@ export class IndexController extends Controller { assetId: asset.id, }); - if (!session) { - throw 'No session found'; - } + if (!session) throw new HttpException(404, 'No session found'); - const state = await this.stateService.getAll({ + const state = await this.stateService.findOne({ sessionId: session._id.toString(), + type: StateType.video, }); + if (!state) throw new HttpException(404, 'No state found'); - if (!state || state.length === 0) { - throw 'No state found'; - } + await this.sessionService.update(session._id.toString(), { + clippingStatus: ClippingStatus.failed, + } as any); - await this.stateService.update(state[0]._id.toString(), { - status: StateStatus.error, + await this.stateService.update(state._id.toString(), { + status: StateStatus.failed, }); } }