Stirling-PDF/frontend/public/thumbnailWorker.js
Reece Browne f353d3404c Refactor file context and tool operations
- Updated `useToolOperation` to include file ID and operation parameters for better tracking.
- Enhanced `useToolResources` to utilize refs for blob URL cleanup, improving performance and reducing unnecessary state updates.
- Modified `ThumbnailGenerationService` to clarify worker setup and fallback mechanisms, removing excessive logging for cleaner output.
- Refactored tool components (Compress, Convert, OCR, Split) to use `useFileActions` for state management, ensuring consistency across tools.
- Expanded `FileContextState` and `FileContextActions` to support new file processing features and improved state management.
- Added new `FileContextSelectors` for efficient file access and state querying, minimizing re-renders in components.
2025-08-12 14:37:45 +01:00

27 lines
753 B
JavaScript

// Web Worker for lightweight data processing (not PDF rendering)
// PDF rendering must stay on main thread due to DOM dependencies
self.onmessage = async function(e) {
const { type, data, jobId } = e.data;
try {
// Handle PING for worker health check
if (type === 'PING') {
self.postMessage({ type: 'PONG', jobId });
return;
}
if (type === 'GENERATE_THUMBNAILS') {
// Web Workers cannot do PDF rendering due to DOM dependencies
// This is expected to fail and trigger main thread fallback
throw new Error('PDF rendering requires main thread (DOM access needed)');
}
} catch (error) {
self.postMessage({
type: 'ERROR',
jobId,
data: { error: error.message }
});
}
};