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 c9304405ee - Show all commits
+14 -5
View File
@@ -6,7 +6,7 @@
import type { obsidianTypstPDFExport } from '../../main';
import { ExportErrorHandler } from '../core/ExportErrorHandler';
import { FALLBACK_FONTS } from '../core/constants';
import * as path from 'path';
import { PathUtils } from '../core/PathUtils';
export class FontManager {
constructor(private plugin: obsidianTypstPDFExport) {}
1
@@ -67,8 +67,11 @@ export class FontManager {
typstPath: typstPath
};
const fontsCachePath = path.join(this.plugin.manifest.dir!, 'fonts-cache.json');
await this.plugin.app.vault.adapter.write(fontsCachePath,
const pathUtils = new PathUtils(this.plugin.app);
const vaultPath = pathUtils.getVaultPath();
const pluginDir = pathUtils.getPluginDir(this.plugin.manifest);
const fontsCachePath = pathUtils.joinPath(vaultPath, pluginDir, 'fonts-cache.json');
await this.plugin.app.vault.adapter.write(fontsCachePath,
JSON.stringify(cacheData, null, 2));
} catch (error) {
console.error('Failed to cache fonts from typst:', error);
@@ -86,7 +89,10 @@ export class FontManager {
error: error.message
};
const fontsCachePath = path.join(this.plugin.manifest.dir!, 'fonts-cache.json');
const pathUtils = new PathUtils(this.plugin.app);
const vaultPath = pathUtils.getVaultPath();
const pluginDir = pathUtils.getPluginDir(this.plugin.manifest);
const fontsCachePath = pathUtils.joinPath(vaultPath, pluginDir, 'fonts-cache.json');
await this.plugin.app.vault.adapter.write(fontsCachePath,
JSON.stringify(cacheData, null, 2));
}
@@ -97,7 +103,10 @@ export class FontManager {
*/
coderabbitai[bot] commented 2025-09-25 13:05:41 +02:00 (Migrated from github.com)
Review

⚠️ Potential issue | 🟠 Major

Read cache via vault-relative path too.

-      const pathUtils = new PathUtils(this.plugin.app);
-      const vaultPath = pathUtils.getVaultPath();
-      const pluginDir = pathUtils.getPluginDir(this.plugin.manifest);
-      const fontsCachePath = pathUtils.joinPath(vaultPath, pluginDir, 'fonts-cache.json');
+      const pathUtils = new PathUtils(this.plugin.app);
+      const pluginRelDir = pathUtils.getPluginDir(this.plugin.manifest);
+      const fontsCachePath = pathUtils.joinPath(pluginRelDir, 'fonts-cache.json');
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

			const pathUtils = new PathUtils(this.plugin.app);
			const pluginRelDir = pathUtils.getPluginDir(this.plugin.manifest);
			const fontsCachePath = pathUtils.joinPath(pluginRelDir, 'fonts-cache.json');
			const cacheContent = await this.plugin.app.vault.adapter.read(fontsCachePath);
			const cacheData = JSON.parse(cacheContent);
🤖 Prompt for AI Agents
In src/plugin/FontManager.ts around lines 106 to 111, the code builds an
absolute vaultPath and passes it to app.vault.adapter.read, but adapter.read
expects a vault-relative path; change the read call to use the vault-relative
path (e.g., join pluginDir and 'fonts-cache.json' or use a PathUtils helper that
returns a vault-relative path) instead of including the full vaultPath, and add
a try/catch or existence check before parsing to handle missing or unreadable
cache files.

✅ Addressed in commits 24a169d to 2cdc9c3

_⚠️ Potential issue_ | _🟠 Major_ **Read cache via vault-relative path too.** ```diff - const pathUtils = new PathUtils(this.plugin.app); - const vaultPath = pathUtils.getVaultPath(); - const pluginDir = pathUtils.getPluginDir(this.plugin.manifest); - const fontsCachePath = pathUtils.joinPath(vaultPath, pluginDir, 'fonts-cache.json'); + const pathUtils = new PathUtils(this.plugin.app); + const pluginRelDir = pathUtils.getPluginDir(this.plugin.manifest); + const fontsCachePath = pathUtils.joinPath(pluginRelDir, 'fonts-cache.json'); ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion const pathUtils = new PathUtils(this.plugin.app); const pluginRelDir = pathUtils.getPluginDir(this.plugin.manifest); const fontsCachePath = pathUtils.joinPath(pluginRelDir, 'fonts-cache.json'); const cacheContent = await this.plugin.app.vault.adapter.read(fontsCachePath); const cacheData = JSON.parse(cacheContent); ``` </details> <!-- suggestion_end --> <details> <summary>🤖 Prompt for AI Agents</summary> ``` In src/plugin/FontManager.ts around lines 106 to 111, the code builds an absolute vaultPath and passes it to app.vault.adapter.read, but adapter.read expects a vault-relative path; change the read call to use the vault-relative path (e.g., join pluginDir and 'fonts-cache.json' or use a PathUtils helper that returns a vault-relative path) instead of including the full vaultPath, and add a try/catch or existence check before parsing to handle missing or unreadable cache files. ``` </details> <!-- fingerprinting:phantom:poseidon:chinchilla --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commits 24a169d to 2cdc9c3
async getCachedFonts(): Promise<string[]> {
try {
const fontsCachePath = path.join(this.plugin.manifest.dir!, 'fonts-cache.json');
const pathUtils = new PathUtils(this.plugin.app);
const vaultPath = pathUtils.getVaultPath();
const pluginDir = pathUtils.getPluginDir(this.plugin.manifest);
const fontsCachePath = pathUtils.joinPath(vaultPath, pluginDir, 'fonts-cache.json');
const cacheContent = await this.plugin.app.vault.adapter.read(fontsCachePath);
const cacheData = JSON.parse(cacheContent);
1