@@ -256,20 +256,7 @@ export class DocBase {
256
256
257
257
// 初始化监视器扫描器
258
258
console . info ( "Initializing watcher and scanner..." ) ;
259
- const { watcher, scanner } = FSLayer ( {
260
- filter : ( path : string ) => {
261
- const ext = getExtFromPath ( path ) ;
262
- return this . #docExtToLoaderName. has ( ext ) ;
263
- } ,
264
- upsert : ( path : string ) => {
265
- this . #watcherTaskCache. set ( path , "upsert" ) ;
266
- this . #doWatcherTask( ) ;
267
- } ,
268
- remove : ( path : string ) => {
269
- this . #watcherTaskCache. set ( path , "remove" ) ;
270
- this . #doWatcherTask( ) ;
271
- } ,
272
- } ) ;
259
+ const { watcher, scanner } = FSLayer ( ) ;
273
260
this . #docWatcher = watcher ;
274
261
this . #docScanner = scanner ;
275
262
console . info ( "Watcher and scanner initialized successfully." ) ;
@@ -278,43 +265,63 @@ export class DocBase {
278
265
console . info ( "Initializing DocManager..." ) ;
279
266
const docLoader = ( input : DocLoaderInput ) => this . #hyperDocLoader( input )
280
267
const docSplitter = ( content : AsyncIterable < Content > ) => this . #docSplitter. func ( content )
268
+ const filter = ( path : string ) => {
269
+ const ext = getExtFromPath ( path ) ;
270
+ return this . #docExtToLoaderName. has ( ext ) ;
271
+ }
281
272
const base = await db . base . get ( )
282
273
283
- base . map ( async ( { path, id } ) => {
284
- const docm = new DocManager ( {
285
- indexPrefix : id ,
286
- meiliSearch : this . #meiliSearch,
287
- docLoader,
288
- docSplitter,
289
- } ) ;
290
- await docm . init ( )
291
- // 扫描目录
292
- await this . #scan( [ path ] ) ;
293
- // 监视目录
294
- this . #docWatcher. watch ( path )
295
- return docm
296
- } )
297
- console . info ( "DocManager initialized successfully." ) ;
298
-
299
- // 扫描加载默认目录下文档
300
- // console.info("Scanning initial directories...");
301
- // console.info("Initial directories scanned successfully.");
302
-
303
- // 开启监视,同步变动文档
304
- // console.info("Starting to watch directories...");
305
- // initPaths.map((initPath) => this.#docWatcher.watch(initPath));
306
- // console.info("Directories are being watched.");
274
+ const result = await Promise . allSettled (
275
+ base . map ( async ( { path, id } ) => {
276
+ console . info ( `Init base ${ id } ...` ) ;
277
+ const docm = new DocManager ( {
278
+ indexPrefix : id ,
279
+ meiliSearch : this . #meiliSearch,
280
+ docLoader,
281
+ docSplitter,
282
+ } ) ;
283
+ await docm . init ( )
284
+ this . #docManagers. set ( id , docm )
285
+ console . info ( `Base ${ id } init successfully.` ) ;
286
+
287
+ // 扫描目录
288
+ console . info ( `Scanning base ${ id } ...` ) ;
289
+ await this . #scan( id , [ path ] ) ;
290
+ console . info ( `Base ${ id } scanned successfully.` ) ;
291
+
292
+ // 监视目录
293
+ this . #docWatcher. watch ( path , {
294
+ filter,
295
+ upsert : ( path : string ) => {
296
+ this . #watcherTaskCache. set ( path , { docManagerId : id , type : "upsert" } ) ;
297
+ this . #doWatcherTask( ) ;
298
+ } ,
299
+ remove : ( path : string ) => {
300
+ this . #watcherTaskCache. set ( path , { docManagerId : id , type : "remove" } ) ;
301
+ this . #doWatcherTask( ) ;
302
+ } ,
303
+ } )
304
+ console . info ( `Base ${ id } directories are being watched.` ) ;
305
+ } )
306
+ )
307
+
308
+ // TODO 打印表格
309
+ console . info ( "DocManager initialized successfully." , result ) ;
310
+
307
311
console . info ( "DocBase started successfully." ) ;
308
312
} ;
309
313
314
+ // TODO 新安装插件立即扫描所有目录
310
315
/**
311
316
* 立即扫描所有目录
312
317
*/
313
- scanAllNow = async ( id : string ) => {
314
- console . info ( "Starting to scan all directories immediately..." ) ;
315
- await this . #scan( this . dirs ) ;
316
- console . info ( "All directories scanned immediately." ) ;
317
- } ;
318
+ // scanAllNow = async (id: string) => {
319
+ // console.info("Starting to scan all directories immediately...");
320
+ // await this.#scan(id, this.dirs);
321
+ // console.info("All directories scanned immediately.");
322
+ // };
323
+
324
+ // TODO 增加、删除、查询 知识库
318
325
319
326
/**
320
327
* 卸载文档加载器插件
@@ -463,7 +470,8 @@ export class DocBase {
463
470
knowledgeId : string ;
464
471
} ) => {
465
472
console . info ( `Searching for documents with query: ${ params . q } ` ) ;
466
- const results = await this . #docManager. search ( query , opt ) ;
473
+ const docManager = this . #docManagers. get ( params . knowledgeId )
474
+ const results = await docManager . search ( params ) ;
467
475
console . info ( `Search completed. Found ${ results . length } documents.` ) ;
468
476
return results ;
469
477
} ;
0 commit comments