diff --git a/src/MeetingRoom/meetingroom.schema.ts b/src/MeetingRoom/meetingroom.schema.ts index 8d2ed5d..1eff06d 100644 --- a/src/MeetingRoom/meetingroom.schema.ts +++ b/src/MeetingRoom/meetingroom.schema.ts @@ -1,14 +1,16 @@ -import { Inject, Injectable } from '@nestjs/common' +import { Inject, Injectable, Logger } from '@nestjs/common' import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos' import { Builder, SchemaContext } from 'src/Graphql/graphql.builder' import { PrismaService } from 'src/Prisma/prisma.service' import { LiveKitService } from 'src/LiveKit/livekit.service' +import { MinioService } from 'src/Minio/minio.service' @Injectable() export class MeetingRoomSchema extends PothosSchema { constructor( @Inject(SchemaBuilderToken) private readonly builder: Builder, private readonly prisma: PrismaService, private readonly livekitService: LiveKitService, + private readonly minioService: MinioService, ) { super() } @@ -22,6 +24,12 @@ export class MeetingRoomSchema extends PothosSchema { collaborators: t.relation('collaborators'), createdAt: t.expose('createdAt', { type: 'DateTime' }), updatedAt: t.expose('updatedAt', { type: 'DateTime' }), + recordUrl: t.string({ + nullable: true, + resolve: async (meetingRoom) => { + return await this.minioService.getRoomRecordUrl(meetingRoom.id) + }, + }), }), }) } diff --git a/src/Minio/minio.service.ts b/src/Minio/minio.service.ts index 97caba5..6abf7a7 100644 --- a/src/Minio/minio.service.ts +++ b/src/Minio/minio.service.ts @@ -123,10 +123,6 @@ export class MinioService { }) }) } - - listRecords(roomId: string) { - return this.minioClient.listObjects(this.configService.get('BUCKET_NAME') ?? 'epess', `epess/records/${roomId}`) - } // export document to docx format by get all pages and convert to docx async exportDocument(id: string) { // get all pages @@ -141,4 +137,22 @@ export class MinioService { // generate a unique file name using uuid return uuidv4() } + // get the record url from minio by searching for the file starting with roomId and ending with .mp4 and returning the presigned url + async getRoomRecordUrl(roomId: string) { + return new Promise(async (resolve, reject) => { + const stream = this.minioClient.listObjects(this.configService.get('BUCKET_NAME') ?? 'epess', `records/${roomId}`, true) + const items: BucketItem[] = [] + + stream.on('data', (item) => { + items.push(item) + }) + stream.on('end', async () => { + const record = items.find((item) => item.name?.endsWith('.mp4')) + resolve(record ? await this.minioClient.presignedUrl('GET', this.configService.get('BUCKET_NAME') ?? 'epess', record.name ?? '') : null) + }) + stream.on('error', (err) => { + reject(err) + }) + }) + } }