mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-08-26 14:19:24 +00:00
feat: Add file ID lookup and integrate with file consumption in tool operations
This commit is contained in:
parent
50f4ccd4d5
commit
b8cf5fda7e
@ -375,7 +375,7 @@ const PageEditor = ({
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(`📸 PageEditor: Thumbnail generation completed for ${pageNumbers.length} pages`);
|
// Removed verbose logging - only log errors
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('PageEditor: Thumbnail generation failed:', error);
|
console.error('PageEditor: Thumbnail generation failed:', error);
|
||||||
}
|
}
|
||||||
@ -399,7 +399,7 @@ const PageEditor = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (chunkPageNumbers.length > 0) {
|
if (chunkPageNumbers.length > 0) {
|
||||||
console.log(`📸 PageEditor: Background generating chunk: pages ${start}-${end} (${chunkPageNumbers.length} needed)`);
|
// Background thumbnail generation in progress (removed verbose logging)
|
||||||
await generateThumbnailBatch(file, fileId, chunkPageNumbers);
|
await generateThumbnailBatch(file, fileId, chunkPageNumbers);
|
||||||
|
|
||||||
// Small delay between chunks to keep UI responsive
|
// Small delay between chunks to keep UI responsive
|
||||||
|
@ -161,6 +161,17 @@ export function useFileContext() {
|
|||||||
markOperationApplied: (fileId: string, operationId: string) => {}, // TODO: Implement operation tracking
|
markOperationApplied: (fileId: string, operationId: string) => {}, // TODO: Implement operation tracking
|
||||||
markOperationFailed: (fileId: string, operationId: string, error: string) => {}, // TODO: Implement operation tracking
|
markOperationFailed: (fileId: string, operationId: string, error: string) => {}, // TODO: Implement operation tracking
|
||||||
|
|
||||||
|
// File ID lookup
|
||||||
|
findFileId: (file: File) => {
|
||||||
|
return state.files.ids.find(id => {
|
||||||
|
const record = state.files.byId[id];
|
||||||
|
return record &&
|
||||||
|
record.name === file.name &&
|
||||||
|
record.size === file.size &&
|
||||||
|
record.lastModified === file.lastModified;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
// Pinned files
|
// Pinned files
|
||||||
pinnedFiles: state.pinnedFiles,
|
pinnedFiles: state.pinnedFiles,
|
||||||
pinFile: actions.pinFile,
|
pinFile: actions.pinFile,
|
||||||
|
@ -104,7 +104,7 @@ export const useToolOperation = <TParams = void>(
|
|||||||
config: ToolOperationConfig<TParams>
|
config: ToolOperationConfig<TParams>
|
||||||
): ToolOperationHook<TParams> => {
|
): ToolOperationHook<TParams> => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { recordOperation, markOperationApplied, markOperationFailed, addFiles } = useFileContext();
|
const { recordOperation, markOperationApplied, markOperationFailed, addFiles, consumeFiles, findFileId } = useFileContext();
|
||||||
|
|
||||||
// Composed hooks
|
// Composed hooks
|
||||||
const { state, actions } = useToolState();
|
const { state, actions } = useToolState();
|
||||||
@ -198,8 +198,9 @@ export const useToolOperation = <TParams = void>(
|
|||||||
actions.setThumbnails(thumbnails);
|
actions.setThumbnails(thumbnails);
|
||||||
actions.setDownloadInfo(downloadInfo.url, downloadInfo.filename);
|
actions.setDownloadInfo(downloadInfo.url, downloadInfo.filename);
|
||||||
|
|
||||||
// Add processed files to the file context
|
// Replace input files with processed files (consumeFiles handles pinning)
|
||||||
await addFiles(processedFiles);
|
const inputFileIds = validFiles.map(file => findFileId(file)).filter(Boolean) as string[];
|
||||||
|
await consumeFiles(inputFileIds, processedFiles);
|
||||||
|
|
||||||
markOperationApplied(fileId, operationId);
|
markOperationApplied(fileId, operationId);
|
||||||
}
|
}
|
||||||
@ -213,7 +214,7 @@ export const useToolOperation = <TParams = void>(
|
|||||||
actions.setLoading(false);
|
actions.setLoading(false);
|
||||||
actions.setProgress(null);
|
actions.setProgress(null);
|
||||||
}
|
}
|
||||||
}, [t, config, actions, recordOperation, markOperationApplied, markOperationFailed, addFiles, processFiles, generateThumbnails, createDownloadInfo, cleanupBlobUrls, extractZipFiles, extractAllZipFiles]);
|
}, [t, config, actions, recordOperation, markOperationApplied, markOperationFailed, addFiles, consumeFiles, findFileId, processFiles, generateThumbnails, createDownloadInfo, cleanupBlobUrls, extractZipFiles, extractAllZipFiles]);
|
||||||
|
|
||||||
const cancelOperation = useCallback(() => {
|
const cancelOperation = useCallback(() => {
|
||||||
cancelApiCalls();
|
cancelApiCalls();
|
||||||
|
@ -248,9 +248,6 @@ export interface FileContextActions {
|
|||||||
trackPdfDocument: (key: string, pdfDoc: any) => void;
|
trackPdfDocument: (key: string, pdfDoc: any) => void;
|
||||||
scheduleCleanup: (fileId: string, delay?: number) => void;
|
scheduleCleanup: (fileId: string, delay?: number) => void;
|
||||||
cleanupFile: (fileId: string) => void;
|
cleanupFile: (fileId: string) => void;
|
||||||
|
|
||||||
// Persistence operations
|
|
||||||
loadFromPersistence: () => Promise<void>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// File selectors (separate from actions to avoid re-renders)
|
// File selectors (separate from actions to avoid re-renders)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user