backend: implement deletion of archived room metadata in MeetStorageService and S3StorageProvider

This commit is contained in:
Carlos Santos 2025-05-28 16:35:41 +02:00
parent 325fb90550
commit 616222fb73
3 changed files with 38 additions and 21 deletions

View File

@ -187,13 +187,11 @@ export class RecordingService {
await this.s3Service.deleteObjects(Array.from(filesToDelete)); await this.s3Service.deleteObjects(Array.from(filesToDelete));
this.logger.info(`Successfully deleted ${recordingId}`); this.logger.info(`Successfully deleted ${recordingId}`);
const roomMetadataFilePath = await this.shouldDeleteRoomMetadata(roomId); const shouldDeleteRoomMetadata = await this.shouldDeleteRoomMetadata(roomId);
if (roomMetadataFilePath) { if (shouldDeleteRoomMetadata) {
await this.s3Service.deleteObjects([ this.logger.verbose(`Deleting room_metadata.json for rooms: ${roomId}}`);
`${INTERNAL_CONFIG.S3_RECORDINGS_PREFIX}/.room_metadata/${roomId}/room_metadata.json` await this.storageService.deleteArchivedRoomMetadata(roomId);
]);
this.logger.verbose(`Successfully deleted room metadata for room ${roomId}`);
} }
return recordingInfo; return recordingInfo;
@ -249,19 +247,21 @@ export class RecordingService {
} }
// Check if the room metadata file should be deleted // Check if the room metadata file should be deleted
const roomMetadataToDelete = []; const roomMetadataToDelete: string[] = [];
const deleteTasks: Promise<void>[] = [];
for (const roomId of roomsToCheck) { for (const roomId of roomsToCheck) {
const roomMetadataFilePath = await this.shouldDeleteRoomMetadata(roomId); const shouldDeleteRoomMetadata = await this.shouldDeleteRoomMetadata(roomId);
if (roomMetadataFilePath) { if (shouldDeleteRoomMetadata) {
roomMetadataToDelete.push(roomMetadataFilePath); deleteTasks.push(this.storageService.deleteArchivedRoomMetadata(roomId));
roomMetadataToDelete.push(roomId);
} }
} }
try { try {
this.logger.verbose(`Deleting room_metadata.json for rooms: ${roomsToCheck}`); this.logger.verbose(`Deleting room_metadata.json for rooms: ${roomMetadataToDelete.join(', ')}`);
await this.s3Service.deleteObjects(roomMetadataToDelete); await Promise.all(deleteTasks);
this.logger.verbose(`BulkDelete: Successfully deleted ${allFilesToDelete.size} room metadata files.`); this.logger.verbose(`BulkDelete: Successfully deleted ${allFilesToDelete.size} room metadata files.`);
} catch (error) { } catch (error) {
this.logger.error(`BulkDelete: Error performing bulk deletion: ${error}`); this.logger.error(`BulkDelete: Error performing bulk deletion: ${error}`);
@ -276,19 +276,15 @@ export class RecordingService {
* are any remaining recording metadata files for the room. * are any remaining recording metadata files for the room.
* *
* @param roomId - The identifier of the room to check * @param roomId - The identifier of the room to check
* @returns The full path to the room metadata file if it should be deleted, or null otherwise * @returns A promise that resolves to a boolean indicating whether the room metadata should be deleted.
*/ */
protected async shouldDeleteRoomMetadata(roomId: string): Promise<string | null> { protected async shouldDeleteRoomMetadata(roomId: string): Promise<boolean | null> {
try { try {
const metadataPrefix = `${INTERNAL_CONFIG.S3_RECORDINGS_PREFIX}/.metadata/${roomId}`; const metadataPrefix = `${INTERNAL_CONFIG.S3_RECORDINGS_PREFIX}/.metadata/${roomId}`;
const { Contents } = await this.s3Service.listObjectsPaginated(metadataPrefix); const { Contents } = await this.s3Service.listObjectsPaginated(metadataPrefix);
// If no metadata files exist or the list is empty, the room metadata should be deleted // If no metadata files exist or the list is empty, the room metadata should be deleted
if (!Contents || Contents.length === 0) { return !Contents || Contents.length === 0;
return `${INTERNAL_CONFIG.S3_RECORDINGS_PREFIX}/.room_metadata/${roomId}/room_metadata.json`;
}
return null;
} catch (error) { } catch (error) {
this.logger.warn(`Error checking room metadata for deletion (room ${roomId}): ${error}`); this.logger.warn(`Error checking room metadata for deletion (room ${roomId}): ${error}`);
return null; return null;

View File

@ -350,8 +350,18 @@ export class S3StorageProvider<
} }
async deleteArchivedRoomMetadata(roomId: string): Promise<void> { async deleteArchivedRoomMetadata(roomId: string): Promise<void> {
//TODO : Implement this method to delete archived room metadata const archivedRoomMetadataPath = `${INTERNAL_CONFIG.S3_RECORDINGS_PREFIX}/.room_metadata/${roomId}/room_metadata.json`;
this.logger.warn('deleteArchivedRoomMetadata is not implemented yet');
try {
await this.s3Service.deleteObjects([archivedRoomMetadataPath]);
this.logger.verbose(`Archived room metadata deleted for room ${roomId} in recordings bucket`);
} catch (error) {
this.logger.error(
`Error deleting archived room metadata for room ${roomId} in recordings bucket: ${error}`
);
this.handleError(error, `Error deleting archived room metadata for room ${roomId}`);
throw error;
}
} }
async getRecordingMetadata(recordingId: string): Promise<{ recordingInfo: MRec; metadataFilePath: string }> { async getRecordingMetadata(recordingId: string): Promise<{ recordingInfo: MRec; metadataFilePath: string }> {

View File

@ -182,6 +182,17 @@ export class MeetStorageService<
return this.storageProvider.updateArchivedRoomMetadata(roomId); return this.storageProvider.updateArchivedRoomMetadata(roomId);
} }
/**
* Deletes the archived metadata for a specific room.
*
* @param roomId - The unique identifier of the room whose archived metadata should be deleted
* @returns A promise that resolves when the archived room metadata has been successfully deleted
* @throws May throw an error if the deletion operation fails or if the room ID is invalid
*/
async deleteArchivedRoomMetadata(roomId: string): Promise<void> {
return this.storageProvider.deleteArchivedRoomMetadata(roomId);
}
/** /**
* Saves recording metadata to the storage provider. * Saves recording metadata to the storage provider.
* *