feat(admin): Implement System Knowledge Base management module
Features:
- Backend: SystemKbService with full CRUD (knowledge bases + documents)
- Backend: 8 RESTful API endpoints (list/detail/create/update/delete/upload/download)
- Backend: OSS storage integration (system/knowledge-bases/{kbId}/{docId})
- Backend: RAG engine integration (document parsing, chunking, vectorization)
- Frontend: SystemKbListPage with card-based layout
- Frontend: SystemKbDetailPage with document management table
- Frontend: Master-Detail UX pattern for better user experience
- Document upload (single/batch), download (preserving original filename), delete
Technical:
- Database migration for system_knowledge_bases and system_kb_documents tables
- OSSAdapter.getSignedUrl with Content-Disposition for original filename
- Reuse RAG engine from common/rag for document processing
Tested: Local environment verified, all features working
This commit is contained in:
75
backend/src/modules/admin/system-kb/systemKbRoutes.ts
Normal file
75
backend/src/modules/admin/system-kb/systemKbRoutes.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* 系统知识库路由
|
||||
*
|
||||
* 路由前缀:/api/v1/admin/system-kb
|
||||
*/
|
||||
|
||||
import { FastifyInstance } from 'fastify';
|
||||
import {
|
||||
listKnowledgeBases,
|
||||
getKnowledgeBase,
|
||||
createKnowledgeBase,
|
||||
updateKnowledgeBase,
|
||||
deleteKnowledgeBase,
|
||||
listDocuments,
|
||||
uploadDocument,
|
||||
deleteDocument,
|
||||
downloadDocument,
|
||||
} from './systemKbController.js';
|
||||
import { authenticate, requireRoles } from '../../../common/auth/auth.middleware.js';
|
||||
|
||||
export async function systemKbRoutes(fastify: FastifyInstance) {
|
||||
// 所有路由都需要认证 + SUPER_ADMIN 或 ADMIN 角色
|
||||
const preHandler = [authenticate, requireRoles('SUPER_ADMIN', 'ADMIN')];
|
||||
|
||||
// ==================== 知识库 CRUD ====================
|
||||
|
||||
// 获取知识库列表
|
||||
fastify.get('/', {
|
||||
preHandler,
|
||||
}, listKnowledgeBases as any);
|
||||
|
||||
// 创建知识库
|
||||
fastify.post('/', {
|
||||
preHandler,
|
||||
}, createKnowledgeBase as any);
|
||||
|
||||
// 获取知识库详情
|
||||
fastify.get('/:id', {
|
||||
preHandler,
|
||||
}, getKnowledgeBase as any);
|
||||
|
||||
// 更新知识库
|
||||
fastify.patch('/:id', {
|
||||
preHandler,
|
||||
}, updateKnowledgeBase as any);
|
||||
|
||||
// 删除知识库
|
||||
fastify.delete('/:id', {
|
||||
preHandler,
|
||||
}, deleteKnowledgeBase as any);
|
||||
|
||||
// ==================== 文档管理 ====================
|
||||
|
||||
// 获取文档列表
|
||||
fastify.get('/:id/documents', {
|
||||
preHandler,
|
||||
}, listDocuments as any);
|
||||
|
||||
// 上传文档
|
||||
fastify.post('/:id/documents', {
|
||||
preHandler,
|
||||
}, uploadDocument as any);
|
||||
|
||||
// 删除文档
|
||||
fastify.delete('/:id/documents/:docId', {
|
||||
preHandler,
|
||||
}, deleteDocument as any);
|
||||
|
||||
// 下载文档(获取签名 URL)
|
||||
fastify.get('/:id/documents/:docId/download', {
|
||||
preHandler,
|
||||
}, downloadDocument as any);
|
||||
}
|
||||
|
||||
export default systemKbRoutes;
|
||||
Reference in New Issue
Block a user