()
| 321 | |
| 322 | // Execute the end-to-end processing workflow |
| 323 | async function startWorkflow() { |
| 324 | try { |
| 325 | state.isProcessing = true; |
| 326 | console.log('🚀 Starting workflow...'); |
| 327 | |
| 328 | // Step 1: compress |
| 329 | await setStep(2); |
| 330 | showProgress('Compressing GIFs...', 0); |
| 331 | state.compressedFiles = await compressGifs(state.originalFiles); |
| 332 | console.log(`📦 Compressed files: ${state.compressedFiles.length}`); |
| 333 | |
| 334 | // Step 2: deduplicate |
| 335 | await setStep(3); |
| 336 | showProgress('Detecting duplicates...', 0); |
| 337 | state.deduplicatedFiles = await deduplicateGifs(state.compressedFiles); |
| 338 | console.log(`🔍 After deduplication: ${state.deduplicatedFiles.length}`); |
| 339 | |
| 340 | // Step 3: rename |
| 341 | if (state.settings.autoRename) { |
| 342 | await setStep(4); |
| 343 | showProgress('Renaming files...', 0); |
| 344 | state.finalFiles = await renameGifs(state.deduplicatedFiles); |
| 345 | console.log(`✏️ After rename: ${state.finalFiles.length}`); |
| 346 | } else { |
| 347 | state.finalFiles = state.deduplicatedFiles; |
| 348 | console.log(`📝 Skipped rename. Final files: ${state.finalFiles.length}`); |
| 349 | } |
| 350 | |
| 351 | // Step 4: display results |
| 352 | await setStep(5); |
| 353 | console.log(`🎬 Ready to display ${state.finalFiles.length} files`); |
| 354 | displayResults(); |
| 355 | |
| 356 | } catch (error) { |
| 357 | console.error('❌ Workflow failed:', error); |
| 358 | alert('Processing failed: ' + error.message); |
| 359 | restart(); |
| 360 | } finally { |
| 361 | state.isProcessing = false; |
| 362 | hideProgress(); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | // Update the current step |
| 367 | async function setStep(step) { |
no test coverage detected