diff --git a/FILE_HISTORY_SPECIFICATION.md b/FILE_HISTORY_SPECIFICATION.md new file mode 100644 index 000000000..0297628fb --- /dev/null +++ b/FILE_HISTORY_SPECIFICATION.md @@ -0,0 +1,231 @@ +# Stirling PDF File History Specification + +## Overview + +Stirling PDF implements a comprehensive file history tracking system that embeds metadata directly into PDF documents using the PDF keywords field. This system tracks tool operations, version progression, and file lineage through the processing pipeline. + +## PDF Metadata Format + +### Storage Mechanism +File history is stored in the PDF **Keywords** field as a JSON string with the prefix `stirling-history:`. + +### Metadata Structure + +```typescript +interface PDFHistoryMetadata { + stirlingHistory: { + originalFileId: string; // UUID of the root file in the version chain + parentFileId?: string; // UUID of the immediate parent file + versionNumber: number; // Version number (1, 2, 3, etc.) + toolChain: ToolOperation[]; // Array of applied tool operations + createdBy: 'Stirling-PDF'; // System identifier + formatVersion: '1.0'; // Metadata format version + createdAt: number; // Timestamp when version was created + lastModified: number; // Timestamp when last modified + }; +} + +interface ToolOperation { + toolName: string; // Tool identifier (e.g., 'compress', 'sanitize') + timestamp: number; // When the tool was applied + parameters?: Record; // Tool-specific parameters (optional) +} +``` + +### Example PDF Keywords Field +``` +Keywords: ["user-keyword", "stirling-history:{\"stirlingHistory\":{\"originalFileId\":\"abc123\",\"versionNumber\":2,\"toolChain\":[{\"toolName\":\"compress\",\"timestamp\":1756825614618},{\"toolName\":\"sanitize\",\"timestamp\":1756825631545}],\"createdBy\":\"Stirling-PDF\",\"formatVersion\":\"1.0\"}}"] +``` + +## Version Numbering System + +### Version Progression +- **v0**: Original uploaded file (no Stirling PDF processing) +- **v1**: First tool applied to original file +- **v2**: Second tool applied (inherits from v1) +- **v3**: Third tool applied (inherits from v2) +- **etc.** + +### Version Relationships +``` +document.pdf (v0) + ↓ compress +document.pdf (v1: compress) + ↓ sanitize +document.pdf (v2: compress → sanitize) + ↓ ocr +document.pdf (v3: compress → sanitize → ocr) +``` + +## File Lineage Tracking + +### Original File ID +The `originalFileId` remains constant throughout the entire version chain, enabling grouping of all versions of the same logical document. + +### Parent-Child Relationships +Each processed file references its immediate parent via `parentFileId`, creating a complete audit trail. + +### Tool Chain +The `toolChain` array maintains the complete sequence of tool operations applied to reach the current version. + +## Implementation Architecture + +### Frontend Components + +#### 1. PDF Metadata Service (`pdfMetadataService.ts`) +- **PDF-lib Integration**: Uses pdf-lib for metadata injection/extraction +- **Caching**: ContentCache with 10-minute TTL for performance +- **Encryption Support**: Handles encrypted PDFs with `ignoreEncryption: true` + +**Key Methods:** +```typescript +// Inject metadata into PDF +injectHistoryMetadata(pdfBytes: ArrayBuffer, originalFileId: string, parentFileId?: string, toolChain: ToolOperation[], versionNumber: number): Promise + +// Extract metadata from PDF +extractHistoryMetadata(pdfBytes: ArrayBuffer): Promise + +// Create new version with incremented number +createNewVersion(pdfBytes: ArrayBuffer, parentFileId: string, toolOperation: ToolOperation): Promise +``` + +#### 2. File History Utilities (`fileHistoryUtils.ts`) +- **FileContext Integration**: Links PDF metadata with React state management +- **Version Management**: Handles version grouping and latest version filtering +- **Tool Integration**: Prepares files for tool processing with history injection + +**Key Functions:** +```typescript +// Extract history from File and update FileRecord +extractFileHistory(file: File, record: FileRecord): Promise + +// Inject history before tool processing +injectHistoryForTool(file: File, sourceFileRecord: FileRecord, toolName: string, parameters?): Promise + +// Group files by original ID for version management +groupFilesByOriginal(fileRecords: FileRecord[]): Map + +// Get only latest version of each file group +getLatestVersions(fileRecords: FileRecord[]): FileRecord[] +``` + +#### 3. Tool Operation Integration (`useToolOperation.ts`) +- **Automatic Injection**: All tool operations automatically inject history metadata +- **Version Progression**: Reads current version from PDF and increments appropriately +- **Universal Support**: Works with single-file, multi-file, and custom tool patterns + +### Data Flow + +``` +1. User uploads PDF → No history (v0) +2. Tool processing begins → prepareFilesWithHistory() injects current state +3. Backend processes PDF → Returns processed file with embedded history +4. FileContext adds result → extractFileHistory() reads embedded metadata +5. UI displays file → Shows version badges and tool chain +``` + +## UI Integration + +### File Manager +- **Version Toggle**: Switch between "Latest Only" and "All Versions" views +- **Version Badges**: v0, v1, v2 indicators on file items +- **History Dropdown**: Version timeline with restore functionality +- **Tool Chain Display**: Complete processing history in file details panel + +### Active Files Workbench +- **Version Metadata**: Version number in file metadata line (e.g., "PDF file - 3 Pages - v2") +- **Tool Chain Overlay**: Bottom overlay showing tool sequence (e.g., "compress → sanitize") +- **Real-time Updates**: Immediate display after tool processing + +## Storage and Persistence + +### PDF Metadata +- **Embedded in PDF**: History travels with the document across downloads/uploads +- **Keywords Field**: Uses standard PDF metadata field for maximum compatibility +- **Multiple Keywords**: System handles multiple history entries and extracts latest version + +### IndexedDB Storage +- **Client-side Persistence**: FileMetadata includes extracted history information +- **Lazy Loading**: History extracted when files are accessed from storage +- **Batch Processing**: Large collections processed in batches of 5 to prevent memory issues + +### Memory Management +- **ContentCache**: 10-minute TTL, 50-file capacity for metadata extraction results +- **Cleanup**: Automatic cache eviction and expired entry removal +- **Large File Support**: No artificial size limits (supports 100GB+ PDFs) + +## Tool Configuration + +### Filename Preservation +Most tools preserve the original filename to maintain file identity: + +**No Prefix (Filename Preserved):** +- compress, repair, sanitize, addPassword, removePassword, changePermissions, removeCertificateSign, unlockPdfForms, ocr, addWatermark + +**With Prefix (Different Content):** +- split (`split_` - creates multiple files) +- convert (`converted_` - changes file format) + +### Configuration Pattern +```typescript +export const toolOperationConfig = { + toolType: ToolType.singleFile, + operationType: 'toolName', + endpoint: '/api/v1/category/tool-endpoint', + filePrefix: '', // Empty for filename preservation + buildFormData: buildToolFormData, + defaultParameters +}; +``` + +## Error Handling and Resilience + +### Graceful Degradation +- **Extraction Failures**: Files display normally without history if metadata extraction fails +- **Encrypted PDFs**: System handles encrypted documents with `ignoreEncryption` option +- **Corrupted Metadata**: Invalid history metadata is silently ignored with fallback to basic file info + +### Performance Considerations +- **Caching**: Metadata extraction results are cached to avoid re-parsing +- **Batch Processing**: Large file collections processed in controlled batches +- **Async Extraction**: History extraction doesn't block file operations + +## Developer Guidelines + +### Adding History to New Tools +1. **Set `filePrefix: ''`** in tool configuration to preserve filenames +2. **Use existing patterns**: Tool operations automatically inherit history injection +3. **Custom processors**: Must handle history injection manually if using custom response handlers + +### Testing File History +1. **Upload a PDF**: Should show no version (v0) +2. **Apply any tool**: Should show v1 with tool name in history +3. **Apply another tool**: Should show v2 with tool chain sequence +4. **Check file manager**: Version toggle and history dropdown should work +5. **Check workbench**: Tool chain overlay should appear on thumbnails + +### Debugging +Enable development mode logging to see: +- History injection: `📄 Injected PDF history metadata` +- History extraction: `📄 History extraction completed` +- Version progression: Version number increments and tool chain updates + +## Future Enhancements + +### Possible Extensions +- **Branching**: Support for parallel processing branches from same source +- **Diff Tracking**: Track specific changes made by each tool +- **User Attribution**: Add user information to tool operations +- **Timestamp Precision**: Enhanced timestamp tracking for audit trails +- **Export Options**: Export complete processing history as JSON/XML + +### Compatibility +- **PDF Standard Compliance**: Uses standard PDF Keywords field for broad compatibility +- **Backwards Compatibility**: PDFs without history metadata work normally +- **Future Versions**: Format version field enables future metadata schema evolution + +--- + +**Last Updated**: January 2025 +**Format Version**: 1.0 +**Implementation**: Stirling PDF Frontend v2 \ No newline at end of file diff --git a/frontend/src/hooks/tools/addPassword/useAddPasswordOperation.ts b/frontend/src/hooks/tools/addPassword/useAddPasswordOperation.ts index c9a2bdaad..f271a5a5a 100644 --- a/frontend/src/hooks/tools/addPassword/useAddPasswordOperation.ts +++ b/frontend/src/hooks/tools/addPassword/useAddPasswordOperation.ts @@ -30,7 +30,6 @@ export const addPasswordOperationConfig = { buildFormData: buildAddPasswordFormData, operationType: 'addPassword', endpoint: '/api/v1/security/add-password', - filePrefix: 'encrypted_', // Will be overridden in hook with translation defaultParameters: fullDefaultParameters, } as const; @@ -39,7 +38,6 @@ export const useAddPasswordOperation = () => { return useToolOperation({ ...addPasswordOperationConfig, - filePrefix: t('addPassword.filenamePrefix', 'encrypted') + '_', getErrorMessage: createStandardErrorHandler(t('addPassword.error.failed', 'An error occurred while encrypting the PDF.')) }); }; diff --git a/frontend/src/hooks/tools/addWatermark/useAddWatermarkOperation.ts b/frontend/src/hooks/tools/addWatermark/useAddWatermarkOperation.ts index 9da189ea3..d718a1762 100644 --- a/frontend/src/hooks/tools/addWatermark/useAddWatermarkOperation.ts +++ b/frontend/src/hooks/tools/addWatermark/useAddWatermarkOperation.ts @@ -39,7 +39,6 @@ export const addWatermarkOperationConfig = { buildFormData: buildAddWatermarkFormData, operationType: 'watermark', endpoint: '/api/v1/security/add-watermark', - filePrefix: 'watermarked_', // Will be overridden in hook with translation defaultParameters, } as const; @@ -48,7 +47,6 @@ export const useAddWatermarkOperation = () => { return useToolOperation({ ...addWatermarkOperationConfig, - filePrefix: t('watermark.filenamePrefix', 'watermarked') + '_', getErrorMessage: createStandardErrorHandler(t('watermark.error.failed', 'An error occurred while adding watermark to the PDF.')) }); }; diff --git a/frontend/src/hooks/tools/automate/useAutomateOperation.ts b/frontend/src/hooks/tools/automate/useAutomateOperation.ts index 112bafbd2..e051d5f1b 100644 --- a/frontend/src/hooks/tools/automate/useAutomateOperation.ts +++ b/frontend/src/hooks/tools/automate/useAutomateOperation.ts @@ -3,7 +3,6 @@ import { useCallback } from 'react'; import { executeAutomationSequence } from '../../../utils/automationExecutor'; import { useFlatToolRegistry } from '../../../data/useTranslatedToolRegistry'; import { AutomateParameters } from '../../../types/automation'; -import { AUTOMATION_CONSTANTS } from '../../../constants/automation'; export function useAutomateOperation() { const toolRegistry = useFlatToolRegistry(); @@ -43,6 +42,5 @@ export function useAutomateOperation() { toolType: ToolType.custom, operationType: 'automate', customProcessor, - filePrefix: '' // No prefix needed since automation handles naming internally }); } diff --git a/frontend/src/hooks/tools/changePermissions/useChangePermissionsOperation.ts b/frontend/src/hooks/tools/changePermissions/useChangePermissionsOperation.ts index 89f7e1345..30feb3d25 100644 --- a/frontend/src/hooks/tools/changePermissions/useChangePermissionsOperation.ts +++ b/frontend/src/hooks/tools/changePermissions/useChangePermissionsOperation.ts @@ -28,7 +28,6 @@ export const changePermissionsOperationConfig = { buildFormData: buildChangePermissionsFormData, operationType: 'change-permissions', endpoint: '/api/v1/security/add-password', // Change Permissions is a fake endpoint for the Add Password tool - filePrefix: 'permissions_', defaultParameters, } as const; diff --git a/frontend/src/hooks/tools/compress/useCompressOperation.ts b/frontend/src/hooks/tools/compress/useCompressOperation.ts index 8327dd698..1a6a69c8f 100644 --- a/frontend/src/hooks/tools/compress/useCompressOperation.ts +++ b/frontend/src/hooks/tools/compress/useCompressOperation.ts @@ -28,7 +28,6 @@ export const compressOperationConfig = { buildFormData: buildCompressFormData, operationType: 'compress', endpoint: '/api/v1/misc/compress-pdf', - filePrefix: 'compressed_', defaultParameters, } as const; diff --git a/frontend/src/hooks/tools/convert/useConvertOperation.ts b/frontend/src/hooks/tools/convert/useConvertOperation.ts index 6de20282f..315a33aee 100644 --- a/frontend/src/hooks/tools/convert/useConvertOperation.ts +++ b/frontend/src/hooks/tools/convert/useConvertOperation.ts @@ -84,7 +84,7 @@ export const createFileFromResponse = ( targetExtension = 'pdf'; } - const fallbackFilename = `${originalName}_converted.${targetExtension}`; + const fallbackFilename = `${originalName}.${targetExtension}`; return createFileFromApiResponse(responseData, headers, fallbackFilename); }; @@ -137,7 +137,6 @@ export const convertOperationConfig = { toolType: ToolType.custom, customProcessor: convertProcessor, // Can't use callback version here operationType: 'convert', - filePrefix: 'converted_', defaultParameters, } as const; diff --git a/frontend/src/hooks/tools/ocr/useOCROperation.ts b/frontend/src/hooks/tools/ocr/useOCROperation.ts index 4d25a172f..b2d3a434a 100644 --- a/frontend/src/hooks/tools/ocr/useOCROperation.ts +++ b/frontend/src/hooks/tools/ocr/useOCROperation.ts @@ -88,8 +88,8 @@ export const ocrResponseHandler = async (blob: Blob, originalFiles: File[], extr throw new Error(`Response is not a valid PDF. Header: "${head}"`); } - const base = stripExt(originalFiles[0].name); - return [new File([blob], `ocr_${base}.pdf`, { type: 'application/pdf' })]; + const originalName = originalFiles[0].name; + return [new File([blob], originalName, { type: 'application/pdf' })]; }; // Static configuration object (without t function dependencies) @@ -98,7 +98,6 @@ export const ocrOperationConfig = { buildFormData: buildOCRFormData, operationType: 'ocr', endpoint: '/api/v1/misc/ocr-pdf', - filePrefix: 'ocr_', defaultParameters, } as const; diff --git a/frontend/src/hooks/tools/removeCertificateSign/useRemoveCertificateSignOperation.ts b/frontend/src/hooks/tools/removeCertificateSign/useRemoveCertificateSignOperation.ts index 106150281..1535716f0 100644 --- a/frontend/src/hooks/tools/removeCertificateSign/useRemoveCertificateSignOperation.ts +++ b/frontend/src/hooks/tools/removeCertificateSign/useRemoveCertificateSignOperation.ts @@ -16,7 +16,6 @@ export const removeCertificateSignOperationConfig = { buildFormData: buildRemoveCertificateSignFormData, operationType: 'remove-certificate-sign', endpoint: '/api/v1/security/remove-cert-sign', - filePrefix: 'unsigned_', // Will be overridden in hook with translation defaultParameters, } as const; @@ -25,7 +24,6 @@ export const useRemoveCertificateSignOperation = () => { return useToolOperation({ ...removeCertificateSignOperationConfig, - filePrefix: t('removeCertSign.filenamePrefix', 'unsigned') + '_', getErrorMessage: createStandardErrorHandler(t('removeCertSign.error.failed', 'An error occurred while removing certificate signatures.')) }); }; diff --git a/frontend/src/hooks/tools/removePassword/useRemovePasswordOperation.ts b/frontend/src/hooks/tools/removePassword/useRemovePasswordOperation.ts index ff644db42..e2a76638b 100644 --- a/frontend/src/hooks/tools/removePassword/useRemovePasswordOperation.ts +++ b/frontend/src/hooks/tools/removePassword/useRemovePasswordOperation.ts @@ -17,7 +17,6 @@ export const removePasswordOperationConfig = { buildFormData: buildRemovePasswordFormData, operationType: 'removePassword', endpoint: '/api/v1/security/remove-password', - filePrefix: 'decrypted_', // Will be overridden in hook with translation defaultParameters, } as const; @@ -26,7 +25,6 @@ export const useRemovePasswordOperation = () => { return useToolOperation({ ...removePasswordOperationConfig, - filePrefix: t('removePassword.filenamePrefix', 'decrypted') + '_', getErrorMessage: createStandardErrorHandler(t('removePassword.error.failed', 'An error occurred while removing the password from the PDF.')) }); }; diff --git a/frontend/src/hooks/tools/repair/useRepairOperation.ts b/frontend/src/hooks/tools/repair/useRepairOperation.ts index 44fcc9b70..dc40b03cd 100644 --- a/frontend/src/hooks/tools/repair/useRepairOperation.ts +++ b/frontend/src/hooks/tools/repair/useRepairOperation.ts @@ -16,7 +16,6 @@ export const repairOperationConfig = { buildFormData: buildRepairFormData, operationType: 'repair', endpoint: '/api/v1/misc/repair', - filePrefix: 'repaired_', // Will be overridden in hook with translation defaultParameters, } as const; @@ -25,7 +24,6 @@ export const useRepairOperation = () => { return useToolOperation({ ...repairOperationConfig, - filePrefix: t('repair.filenamePrefix', 'repaired') + '_', getErrorMessage: createStandardErrorHandler(t('repair.error.failed', 'An error occurred while repairing the PDF.')) }); }; diff --git a/frontend/src/hooks/tools/sanitize/useSanitizeOperation.ts b/frontend/src/hooks/tools/sanitize/useSanitizeOperation.ts index 4215011cb..97e539fcb 100644 --- a/frontend/src/hooks/tools/sanitize/useSanitizeOperation.ts +++ b/frontend/src/hooks/tools/sanitize/useSanitizeOperation.ts @@ -25,7 +25,6 @@ export const sanitizeOperationConfig = { buildFormData: buildSanitizeFormData, operationType: 'sanitize', endpoint: '/api/v1/security/sanitize-pdf', - filePrefix: 'sanitized_', // Will be overridden in hook with translation multiFileEndpoint: false, defaultParameters, } as const; @@ -35,7 +34,6 @@ export const useSanitizeOperation = () => { return useToolOperation({ ...sanitizeOperationConfig, - filePrefix: t('sanitize.filenamePrefix', 'sanitized') + '_', getErrorMessage: createStandardErrorHandler(t('sanitize.error.failed', 'An error occurred while sanitising the PDF.')) }); }; diff --git a/frontend/src/hooks/tools/shared/useToolApiCalls.ts b/frontend/src/hooks/tools/shared/useToolApiCalls.ts index ec0f398aa..8603c744c 100644 --- a/frontend/src/hooks/tools/shared/useToolApiCalls.ts +++ b/frontend/src/hooks/tools/shared/useToolApiCalls.ts @@ -6,7 +6,7 @@ import type { ProcessingProgress } from './useToolState'; export interface ApiCallsConfig { endpoint: string | ((params: TParams) => string); buildFormData: (params: TParams, file: File) => FormData; - filePrefix: string; + filePrefix?: string; responseHandler?: ResponseHandler; } diff --git a/frontend/src/hooks/tools/shared/useToolOperation.ts b/frontend/src/hooks/tools/shared/useToolOperation.ts index 49f2fbb02..fe6b9465c 100644 --- a/frontend/src/hooks/tools/shared/useToolOperation.ts +++ b/frontend/src/hooks/tools/shared/useToolOperation.ts @@ -34,7 +34,7 @@ interface BaseToolOperationConfig { operationType: string; /** Prefix added to processed filenames (e.g., 'compressed_', 'split_') */ - filePrefix: string; + filePrefix?: string; /** How to handle API responses (e.g., ZIP extraction, single file response) */ responseHandler?: ResponseHandler; @@ -258,7 +258,7 @@ export const useToolOperation = ( // Replace input files with processed files (consumeFiles handles pinning) const inputFileIds: FileId[] = []; const inputFileRecords: FileRecord[] = []; - + // Build parallel arrays of IDs and records for undo tracking for (const file of validFiles) { const fileId = findFileId(file); @@ -274,9 +274,9 @@ export const useToolOperation = ( console.warn(`No file ID found for file: ${file.name}`); } } - + const outputFileIds = await consumeFiles(inputFileIds, processedFiles); - + // Store operation data for undo (only store what we need to avoid memory bloat) lastOperationRef.current = { inputFiles: validFiles, // Keep original File objects for undo @@ -341,17 +341,17 @@ export const useToolOperation = ( try { // Undo the consume operation await undoConsumeFiles(inputFiles, inputFileRecords, outputFileIds); - + // Clear results and operation tracking resetResults(); lastOperationRef.current = null; - + // Show success message actions.setStatus(t('undoSuccess', 'Operation undone successfully')); - + } catch (error: any) { let errorMessage = extractErrorMessage(error); - + // Provide more specific error messages based on error type if (error.message?.includes('Mismatch between input files')) { errorMessage = t('undoDataMismatch', 'Cannot undo: operation data is corrupted'); @@ -360,9 +360,9 @@ export const useToolOperation = ( } else if (error.name === 'QuotaExceededError') { errorMessage = t('undoQuotaError', 'Cannot undo: insufficient storage space'); } - + actions.setError(`${t('undoFailed', 'Failed to undo operation')}: ${errorMessage}`); - + // Don't clear the operation data if undo failed - user might want to try again } }, [undoConsumeFiles, resetResults, actions, t]); diff --git a/frontend/src/hooks/tools/singleLargePage/useSingleLargePageOperation.ts b/frontend/src/hooks/tools/singleLargePage/useSingleLargePageOperation.ts index ef304fa09..b5ef5b5b7 100644 --- a/frontend/src/hooks/tools/singleLargePage/useSingleLargePageOperation.ts +++ b/frontend/src/hooks/tools/singleLargePage/useSingleLargePageOperation.ts @@ -16,7 +16,6 @@ export const singleLargePageOperationConfig = { buildFormData: buildSingleLargePageFormData, operationType: 'single-large-page', endpoint: '/api/v1/general/pdf-to-single-page', - filePrefix: 'single_page_', // Will be overridden in hook with translation defaultParameters, } as const; @@ -25,7 +24,6 @@ export const useSingleLargePageOperation = () => { return useToolOperation({ ...singleLargePageOperationConfig, - filePrefix: t('pdfToSinglePage.filenamePrefix', 'single_page') + '_', getErrorMessage: createStandardErrorHandler(t('pdfToSinglePage.error.failed', 'An error occurred while converting to single page.')) }); }; diff --git a/frontend/src/hooks/tools/split/useSplitOperation.ts b/frontend/src/hooks/tools/split/useSplitOperation.ts index 394fb694d..a2b47f3b5 100644 --- a/frontend/src/hooks/tools/split/useSplitOperation.ts +++ b/frontend/src/hooks/tools/split/useSplitOperation.ts @@ -61,7 +61,6 @@ export const splitOperationConfig = { buildFormData: buildSplitFormData, operationType: 'splitPdf', endpoint: getSplitEndpoint, - filePrefix: 'split_', defaultParameters, } as const; diff --git a/frontend/src/hooks/tools/unlockPdfForms/useUnlockPdfFormsOperation.ts b/frontend/src/hooks/tools/unlockPdfForms/useUnlockPdfFormsOperation.ts index d47800b34..5b55aa00c 100644 --- a/frontend/src/hooks/tools/unlockPdfForms/useUnlockPdfFormsOperation.ts +++ b/frontend/src/hooks/tools/unlockPdfForms/useUnlockPdfFormsOperation.ts @@ -16,7 +16,6 @@ export const unlockPdfFormsOperationConfig = { buildFormData: buildUnlockPdfFormsFormData, operationType: 'unlock-pdf-forms', endpoint: '/api/v1/misc/unlock-pdf-forms', - filePrefix: 'unlocked_forms_', // Will be overridden in hook with translation defaultParameters, } as const; @@ -25,7 +24,6 @@ export const useUnlockPdfFormsOperation = () => { return useToolOperation({ ...unlockPdfFormsOperationConfig, - filePrefix: t('unlockPDFForms.filenamePrefix', 'unlocked_forms') + '_', getErrorMessage: createStandardErrorHandler(t('unlockPDFForms.error.failed', 'An error occurred while unlocking PDF forms.')) }); }; diff --git a/frontend/src/utils/toolResponseProcessor.ts b/frontend/src/utils/toolResponseProcessor.ts index fe2f11242..56c9781ef 100644 --- a/frontend/src/utils/toolResponseProcessor.ts +++ b/frontend/src/utils/toolResponseProcessor.ts @@ -6,11 +6,12 @@ export type ResponseHandler = (blob: Blob, originalFiles: File[]) => Promise { if (responseHandler) { @@ -19,7 +20,8 @@ export async function processResponse( } const original = originalFiles[0]?.name ?? 'result.pdf'; - const name = `${filePrefix}${original}`; + // Only add prefix if it's not empty - this preserves original filenames for file history + const name = filePrefix ? `${filePrefix}${original}` : original; const type = blob.type || 'application/octet-stream'; return [new File([blob], name, { type })]; }