scan
This commit is contained in:
@@ -80,6 +80,9 @@ interface State {
|
||||
matches: Set<string> | null // null = not searching; else the matched paths
|
||||
searching: boolean
|
||||
searchStats: { count: number; bytes: number }
|
||||
|
||||
scanning: boolean
|
||||
scanError: string
|
||||
}
|
||||
|
||||
export const store = reactive<State>({
|
||||
@@ -102,6 +105,9 @@ export const store = reactive<State>({
|
||||
matches: null,
|
||||
searching: false,
|
||||
searchStats: { count: 0, bytes: 0 },
|
||||
|
||||
scanning: false,
|
||||
scanError: '',
|
||||
})
|
||||
|
||||
let searchTimer: ReturnType<typeof setTimeout> | null = null
|
||||
@@ -216,6 +222,49 @@ export async function toggleCollection(id: string): Promise<void> {
|
||||
if (store.query) runSearch(store.query)
|
||||
}
|
||||
|
||||
/** Scan a source folder (runs process_tree.py server-side) → new collection. */
|
||||
export async function scanFolder(source: string): Promise<void> {
|
||||
if (!source.trim()) return
|
||||
store.scanning = true
|
||||
store.scanError = ''
|
||||
try {
|
||||
const res = await fetch('/api/scan', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ source: source.trim() }),
|
||||
})
|
||||
const data = await res.json()
|
||||
if (!res.ok) { store.scanError = data.error ?? `HTTP ${res.status}`; return }
|
||||
await loadCollections()
|
||||
if (data.id) store.activeCollections.add(data.id) // show the new source
|
||||
await loadTree()
|
||||
} catch (e) {
|
||||
store.scanError = String(e)
|
||||
} finally {
|
||||
store.scanning = false
|
||||
}
|
||||
}
|
||||
|
||||
/** Re-run the scan for an existing collection (its recorded source). */
|
||||
export async function rescanCollection(id: string): Promise<void> {
|
||||
store.scanning = true
|
||||
store.scanError = ''
|
||||
try {
|
||||
const res = await fetch('/api/rescan', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ id }),
|
||||
})
|
||||
const data = await res.json()
|
||||
if (!res.ok) { store.scanError = data.error ?? `HTTP ${res.status}`; return }
|
||||
await loadCollections()
|
||||
await loadTree()
|
||||
if (store.query) runSearch(store.query)
|
||||
} catch (e) {
|
||||
store.scanError = String(e)
|
||||
} finally {
|
||||
store.scanning = false
|
||||
}
|
||||
}
|
||||
|
||||
export async function select(path: string): Promise<void> {
|
||||
store.selectedPath = path
|
||||
store.detailCollapsed = false // opening a file expands the viewer
|
||||
|
||||
Reference in New Issue
Block a user