mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-09-18 01:19:24 +00:00
only expect a zip file
This commit is contained in:
parent
7bca8315d8
commit
9c31d5599c
@ -10,7 +10,7 @@ export const buildRemoveBlanksFormData = (parameters: RemoveBlanksParameters, fi
|
|||||||
formData.append('fileInput', file);
|
formData.append('fileInput', file);
|
||||||
formData.append('threshold', String(parameters.threshold));
|
formData.append('threshold', String(parameters.threshold));
|
||||||
formData.append('whitePercent', String(parameters.whitePercent));
|
formData.append('whitePercent', String(parameters.whitePercent));
|
||||||
formData.append('includeBlankPages', String(parameters.includeBlankPages));
|
// Note: includeBlankPages is not sent to backend as it always returns both files in a ZIP
|
||||||
return formData;
|
return formData;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -28,23 +28,11 @@ export const useRemoveBlanksOperation = () => {
|
|||||||
const { extractZipFiles } = useToolResources();
|
const { extractZipFiles } = useToolResources();
|
||||||
|
|
||||||
const responseHandler = useCallback(async (blob: Blob, originalFiles: File[]): Promise<File[]> => {
|
const responseHandler = useCallback(async (blob: Blob, originalFiles: File[]): Promise<File[]> => {
|
||||||
// Try to detect zip vs pdf
|
// Backend always returns a ZIP file containing the processed PDFs
|
||||||
const headBuf = await blob.slice(0, 4).arrayBuffer();
|
const files = await extractZipFiles(blob);
|
||||||
const head = new TextDecoder().decode(new Uint8Array(headBuf));
|
if (files.length > 0) return files;
|
||||||
|
|
||||||
// ZIP: extract PDFs inside (nonBlankPages, blankPages, etc.)
|
// Fallback error handling
|
||||||
if (head.startsWith('PK')) {
|
|
||||||
const files = await extractZipFiles(blob);
|
|
||||||
if (files.length > 0) return files;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PDF fallback: return as single file
|
|
||||||
if (head.startsWith('%PDF')) {
|
|
||||||
const base = originalFiles[0]?.name?.replace(/\.[^.]+$/, '') || 'document';
|
|
||||||
return [new File([blob], `noblank_${base}.pdf`, { type: 'application/pdf' })];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unknown blob type
|
|
||||||
const textBuf = await blob.slice(0, 1024).arrayBuffer();
|
const textBuf = await blob.slice(0, 1024).arrayBuffer();
|
||||||
const text = new TextDecoder().decode(new Uint8Array(textBuf));
|
const text = new TextDecoder().decode(new Uint8Array(textBuf));
|
||||||
if (/error|exception|html/i.test(text)) {
|
if (/error|exception|html/i.test(text)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user