Replace Windows path separators in indexName configured via Khoj Obsidian

Resolves #185, #199

- Issue
  IndexName created from Obsidian Absolute Vault path wasn't replacing
  windows path, drive separators with underscore. It was only
  replacing unix path separators

- Fix
  Also replace windows drive and path separators with _ while creating
  IndexName in Khoj Obsidian plugin
This commit is contained in:
Debanjum Singh Solanky 2023-04-17 16:24:13 +07:00
parent d90df966a9
commit b079fb31bc

View file

@ -10,7 +10,8 @@ export function getVaultAbsolutePath(vault: Vault): string {
}
export async function configureKhojBackend(vault: Vault, setting: KhojSetting, notify: boolean = true) {
let mdInVault = `${getVaultAbsolutePath(vault)}/**/*.md`;
let vaultPath = getVaultAbsolutePath(vault);
let mdInVault = `${vaultPath}/**/*.md`;
let khojConfigUrl = `${setting.khojUrl}/api/config/data`;
// Check if khoj backend is configured, note if cannot connect to backend
@ -28,7 +29,7 @@ export async function configureKhojBackend(vault: Vault, setting: KhojSetting, n
if (!setting.connectedToBackend) return;
// Set index name from the path of the current vault
let indexName = getVaultAbsolutePath(vault).replace(/\//g, '_').replace(/ /g, '_');
let indexName = vaultPath.replace(/\//g, '_').replace(/\\/g, '_').replace(/ /g, '_').replace(/:/g, '_');
// Get default config fields from khoj backend
let defaultConfig = await request(`${khojConfigUrl}/default`).then(response => JSON.parse(response));
let khojDefaultIndexDirectory = getIndexDirectoryFromBackendConfig(defaultConfig["content-type"]["markdown"]["embeddings-file"]);