diff --git a/src/app/locate-db.ts b/src/app/locate-db.ts index 7a28430..4ed40ca 100644 --- a/src/app/locate-db.ts +++ b/src/app/locate-db.ts @@ -180,12 +180,27 @@ export async function buildLocateDb( signal?.throwIfAborted(); const sqlite3 = await getSqlite3(); - // ── 1. Recursive PROPFIND on /sd ──────────────────────────────────────── - const entries = await listDirectory( - '/sd', true, - bytes => onProgress?.('scanning', bytes), - signal, - ); + // ── 1. BFS directory walk with Depth:1 per directory ──────────────────── + // Depth:infinity is not supported by the device's WebDAV server, so we + // walk the tree manually, one directory at a time. + const entries: Awaited> = []; + const queue: string[] = ['/sd']; + let totalBytes = 0; + + while (queue.length > 0) { + signal?.throwIfAborted(); + const dir = queue.shift()!; + let prevBytes = 0; + const batch = await listDirectory(dir, false, bytes => { + totalBytes += bytes - prevBytes; + prevBytes = bytes; + onProgress?.('scanning', totalBytes, dir); + }, signal); + for (const e of batch) { + entries.push(e); + if (e.type === 'folder') queue.push(e.path); + } + } signal?.throwIfAborted(); // ── 2. Build in-memory DB ───────────────────────────────────────────────