fix(bridge): resolve data dir same as Python for sync-result.json
Both readSyncResult() and probeAll() now mirror Python's _resolve_data_dir() logic: dev detection (cwd/.obsidian-rag or cwd/KnowledgeVault) then home dir fallback. Previously readSyncResult always used cwd/.obsidian-rag (wrong for server deployments) and probeAll resolved sync-result.json relative to db path (wrong for absolute paths like /home/san/.obsidian-rag/).
This commit is contained in:
@@ -98,7 +98,8 @@ export async function probeAll(config: ObsidianRagConfig): Promise<ProbeResult>
|
|||||||
|
|
||||||
if (indexExists) {
|
if (indexExists) {
|
||||||
try {
|
try {
|
||||||
const syncPath = resolve(dbPath, "..", "sync-result.json");
|
const dataDir = resolveDataDir();
|
||||||
|
const syncPath = resolve(dataDir, "sync-result.json");
|
||||||
if (existsSync(syncPath)) {
|
if (existsSync(syncPath)) {
|
||||||
const data = JSON.parse(readFileSync(syncPath, "utf-8"));
|
const data = JSON.parse(readFileSync(syncPath, "utf-8"));
|
||||||
lastSync = data.timestamp ?? null;
|
lastSync = data.timestamp ?? null;
|
||||||
@@ -120,6 +121,17 @@ export async function probeAll(config: ObsidianRagConfig): Promise<ProbeResult>
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolveDataDir(): string {
|
||||||
|
const cwd = process.cwd();
|
||||||
|
const devDataDir = resolve(cwd, ".obsidian-rag");
|
||||||
|
const devVaultMarker = resolve(cwd, "KnowledgeVault");
|
||||||
|
if (existsSync(devDataDir) || existsSync(devVaultMarker)) {
|
||||||
|
return devDataDir;
|
||||||
|
}
|
||||||
|
const home = process.env.HOME ?? process.env.USERPROFILE ?? "";
|
||||||
|
return resolve(home, ".obsidian-rag");
|
||||||
|
}
|
||||||
|
|
||||||
async function probeOllama(baseUrl: string): Promise<boolean> {
|
async function probeOllama(baseUrl: string): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${baseUrl}/api/tags`, { signal: AbortSignal.timeout(3000) });
|
const res = await fetch(`${baseUrl}/api/tags`, { signal: AbortSignal.timeout(3000) });
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ export function readSyncResult(config: ObsidianRagConfig): {
|
|||||||
total_chunks: number;
|
total_chunks: number;
|
||||||
errors: Array<{ file: string; error: string }>;
|
errors: Array<{ file: string; error: string }>;
|
||||||
} | null {
|
} | null {
|
||||||
const dataDir = resolve(process.cwd(), ".obsidian-rag");
|
const dataDir = _resolveDataDir();
|
||||||
const path = resolve(dataDir, "sync-result.json");
|
const path = resolve(dataDir, "sync-result.json");
|
||||||
if (!existsSync(path)) return null;
|
if (!existsSync(path)) return null;
|
||||||
try {
|
try {
|
||||||
@@ -118,3 +118,14 @@ export function readSyncResult(config: ObsidianRagConfig): {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _resolveDataDir(): string {
|
||||||
|
const cwd = process.cwd();
|
||||||
|
const devDataDir = resolve(cwd, ".obsidian-rag");
|
||||||
|
const devVaultMarker = resolve(cwd, "KnowledgeVault");
|
||||||
|
if (existsSync(devDataDir) || existsSync(devVaultMarker)) {
|
||||||
|
return devDataDir;
|
||||||
|
}
|
||||||
|
const home = process.env.HOME ?? process.env.USERPROFILE ?? "";
|
||||||
|
return resolve(home, ".obsidian-rag");
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user