From c59052a03e3d6abd459f634a7eff0cdc04e9673c Mon Sep 17 00:00:00 2001 From: Richard R Date: Thu, 4 Jun 2026 13:20:47 -0600 Subject: [PATCH] fix(documents): allow all accepted files for upload and add docx conversion timeout Update DocumentUploader to upload all accepted files without filtering by type, enabling consistent handling of DOCX and other supported formats. Add a default timeout for DOCX-to-PDF conversion to prevent hanging LibreOffice processes. This improves reliability and ensures uploads do not silently stall. --- src/components/documents/DocumentUploader.tsx | 17 +++-------------- src/lib/server/documents/docx-convert.ts | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 15 deletions(-) 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}`)); });