Add detailed processing and validation for new files
Enhanced the "new" method to include detailed documentation and parameters for file processing and validation. Introduced allowed MIME types as a parameter and logging for clearer file management.
This commit is contained in:
parent
fd8ad47cf7
commit
e788f4945e
@ -177,11 +177,22 @@ export class StorageService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes and saves a new file after validating its properties and conditions.
|
||||
*
|
||||
* @param {string} fileDisplayName - The display name of the file.
|
||||
* @param {Buffer} file - The buffer representing the file content.
|
||||
* @param {Array<string>} allowedMIMEs - An array of allowed MIME types for validation.
|
||||
* @param {boolean} [isDocumentation] - Optional flag to mark whether the file is documentation.
|
||||
* @return {Promise<IFileInformation>} - Returns a promise resolving to the file information object upon successful operation.
|
||||
* @throws {BadRequestException} If an error occurs during the file processing or saving.
|
||||
*/
|
||||
public async new(
|
||||
fileDisplayName: string,
|
||||
file: Buffer,
|
||||
allowedMIMEs: Array<string>,
|
||||
isDocumentation?: boolean,
|
||||
) {
|
||||
): Promise<IFileInformation> {
|
||||
try {
|
||||
const info = await this.generateInformation(
|
||||
file,
|
||||
@ -192,9 +203,7 @@ export class StorageService {
|
||||
`Trying to append a new file : "${info.fileDisplayName}"...\n > Checksum SHA-256 : ${info.fileChecksum}\n > Size : ${info.fileSize / (1024 * 1024)}Mio\n > File format : ${info.fileType.mime}\n`,
|
||||
);
|
||||
const condition = await this.checkConditions(
|
||||
[
|
||||
/* TODO import autorized file format */
|
||||
],
|
||||
allowedMIMEs,
|
||||
file,
|
||||
);
|
||||
if (!condition) {
|
||||
@ -202,8 +211,17 @@ export class StorageService {
|
||||
`File "${info.fileDisplayName}" did not pass the files requirement.\n${info.fileChecksum}`,
|
||||
);
|
||||
}
|
||||
console.log(
|
||||
`File "${info.fileDisplayName}" passed the files requirement successfully.\n${info.fileChecksum}`
|
||||
);
|
||||
|
||||
//TODO Append in DB and save to storage
|
||||
// Save the file with "saveFile()"
|
||||
console.log(`Saving file "${info.fileName}"...`);
|
||||
console.log(`Nom d'affichage : ${info.fileDisplayName}`);
|
||||
await this.saveFile(info.fileName, file);
|
||||
|
||||
// All good we return data about the file to append it to the db.
|
||||
return info;
|
||||
} catch (err) {
|
||||
throw new BadRequestException(err);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user