mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
feat(api): add attachment extra attributes
This commit is contained in:
@@ -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)
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user