FEAT: add svg

This commit is contained in:
marcos-silva-rodrigues
2025-01-30 16:06:13 -03:00
parent db78494b1a
commit 867aec092b
2 changed files with 11 additions and 4 deletions
+2 -2
View File
@@ -95,10 +95,10 @@ export class ThemeController {
}
private validMimeType(file: Express.Multer.File) {
const mimeTypesValid = ['image/jpeg', 'image/jpg', 'image/png'];
const mimeTypesValid = ['image/jpeg', 'image/jpg', 'image/png', 'image/svg+xml'];
if (file && !mimeTypesValid.includes(file.mimetype)) {
throw new HttpException(`O Arquivo ${file.fieldname} deve ser jpeg, jpg ou png`, HttpStatus.BAD_REQUEST);
throw new HttpException(`O Arquivo ${file.fieldname} deve ser jpeg, jpg, png ou svg`, HttpStatus.BAD_REQUEST);
}
}
+9 -2
View File
@@ -96,11 +96,18 @@ export class ThemeService implements OnModuleInit {
private async sendFile(file: Express.Multer.File, stream$: ReplaySubject<ThemeRequest>) {
const chunkSize = 4 * 1024 * 1024;
const bufferStream = new CustomBufferStream(file.buffer, chunkSize);
const parseMimitypeForExtension = {
'image/jpeg': '.jpeg',
'image/jpg': '.jpg',
'image/png': '.png',
'image/svg+xml': '.svg',
}
const extension = parseMimitypeForExtension[file.mimetype];
return new Promise((resolve, reject) => {
bufferStream.on('data', (chunk) => {
const mimetype = file.mimetype.split('/')[1]; // example image/jpeg
const filename = file.fieldname.concat(".", mimetype);
const filename = file.fieldname.concat(extension);
stream$.next({
customerId: '',
displayName: '',