Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

chore: file type map type clean up (#242)

gbirman439e66538850
diff --git a/js/app/packages/block-email/component/AttachmentPill.tsx b/js/app/packages/block-email/component/AttachmentPill.tsx
index cce216453c..0fdb6bf252 100644
--- a/js/app/packages/block-email/component/AttachmentPill.tsx
+++ b/js/app/packages/block-email/component/AttachmentPill.tsx
@@ -11,6 +11,10 @@ import { platformFetch } from 'core/util/platformFetch';
import { Show } from 'solid-js';
import { useSplitLayout } from '../../app/component/split-layout/layout';
+const mimeToFileExtTypeMap = new Map<string, string>(
+ Object.values(FileTypeMap).map((value) => [value.mime, value.extension])
+);
+
export function EmailAttachmentPill(props: {
attachment: Attachment;
removable?: boolean;
@@ -20,9 +24,6 @@ export function EmailAttachmentPill(props: {
const { replaceOrInsertSplit } = useSplitLayout();
- const mimeToFileExtTypeMap = new Map<string, string>(
- Object.values(FileTypeMap).map((value) => [value.mime, value.extension])
- );
const fileType = props.attachment.mime_type
? (mimeToFileExtTypeMap.get(props.attachment.mime_type) as FileType)
: undefined;
diff --git a/js/app/packages/core/component/AI/util/attachment.ts b/js/app/packages/core/component/AI/util/attachment.ts
index 3236a62657..762da4e5eb 100644
--- a/js/app/packages/core/component/AI/util/attachment.ts
+++ b/js/app/packages/core/component/AI/util/attachment.ts
@@ -2,11 +2,14 @@ import { SUPPORTED_IMAGE_ATTACHMENT_EXTENSIONS } from '@core/component/AI/consta
import { FileType as FileTypeMap } from '@service-cognition/generated/schemas/fileType';
import type { AttachmentMetadata, AttachmentPreview, FileType } from '../types';
+const FILE_TYPE_SET = new Set(Object.keys(FileTypeMap));
+
// maps file type string to FileType enum if it exists
export const asFileType = (
fileType: string | null | undefined
): FileType | undefined => {
- return Object.entries(FileTypeMap).find(([key, _]) => key === fileType)?.[1];
+ if (!fileType || !FILE_TYPE_SET.has(fileType)) return undefined;
+ return fileType as FileType;
};
export const isImageAttachment = (attachment: AttachmentPreview) => {