diff --git a/src/components/documents/DocumentUploader.tsx b/src/components/documents/DocumentUploader.tsx index 49465d5..ffa1b27 100644 --- a/src/components/documents/DocumentUploader.tsx +++ b/src/components/documents/DocumentUploader.tsx @@ -58,19 +58,8 @@ export function DocumentUploader({ }); try { - const uploadableFiles = acceptedFiles.filter((file) => - file.type === 'application/pdf' - || file.type === 'application/epub+zip' - || file.type === 'text/plain' - || file.type === 'text/markdown' - || file.name.endsWith('.md') - || (enableDocx && file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'), - ); - - if (uploadableFiles.length > 0) { - await uploadDocuments(uploadableFiles); - completedFiles = uploadableFiles.length; - } + await uploadDocuments(acceptedFiles); + completedFiles = acceptedFiles.length; } catch (err) { setError('Failed to upload file. Please try again.'); console.error('Upload error:', err); @@ -84,7 +73,7 @@ export function DocumentUploader({ currentFileName: null, }); } - }, [uploadDocuments, enableDocx, emitBatchState]); + }, [uploadDocuments, emitBatchState]); const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop, diff --git a/src/lib/server/documents/docx-convert.ts b/src/lib/server/documents/docx-convert.ts index 67cf5cd..1c940a1 100644 --- a/src/lib/server/documents/docx-convert.ts +++ b/src/lib/server/documents/docx-convert.ts @@ -7,6 +7,7 @@ import { pathToFileURL } from 'url'; const DOCSTORE_DIR = path.join(process.cwd(), 'docstore'); const TEMP_DIR = path.join(DOCSTORE_DIR, 'tmp'); +const DEFAULT_DOCX_CONVERSION_TIMEOUT_MS = 60_000; async function ensureTempDir(): Promise { if (!existsSync(DOCSTORE_DIR)) { @@ -25,9 +26,24 @@ async function convertDocxToPdf(inputPath: string, outputDir: string, profileDir } args.push('--headless', '--nologo', '--convert-to', 'pdf', '--outdir', outputDir, inputPath); const proc = spawn('soffice', args); + let settled = false; + const timeout = setTimeout(() => { + if (settled) return; + settled = true; + proc.kill(); + reject(new Error(`LibreOffice conversion timed out after ${DEFAULT_DOCX_CONVERSION_TIMEOUT_MS}ms`)); + }, DEFAULT_DOCX_CONVERSION_TIMEOUT_MS); - proc.on('error', (error) => reject(error)); + proc.on('error', (error) => { + clearTimeout(timeout); + if (settled) return; + settled = true; + reject(error); + }); proc.on('close', (code) => { + clearTimeout(timeout); + if (settled) return; + settled = true; if (code === 0) resolve(); else reject(new Error(`LibreOffice conversion failed with code ${code}`)); });