From 731a76eaf21e18d2e38ca5953833967cea05434d Mon Sep 17 00:00:00 2001 From: Jarvis Date: Thu, 25 Sep 2025 16:39:08 +0200 Subject: [PATCH] fix(FileDiscovery): Add vault path detection for safe adapter.list() usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevents adapter.list() errors on absolute temp paths by detecting whether outputDir is inside the vault and using filesystem fallback for external/absolute paths. Only calls adapter.list() with vault-relative paths for proper Obsidian compatibility. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/converters/pdf/FileDiscovery.ts | 30 ++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/converters/pdf/FileDiscovery.ts b/src/converters/pdf/FileDiscovery.ts index b5945d9..11edd11 100644 --- a/src/converters/pdf/FileDiscovery.ts +++ b/src/converters/pdf/FileDiscovery.ts @@ -81,11 +81,35 @@ export class FileDiscovery { plugin: obsidianTypstPDFExport ): Promise { try { - // Debug: List what files are actually in the output directory - const dirList = await plugin.app.vault.adapter.list(outputDir); - const files = dirList.files.map(f => path.basename(f)); const pathUtils = new PathUtils(plugin.app); + // Check if outputDir is inside the vault + const vaultPath = plugin.app.vault.adapter.basePath || ''; + let isVaultRelative = false; + let vaultRelativeDir = outputDir; + + if (vaultPath) { + // Compute relative path from vault root + const relativePath = path.relative(vaultPath, outputDir); + // Path is inside vault if it doesn't start with '..' or path separator + isVaultRelative = !relativePath.startsWith('..') && !path.isAbsolute(relativePath); + if (isVaultRelative) { + vaultRelativeDir = relativePath; + } + } + + let files: string[]; + + if (isVaultRelative) { + // Use adapter for vault-relative paths + const dirList = await plugin.app.vault.adapter.list(vaultRelativeDir); + files = dirList.files.map(f => path.basename(f)); + } else { + // Use filesystem fallback for absolute/external paths + const fs = require('fs').promises; + files = await fs.readdir(outputDir); + } + // Look for any image files that might match const imageFiles = files.filter(f => this.SUPPORTED_IMAGE_EXTENSIONS.some(ext => f.toLowerCase().endsWith(ext))