Enhances path handling and file resolution #5

Merged
AlexKucera merged 36 commits from 1.3.0 into master 2025-09-25 16:47:12 +02:00
Showing only changes of commit d54ac148c0 - Show all commits
+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);
1