Add attachments (#733)

* Add attachments v1

* Refacto

* Add Policy checks

* Fix tests

* Remove generated files from git

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Félix Malfait
2023-07-19 00:24:03 +02:00
committed by GitHub
parent 84018efc7d
commit 10f7b08fdc
1130 changed files with 570 additions and 39762 deletions

View File

@ -3,6 +3,7 @@ import { registerEnumType } from '@nestjs/graphql';
export enum FileFolder {
ProfilePicture = 'profile-picture',
WorkspaceLogo = 'workspace-logo',
Attachment = 'attachment',
}
registerEnumType(FileFolder, {

View File

@ -46,12 +46,14 @@ export class FileUploadService {
await this._uploadFile({
file,
filename,
filename: name,
mimeType,
fileFolder,
});
return {
id,
mimeType,
path: `${fileFolder}/${name}`,
};
}
@ -71,11 +73,12 @@ export class FileUploadService {
const id = uuidV4();
const name = `${id}${ext ? `.${ext}` : ''}`;
// Get all cropSizes for this fileFolder
const cropSizes = settings.storage.imageCropSizes[fileFolder];
// Extract the values from ShortCropSize
if (!cropSizes) {
throw new Error(`No crop sizes found for ${fileFolder}`);
}
const sizes = cropSizes.map((shortSize) => getCropSize(shortSize));
// Crop images based on sizes
const images = await Promise.all(
sizes.map((size) =>
sharp(file).resize({
@ -86,7 +89,6 @@ export class FileUploadService {
const paths: Array<string> = [];
// Upload all images to corresponding folders
await Promise.all(
images.map(async (image, index) => {
const buffer = await image.toBuffer();
@ -103,6 +105,8 @@ export class FileUploadService {
);
return {
id,
mimeType,
paths,
};
}