andy-stack_vaultkeeper-ai/Services/WorkSpaceService.ts
Andrew Beal 28376053c4 Add exclusion filtering to active file retrieval
Enhance WorkSpaceService.getActiveFile() to filter out excluded files using VaultService.isExclusion(), preventing access to restricted paths. Add optional allowAccessToPluginRoot parameter for cases requiring access to plugin root directory. Update test expectations to match new method signature.
2025-12-23 14:08:10 +00:00

29 lines
No EOL
1.1 KiB
TypeScript

import type VaultkeeperAIPlugin from "main";
import { Resolve } from "./DependencyService";
import { Services } from "./Services";
import type { TFile, WorkspaceLeaf } from "obsidian";
import type { VaultService } from "./VaultService";
export class WorkSpaceService {
private readonly plugin: VaultkeeperAIPlugin = Resolve<VaultkeeperAIPlugin>(Services.VaultkeeperAIPlugin);
private readonly vaultService: VaultService = Resolve<VaultService>(Services.VaultService);
public async openNote(noteName: string) {
const file: TFile | null = this.plugin.app.metadataCache.getFirstLinkpathDest(noteName, "");
const leaf: WorkspaceLeaf = this.plugin.app.workspace.getLeaf(false);
if (file) {
await leaf.openFile(file);
}
}
public getActiveFile(allowAccessToPluginRoot: boolean = false): TFile | null {
const activeFile = this.plugin.app.workspace.getActiveFile();
if (!activeFile || this.vaultService.isExclusion(activeFile.path, allowAccessToPluginRoot)) {
return null;
}
return activeFile;
}
}