feat: add record URL retrieval to MeetingRoom schema and enhance MinioService

- Introduced a new field `recordUrl` in the MeetingRoom schema to fetch the presigned URL for meeting room recordings.
- Implemented `getRoomRecordUrl` method in MinioService to retrieve the recording URL from Minio, enhancing the service's functionality.
- Updated imports in MeetingRoom schema to include MinioService for the new functionality.
This commit is contained in:
2024-12-05 21:10:45 +07:00
parent 62662b0256
commit 10df93d534
2 changed files with 27 additions and 5 deletions

View File

@@ -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 { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
import { Builder, SchemaContext } from 'src/Graphql/graphql.builder' import { Builder, SchemaContext } from 'src/Graphql/graphql.builder'
import { PrismaService } from 'src/Prisma/prisma.service' import { PrismaService } from 'src/Prisma/prisma.service'
import { LiveKitService } from 'src/LiveKit/livekit.service' import { LiveKitService } from 'src/LiveKit/livekit.service'
import { MinioService } from 'src/Minio/minio.service'
@Injectable() @Injectable()
export class MeetingRoomSchema extends PothosSchema { export class MeetingRoomSchema extends PothosSchema {
constructor( constructor(
@Inject(SchemaBuilderToken) private readonly builder: Builder, @Inject(SchemaBuilderToken) private readonly builder: Builder,
private readonly prisma: PrismaService, private readonly prisma: PrismaService,
private readonly livekitService: LiveKitService, private readonly livekitService: LiveKitService,
private readonly minioService: MinioService,
) { ) {
super() super()
} }
@@ -22,6 +24,12 @@ export class MeetingRoomSchema extends PothosSchema {
collaborators: t.relation('collaborators'), collaborators: t.relation('collaborators'),
createdAt: t.expose('createdAt', { type: 'DateTime' }), createdAt: t.expose('createdAt', { type: 'DateTime' }),
updatedAt: t.expose('updatedAt', { type: 'DateTime' }), updatedAt: t.expose('updatedAt', { type: 'DateTime' }),
recordUrl: t.string({
nullable: true,
resolve: async (meetingRoom) => {
return await this.minioService.getRoomRecordUrl(meetingRoom.id)
},
}),
}), }),
}) })
} }

View File

@@ -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 // export document to docx format by get all pages and convert to docx
async exportDocument(id: string) { async exportDocument(id: string) {
// get all pages // get all pages
@@ -141,4 +137,22 @@ export class MinioService {
// generate a unique file name using uuid // generate a unique file name using uuid
return uuidv4() 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<string | null>(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)
})
})
}
} }