Add method to read file from storage
Introduced a new `read` method in `storage.service.ts` to fetch files from storage based on checksum, extension, and type. This method handles potential exceptions by throwing a `NotFoundException` if the file is not found.
This commit is contained in:
parent
e788f4945e
commit
ddf9ef4860
@ -177,6 +177,32 @@ export class StorageService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a file from storage based on the provided checksum, extension, and type.
|
||||
*
|
||||
* @param {string} checksum - The checksum of the file for validation purposes.
|
||||
* @param {string} extension - The file extension to define the type of file.
|
||||
* @param {boolean} isDocumentation - A flag to determine if the file is documentation or a regular file.
|
||||
* @return {Promise<Buffer>} - A promise that resolves to the file data buffer.
|
||||
* @throws {NotFoundException} - Throws a NotFoundException if the file is not found in storage.
|
||||
*/
|
||||
public async read(
|
||||
checksum: string,
|
||||
extension: string,
|
||||
isDocumentation: boolean
|
||||
) {
|
||||
try {
|
||||
const fileName = `${isDocumentation ? "doc" : "file"}-${checksum}.${extension.toLowerCase()}`;
|
||||
console.log(`Fetching file "${fileName}" from storage...`);
|
||||
const file = await this.getFile(fileName)
|
||||
console.log(`Got a ${file.byteLength / (1024 * 1024)}MiB file from the storage.`)
|
||||
return file;
|
||||
} catch (err) {
|
||||
console.log("File not found.")
|
||||
throw new NotFoundException(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes and saves a new file after validating its properties and conditions.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user