feat(api): add attachment extra attributes

This commit is contained in:
Mohamed Marrouchi
2025-01-08 16:42:46 +01:00
parent 47e8056a15
commit 994c8857e9
16 changed files with 872 additions and 109 deletions

View File

@@ -15,6 +15,8 @@ import { v4 as uuidv4 } from 'uuid';
import { config } from '@/config';
import { AttachmentContext, TAttachmentContext } from '../types';
export const MIME_REGEX = /^[a-z-]+\/[0-9a-z\-.]+$/gm;
/**
@@ -78,3 +80,29 @@ export const generateUniqueFilename = (originalname: string) => {
const name = originalname.slice(0, -extension.length);
return `${name}-${uuidv4()}${extension}`;
};
/**
* Checks if the given context is of type TAttachmentContext.
*
* @param ctx - The context to check.
* @returns True if the context is of type TAttachmentContext, otherwise false.
*/
export const isAttachmentContext = (ctx: any): ctx is TAttachmentContext => {
return Object.values(AttachmentContext).includes(ctx);
};
/**
* Checks if the given list is an array of TAttachmentContext.
*
* @param ctxList - The list of contexts to check.
* @returns True if all items in the list are of type TAttachmentContext, otherwise false.
*/
export const isAttachmentContextArray = (
ctxList: any,
): ctxList is TAttachmentContext[] => {
return (
Array.isArray(ctxList) &&
ctxList.length > 0 &&
ctxList.every(isAttachmentContext)
);
};