fix(ImageOptimizer): Convert absolute paths to vault-relative for adapter.remove()

- Fixed vault.adapter.remove() call to use vault-relative paths instead of absolute paths
- Added proper path conversion by stripping vault base path and leading separators
- Maintains fs.unlink fallback when plugin.app is not available
- Prevents potential file removal failures due to incorrect path format
- Follows Obsidian API best practices for vault operations

🤖 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:23:54 +02:00
1 parent a1293808af
commit d54ac148c0
1 file changed
+14 -1
+14 -1
View File
@@ -218,7 +218,20 @@ export class ImageOptimizer {
// Clean up the original PNG if conversion succeeded
try {
if (plugin?.app) {
await plugin.app.vault.adapter.remove(inputImagePath);
// Convert absolute path to vault-relative path for adapter.remove()
const pathUtils = new PathUtils(plugin.app);
const vaultBasePath = pathUtils.getVaultPath();
let relativePath = inputImagePath;
if (inputImagePath.startsWith(vaultBasePath)) {
// Remove vault base path and leading separator
relativePath = inputImagePath.substring(vaultBasePath.length);
if (relativePath.startsWith('/') || relativePath.startsWith('\\')) {
relativePath = relativePath.substring(1);
}
}
await plugin.app.vault.adapter.remove(relativePath);
} else {
const fs = require('fs').promises;
await fs.unlink(inputImagePath);