feat: update project configuration and enhance project manager functionality
This commit is contained in:
@@ -6,6 +6,7 @@ import { useKey, useContextKey } from '@kevisual/context';
|
||||
export const app = useContextKey<App>('app', new App());
|
||||
export const manager = useContextKey<ProjectManager>('project-manager', new ProjectManager({
|
||||
meiliSearchOptions: {
|
||||
apiHost: 'http://localhost:7700',
|
||||
apiKey: useKey('CNB_TOKEN')
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -8,8 +8,10 @@ import './routes/auth';
|
||||
import './routes/project';
|
||||
import './routes/search';
|
||||
import './routes/file';
|
||||
|
||||
import { manager } from './app';
|
||||
|
||||
if (import.meta.main) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
await manager.init();
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ProjectManagerInterface } from "./user-interface";
|
||||
import { ProjectSearch } from "./project-search/index";
|
||||
import { ProjectStore } from "./project-store";
|
||||
import { ProjectStore, ProjectDoc } from "./project-store";
|
||||
import { ProjectListener } from "./project-listener/listener";
|
||||
import { EventEmitter } from "eventemitter3";
|
||||
import fs from 'node:fs';
|
||||
@@ -17,7 +17,15 @@ type Project = {
|
||||
};
|
||||
|
||||
export type ProjectInput = Omit<Project, "listener">;
|
||||
export type ProjectInfo = Omit<Project, "listener"> & { status: "active" | "inactive" };
|
||||
export type ProjectInfo = Omit<Project, "listener"> & {
|
||||
status: "active" | "inactive";
|
||||
id?: string;
|
||||
title?: string;
|
||||
tags?: string[];
|
||||
summary?: string;
|
||||
description?: string;
|
||||
link?: string;
|
||||
};
|
||||
|
||||
type ProjectManagerOpt = {
|
||||
meiliSearchOptions?: {
|
||||
@@ -131,16 +139,23 @@ export class ProjectManager implements ProjectManagerInterface {
|
||||
console.log(`[ProjectManager] stopped: ${projectPath}`);
|
||||
}
|
||||
|
||||
getProjectInfo(project: Project): ProjectInfo {
|
||||
async getProjectInfo(project: Project): Promise<ProjectInfo> {
|
||||
const { listener, ...info } = project;
|
||||
const storeDoc: ProjectDoc | null = await this.projectStore.getProject(info.path).catch(() => null);
|
||||
return {
|
||||
...info,
|
||||
status: listener.isWatching ? "active" : "inactive",
|
||||
id: storeDoc?.id,
|
||||
title: storeDoc?.title,
|
||||
tags: storeDoc?.tags,
|
||||
summary: storeDoc?.summary,
|
||||
description: storeDoc?.description,
|
||||
link: storeDoc?.link,
|
||||
};
|
||||
}
|
||||
|
||||
listProjects(): ProjectInfo[] {
|
||||
return Array.from(this.projects.values()).map(p => this.getProjectInfo(p));
|
||||
async listProjects(): Promise<ProjectInfo[]> {
|
||||
return Promise.all(Array.from(this.projects.values()).map(p => this.getProjectInfo(p)));
|
||||
}
|
||||
|
||||
async getFile(filepath: string): Promise<{ filepath: string, content: string; type: string } | null> {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export interface ProjectManagerInterface {
|
||||
removeProject(path: string): void;
|
||||
getProject(path: string): any;
|
||||
listProjects(): any[];
|
||||
listProjects(): any[] | Promise<any[]>;
|
||||
addProject(project: any): void;
|
||||
}
|
||||
14
src/remote.ts
Normal file
14
src/remote.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { app, manager } from './index'
|
||||
import { RemoteApp } from '@kevisual/remote-app'
|
||||
|
||||
app.createRouteList()
|
||||
const remote = new RemoteApp({
|
||||
app,
|
||||
id: 'project-search',
|
||||
username: 'root'
|
||||
});
|
||||
const isConnect = await remote.isConnect();
|
||||
if (isConnect) {
|
||||
console.log('Remote app connected successfully', isConnect);
|
||||
remote.listenProxy();
|
||||
}
|
||||
@@ -104,7 +104,7 @@ app
|
||||
ctx.throw(404, '项目不存在');
|
||||
return;
|
||||
}
|
||||
ctx.body = { success: true, data: manager.getProjectInfo(project) };
|
||||
ctx.body = { data: await manager.getProjectInfo(project) };
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
@@ -119,7 +119,7 @@ app
|
||||
middleware: ['auth-admin'],
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
ctx.body = { list: manager.listProjects() };
|
||||
ctx.body = { list: await manager.listProjects() };
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user