Skip to content

Commit 5798b87

Browse files
committed
refactor(files): hoist BINARY_DOC_TASKS to module scope in compiled-check route and VFS handler
1 parent 118484a commit 5798b87

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

apps/sim/app/api/workspaces/[id]/files/[fileId]/compiled-check/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const runtime = 'nodejs'
1414

1515
const logger = createLogger('WorkspaceFileCompiledCheckAPI')
1616

17-
const EXT_TO_TASK: Record<string, SandboxTaskId> = {
17+
const BINARY_DOC_TASKS: Record<string, SandboxTaskId> = {
1818
docx: 'docx-generate',
1919
pptx: 'pptx-generate',
2020
pdf: 'pdf-generate',
@@ -53,7 +53,7 @@ export const GET = withRouteHandler(
5353
}
5454

5555
const ext = fileRecord.name.split('.').pop()?.toLowerCase() ?? ''
56-
const taskId = EXT_TO_TASK[ext]
56+
const taskId = BINARY_DOC_TASKS[ext]
5757
if (!taskId) {
5858
return NextResponse.json(
5959
{ error: `Compiled check only supports .docx, .pptx, and .pdf files` },

apps/sim/lib/copilot/vfs/workspace-vfs.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ import { TRIGGER_REGISTRY } from '@/triggers/registry'
8787

8888
const logger = createLogger('WorkspaceVFS')
8989

90+
const BINARY_DOC_TASKS: Record<string, SandboxTaskId> = {
91+
docx: 'docx-generate',
92+
pptx: 'pptx-generate',
93+
pdf: 'pdf-generate',
94+
}
95+
9096
/** Static component files, computed once and shared across all VFS instances */
9197
let staticComponentFiles: Map<string, string> | null = null
9298

@@ -469,12 +475,7 @@ export class WorkspaceVFS {
469475
const record = await getWorkspaceFile(this._workspaceId, fileId)
470476
if (!record) return null
471477
const ext = record.name.split('.').pop()?.toLowerCase() ?? ''
472-
const EXT_TASK: Record<string, SandboxTaskId> = {
473-
docx: 'docx-generate',
474-
pptx: 'pptx-generate',
475-
pdf: 'pdf-generate',
476-
}
477-
const taskId = EXT_TASK[ext]
478+
const taskId = BINARY_DOC_TASKS[ext]
478479
if (!taskId) return null
479480
const buffer = await downloadWorkspaceFile(record)
480481
const code = buffer.toString('utf-8')

0 commit comments

Comments
 (0)