( args: CompileArgs )
| 387 | * at most once per distinct source. |
| 388 | */ |
| 389 | export async function compileDoc( |
| 390 | args: CompileArgs |
| 391 | ): Promise<{ buffer: Buffer; contentType: string }> { |
| 392 | const { source, fileName, workspaceId } = args |
| 393 | const fmt = await getE2BDocFormat(fileName) |
| 394 | if (!fmt) throw new Error(`Unsupported document format: ${fileName}`) |
| 395 | |
| 396 | const existing = await loadCompiledDoc(workspaceId, source, fmt.ext) |
| 397 | if (existing) return { buffer: existing, contentType: fmt.contentType } |
| 398 | |
| 399 | const buffer = |
| 400 | fmt.engine === 'node' |
| 401 | ? await compileDocViaE2BNode({ source, fileName, workspaceId }, fmt.ext as 'pptx' | 'docx') |
| 402 | : await compileDocViaE2BPython({ source, fileName, workspaceId }, fmt) |
| 403 | await storeCompiledDoc(workspaceId, source, fmt.ext, fmt.contentType, buffer) |
| 404 | return { buffer, contentType: fmt.contentType } |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Loads a compiled doc artifact by extension when present, without compiling. |
no test coverage detected