fix(FileDiscovery): Add vault path detection for safe adapter.list() usage

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 <noreply@anthropic.com>
This commit is contained in:
Jarvis committed 2025-09-25 16:39:08 +02:00
1 parent 0cd6b53687
commit 731a76eaf2
1 file changed
+27 -3
+27 -3
View File
@@ -81,11 +81,35 @@ export class FileDiscovery {
plugin: obsidianTypstPDFExport plugin: obsidianTypstPDFExport
): Promise<FileDiscoveryResult> { ): Promise<FileDiscoveryResult> {
try { 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); 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 // Look for any image files that might match
const imageFiles = files.filter(f => const imageFiles = files.filter(f =>
this.SUPPORTED_IMAGE_EXTENSIONS.some(ext => f.toLowerCase().endsWith(ext)) this.SUPPORTED_IMAGE_EXTENSIONS.some(ext => f.toLowerCase().endsWith(ext))