backend: refactor recording metadata retrieval to use MeetStorageService and update StorageProvider interface

This commit is contained in:
Carlos Santos 2025-05-28 15:56:49 +02:00
parent 2e51681cd9
commit 325fb90550
4 changed files with 42 additions and 25 deletions

View File

@ -301,7 +301,7 @@ export class RecordingService {
* @returns A promise that resolves to a MeetRecordingInfo object.
*/
async getRecording(recordingId: string, fields?: string): Promise<MeetRecordingInfo> {
const { recordingInfo } = await this.getMeetRecordingInfoFromMetadata(recordingId);
const { recordingInfo } = await this.storageService.getRecordingMetadata(recordingId);
return UtilsHelper.filterObjectFields(recordingInfo, fields) as MeetRecordingInfo;
}
@ -508,7 +508,7 @@ export class RecordingService {
protected async getDeletableRecordingFiles(
recordingId: string
): Promise<{ filesToDelete: Set<string>; recordingInfo: MeetRecordingInfo }> {
const { metadataFilePath, recordingInfo } = await this.getMeetRecordingInfoFromMetadata(recordingId);
const { metadataFilePath, recordingInfo } = await this.storageService.getRecordingMetadata(recordingId);
const filesToDelete: Set<string> = new Set();
// Validate the recording status
@ -526,23 +526,23 @@ export class RecordingService {
return { filesToDelete, recordingInfo };
}
protected async getMeetRecordingInfoFromMetadata(
recordingId: string
): Promise<{ metadataFilePath: string; recordingInfo: MeetRecordingInfo }> {
const { roomId, egressId, uid } = RecordingHelper.extractInfoFromRecordingId(recordingId);
// protected async getMeetRecordingInfoFromMetadata(
// recordingId: string
// ): Promise<{ metadataFilePath: string; recordingInfo: MeetRecordingInfo }> {
// const { roomId, egressId, uid } = RecordingHelper.extractInfoFromRecordingId(recordingId);
const metadataPath = `${INTERNAL_CONFIG.S3_RECORDINGS_PREFIX}/.metadata/${roomId}/${egressId}/${uid}.json`;
this.logger.debug(`Retrieving metadata for recording ${recordingId} from ${metadataPath}`);
const recordingInfo = (await this.s3Service.getObjectAsJson(metadataPath)) as MeetRecordingInfo;
// const metadataPath = `${INTERNAL_CONFIG.S3_RECORDINGS_PREFIX}/.metadata/${roomId}/${egressId}/${uid}.json`;
// this.logger.debug(`Retrieving metadata for recording ${recordingId} from ${metadataPath}`);
// const recordingInfo = (await this.s3Service.getObjectAsJson(metadataPath)) as MeetRecordingInfo;
if (!recordingInfo) {
throw errorRecordingNotFound(recordingId);
}
// if (!recordingInfo) {
// throw errorRecordingNotFound(recordingId);
// }
this.logger.verbose(`Retrieved metadata for recording ${recordingId} from ${metadataPath}`);
// this.logger.verbose(`Retrieved metadata for recording ${recordingId} from ${metadataPath}`);
return { recordingInfo, metadataFilePath: metadataPath };
}
// return { recordingInfo, metadataFilePath: metadataPath };
// }
protected generateCompositeOptionsFromRequest(layout = 'grid'): RoomCompositeOptions {
return {

View File

@ -2,7 +2,7 @@ import { PutObjectCommandOutput } from '@aws-sdk/client-s3';
import { GlobalPreferences, MeetRecordingInfo, MeetRoom } from '@typings-ce';
import { inject, injectable } from 'inversify';
import INTERNAL_CONFIG from '../../../config/internal-config.js';
import { OpenViduMeetError, RedisKeyName } from '../../../models/index.js';
import { errorRecordingNotFound, OpenViduMeetError, RedisKeyName } from '../../../models/index.js';
import { LoggerService, RedisService, S3Service, StorageProvider } from '../../index.js';
import { RecordingHelper } from '../../../helpers/recording.helper.js';
@ -354,10 +354,23 @@ export class S3StorageProvider<
this.logger.warn('deleteArchivedRoomMetadata is not implemented yet');
}
async getRecordingMetadata(recordingId: string): Promise<MRec | null> {
//TODO : Implement this method to retrieve recording metadata for a room
this.logger.warn('getRecordingMetadata is not implemented yet');
return null;
async getRecordingMetadata(recordingId: string): Promise<{ recordingInfo: MRec; metadataFilePath: string }> {
try {
const metadataPath = RecordingHelper.buildMetadataFilePath(recordingId);
this.logger.debug(`Retrieving metadata for recording ${recordingId} from ${metadataPath}`);
const recordingInfo = (await this.s3Service.getObjectAsJson(metadataPath)) as MRec;
if (!recordingInfo) {
throw errorRecordingNotFound(recordingId);
}
this.logger.verbose(`Retrieved metadata for recording ${recordingId} from ${metadataPath}`);
return { recordingInfo, metadataFilePath: metadataPath };
} catch (error) {
this.handleError(error, `Error fetching recording metadata for recording ${recordingId}`);
throw error;
}
}
async saveRecordingMetadata(recordingInfo: MRec): Promise<MRec> {
@ -371,10 +384,7 @@ export class S3StorageProvider<
}
}
async deleteRecordingMetadata(recordingId: string): Promise<void> {
//TODO : Implement this method to delete recording metadata for a room
this.logger.warn('deleteRecordingMetadata is not implemented yet');
}
async deleteRecordingMetadata(recordingId: string): Promise<void> {}
/**
* Retrieves an object of type U from Redis by the given key.

View File

@ -132,7 +132,7 @@ export interface StorageProvider<
* @param recordingId - The unique identifier of the recording.
* @returns A promise that resolves to the recording metadata, or null if not found.
*/
getRecordingMetadata(recordingId: string): Promise<MRec | null>;
getRecordingMetadata(recordingId: string): Promise<{ recordingInfo: MRec; metadataFilePath: string }>;
/**
* Deletes the recording metadata for a specific recording ID.

View File

@ -192,6 +192,13 @@ export class MeetStorageService<
return this.storageProvider.saveRecordingMetadata(recordingInfo) as Promise<MRec>;
}
async getRecordingMetadata(recordingId: string): Promise<{ recordingInfo: MRec; metadataFilePath: string }> {
return this.storageProvider.getRecordingMetadata(recordingId) as Promise<{
recordingInfo: MRec;
metadataFilePath: string;
}>;
}
/**
* Returns the default global preferences.
* @returns {GPrefs}