From b255b6354e576102b1b5cf2e20d9a4358d1eb938 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Thu, 4 Sep 2025 15:01:06 +0200 Subject: [PATCH] Refactors batch export logic Consolidates the export files and export files with configuration functionalities into a shared `processBatchExport` method. This reduces code duplication and improves maintainability by centralizing the batch processing logic. --- main.ts | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/main.ts b/main.ts index ea6d0b2..5d5ce04 100644 --- a/main.ts +++ b/main.ts @@ -440,26 +440,11 @@ export class obsidianTypstPDFExport extends Plugin { * Export multiple files with default configuration */ private async exportFiles(files: TFile[]): Promise { - if (files.length === 0) { - new Notice('No files to export'); - return; - } - - ExportErrorHandler.showProgressNotice(`Exporting ${files.length} files to PDF...`); - - const { recordSuccess, recordError, getResult } = ExportErrorHandler.createBatchTracker(); - - for (const file of files) { - try { - await this.exportFile(file); - recordSuccess(); - } catch (error) { - recordError(file.name, error); - } - } - - // Show final result - ExportErrorHandler.handleBatchResult(getResult()); + await this.processBatchExport( + files, + `Exporting ${files.length} files to PDF...`, + (file: TFile) => this.exportFile(file) + ); } /** @@ -582,18 +567,33 @@ export class obsidianTypstPDFExport extends Plugin { * Export multiple files with specific configuration */ private async exportFilesWithConfig(files: TFile[], config: ExportConfig): Promise { + await this.processBatchExport( + files, + `Exporting ${files.length} files with custom configuration...`, + (file: TFile) => this.exportFileWithConfig(file, config) + ); + } + + /** + * Common batch processing logic for exporting multiple files + */ + private async processBatchExport( + files: TFile[], + progressMessage: string, + exportFunction: (file: TFile) => Promise + ): Promise { if (files.length === 0) { new Notice('No files to export'); return; } - ExportErrorHandler.showProgressNotice(`Exporting ${files.length} files with custom configuration...`); + ExportErrorHandler.showProgressNotice(progressMessage); const { recordSuccess, recordError, getResult } = ExportErrorHandler.createBatchTracker(); for (const file of files) { try { - await this.exportFileWithConfig(file, config); + await exportFunction(file); recordSuccess(); } catch (error) { recordError(file.name, error);