backend: add getObjectHeaders method to StorageProvider and implement in S3StorageProvider and MeetStorageService

This commit is contained in:
Carlos Santos 2025-05-29 13:57:31 +02:00
parent 5295d6326e
commit e4b77eb2f6
4 changed files with 40 additions and 4 deletions

View File

@ -395,8 +395,7 @@ export class RecordingService {
if (!recordingPath) throw new Error(`Error extracting path from recording ${recordingId}`);
const data = await this.s3Service.getHeaderObject(recordingPath);
const fileSize = data.ContentLength;
const { contentLength: fileSize } = await this.storageService.getObjectHeaders(recordingPath);
if (!fileSize) {
this.logger.error(`Error getting file size for recording ${recordingId}`);

View File

@ -37,6 +37,26 @@ export class S3StorageProvider<
@inject(RedisService) protected redisService: RedisService
) {}
/**
* Retrieves metadata headers for an object stored in S3.
*
* @param filePath - The path/key of the file in the S3 bucket
* @returns A promise that resolves to an object containing the content length and content type of the file
* @throws Will throw an error if the S3 operation fails or the file doesn't exist
*/
async getObjectHeaders(filePath: string): Promise<{ contentLength?: number; contentType?: string }> {
try {
const data = await this.s3Service.getHeaderObject(filePath);
return {
contentLength: data.ContentLength,
contentType: data.ContentType
};
} catch (error) {
this.logger.error(`Error fetching object headers for ${filePath}: ${error}`);
throw error;
}
}
/**
* Initializes global preferences. If no preferences exist, persists the provided defaults.
* If preferences exist but belong to a different project, they are replaced.

View File

@ -24,6 +24,14 @@ export interface StorageProvider<
*/
initialize(defaultPreferences: GPrefs): Promise<void>;
/**
* Retrives the headers of an object stored in the storage provider.
* This is useful to get the content length and content type of the object without downloading it.
*
* @param filePath - The path of the file to retrieve headers for.
*/
getObjectHeaders(filePath: string): Promise<{ contentLength?: number; contentType?: string }>;
/**
* Retrieves the global preferences of Openvidu Meet.
*
@ -148,5 +156,4 @@ export interface StorageProvider<
* @returns A promise that resolves when the recording binary files have been deleted.
*/
deleteRecordingBinaryFilesByPaths(recordingPaths: string[]): Promise<void>;
}

View File

@ -30,6 +30,17 @@ export class MeetStorageService<
this.storageProvider = this.storageFactory.create();
}
async getObjectHeaders(filePath: string): Promise<{ contentLength?: number; contentType?: string }> {
try {
const headers = await this.storageProvider.getObjectHeaders(filePath);
this.logger.verbose(`Object headers retrieved: ${JSON.stringify(headers)}`);
return headers;
} catch (error) {
this.handleError(error, 'Error retrieving object headers');
throw internalError('Getting object headers');
}
}
/**
* Initializes default preferences if not already initialized.
* @returns {Promise<GPrefs>} Default global preferences.
@ -232,7 +243,6 @@ export class MeetStorageService<
return this.storageProvider.deleteRecordingBinaryFilesByPaths(recordingPaths);
}
/**
* Returns the default global preferences.
* @returns {GPrefs}