refactor: improve path normalization and method visibility

- Integrate Obsidian's normalizePath() in SanitiserService
- Make plugin lifecycle methods public for better API access
This commit is contained in:
Andrew Beal 2025-11-01 15:02:41 +00:00
parent 0851e81d7b
commit 9aeb3c2ba1
2 changed files with 11 additions and 4 deletions

View file

@ -1,8 +1,12 @@
import { normalizePath } from "obsidian";
export interface ISanitizeOptions {
replacement?: string;
separator?: string;
}
// this service handles edge cases that 'normalizePath()' misses
export class SanitiserService {
// Regular expressions for different character classes
private readonly illegalRe = /[\?<>\\:\*\|"]/g;
@ -25,6 +29,9 @@ export class SanitiserService {
throw new Error("Input must be a string");
}
// use obsidian helper first
input = normalizePath(input);
// Normalize empty string to "/" for vault root
if (input.trim() === "") {
return "/";

View file

@ -22,7 +22,7 @@ const DEFAULT_SETTINGS: IAIAgentSettings = {
export default class AIAgentPlugin extends Plugin {
public settings: IAIAgentSettings;
async onload() {
public async onload() {
// KaTeX CSS is bundled with the plugin to comply with CSP
require('katex/dist/katex.min.css');
// Plugin styles
@ -52,12 +52,12 @@ export default class AIAgentPlugin extends Plugin {
this.addSettingTab(new AIAgentSettingTab(this.app, this));
}
async onunload() {
public async onunload() {
Resolve<StatusBarService>(Services.StatusBarService).removeStatusBarMessage();
DeregisterAllServices();
}
async activateView() {
public async activateView() {
const { workspace } = this.app;
let leaf: WorkspaceLeaf | null = null;
@ -75,7 +75,7 @@ export default class AIAgentPlugin extends Plugin {
}
}
async loadSettings() {
public async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}