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.
This commit is contained in:
Richard R 2026-06-04 13:20:47 -06:00
parent 2ecd281f75
commit c59052a03e
2 changed files with 20 additions and 15 deletions

View file

@ -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,

View file

@ -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<void> {
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}`));
});