mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-02 12:22:40 +02:00
feat: enhance Local Folder connector with version history and folder sync capabilities
This commit is contained in:
parent
e2f946b7c0
commit
5eeee99bb1
14 changed files with 742 additions and 1 deletions
41
surfsense_web/hooks/use-folder-sync.ts
Normal file
41
surfsense_web/hooks/use-folder-sync.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
"use client";
|
||||
|
||||
import { useEffect, useRef } from "react";
|
||||
import { connectorsApiService } from "@/lib/apis/connectors-api.service";
|
||||
|
||||
const DEBOUNCE_MS = 2000;
|
||||
|
||||
export function useFolderSync() {
|
||||
const pendingRef = useRef<Map<string, ReturnType<typeof setTimeout>>>(new Map());
|
||||
|
||||
useEffect(() => {
|
||||
const api = typeof window !== "undefined" ? window.electronAPI : null;
|
||||
if (!api?.onFileChanged) return;
|
||||
|
||||
const cleanup = api.onFileChanged((event) => {
|
||||
const key = `${event.connectorId}:${event.fullPath}`;
|
||||
|
||||
const existing = pendingRef.current.get(key);
|
||||
if (existing) clearTimeout(existing);
|
||||
|
||||
const timeout = setTimeout(async () => {
|
||||
pendingRef.current.delete(key);
|
||||
try {
|
||||
await connectorsApiService.indexFile(event.connectorId, event.fullPath);
|
||||
} catch (err) {
|
||||
console.error("[FolderSync] Failed to trigger re-index:", err);
|
||||
}
|
||||
}, DEBOUNCE_MS);
|
||||
|
||||
pendingRef.current.set(key, timeout);
|
||||
});
|
||||
|
||||
return () => {
|
||||
cleanup();
|
||||
for (const timeout of pendingRef.current.values()) {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
pendingRef.current.clear();
|
||||
};
|
||||
}, []);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue