mirror of
https://github.com/twentyhq/twenty.git
synced 2024-09-11 15:35:36 +03:00
Use isSvg package
This commit is contained in:
parent
ad3e206ea6
commit
05014b5107
@ -4,6 +4,7 @@ import sharp from 'sharp';
|
|||||||
import { v4 as uuidV4 } from 'uuid';
|
import { v4 as uuidV4 } from 'uuid';
|
||||||
import { JSDOM } from 'jsdom';
|
import { JSDOM } from 'jsdom';
|
||||||
import DOMPurify from 'dompurify';
|
import DOMPurify from 'dompurify';
|
||||||
|
import isSvg from 'is-svg';
|
||||||
|
|
||||||
import { FileFolder } from 'src/engine/core-modules/file/interfaces/file-folder.interface';
|
import { FileFolder } from 'src/engine/core-modules/file/interfaces/file-folder.interface';
|
||||||
|
|
||||||
@ -34,22 +35,12 @@ export class FileUploadService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _sanitizeFile({
|
private _sanitizeFile(
|
||||||
file,
|
file: Buffer | Uint8Array | string,
|
||||||
ext,
|
): Buffer | Uint8Array | string {
|
||||||
mimeType,
|
|
||||||
}: {
|
|
||||||
file: Buffer | Uint8Array | string;
|
|
||||||
ext: string;
|
|
||||||
mimeType: string | undefined;
|
|
||||||
}): Buffer | Uint8Array | string {
|
|
||||||
const fileString = file.toString();
|
const fileString = file.toString();
|
||||||
|
|
||||||
if (
|
if (isSvg(fileString)) {
|
||||||
fileString.includes('svg') &&
|
|
||||||
ext === 'svg' &&
|
|
||||||
mimeType === 'image/svg+xml'
|
|
||||||
) {
|
|
||||||
const window = new JSDOM('').window;
|
const window = new JSDOM('').window;
|
||||||
const purify = DOMPurify(window);
|
const purify = DOMPurify(window);
|
||||||
|
|
||||||
@ -75,7 +66,7 @@ export class FileUploadService {
|
|||||||
const name = `${id}${ext ? `.${ext}` : ''}`;
|
const name = `${id}${ext ? `.${ext}` : ''}`;
|
||||||
|
|
||||||
await this._uploadFile({
|
await this._uploadFile({
|
||||||
file: this._sanitizeFile({ file, ext, mimeType }),
|
file: this._sanitizeFile(file),
|
||||||
filename: name,
|
filename: name,
|
||||||
mimeType,
|
mimeType,
|
||||||
fileFolder,
|
fileFolder,
|
||||||
|
Loading…
Reference in New Issue
Block a user