fix(pkb): fix create KB and upload issues - remove simulated upload, fix department mapping, add upload modal
Fixed issues: - Remove simulateUpload function from DashboardPage Step 3 - Map department to description field when creating KB - Add upload modal in WorkspacePage knowledge assets tab - Fix DocumentUpload import path (../../stores to ../stores) Known issue: Dify API validation error during document upload (file uploaded but DB record failed, needs investigation) Testing: KB creation works, upload dialog opens correctly
This commit is contained in:
@@ -1,8 +1,16 @@
|
||||
import type { FastifyRequest, FastifyReply } from 'fastify';
|
||||
import * as knowledgeBaseService from '../services/knowledgeBaseService.js';
|
||||
|
||||
// Mock用户ID(实际应从JWT token中获取)
|
||||
const MOCK_USER_ID = 'user-mock-001';
|
||||
/**
|
||||
* 获取用户ID(从JWT Token中获取)
|
||||
*/
|
||||
function getUserId(request: FastifyRequest): string {
|
||||
const userId = (request as any).user?.userId;
|
||||
if (!userId) {
|
||||
throw new Error('User not authenticated');
|
||||
}
|
||||
return userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建知识库
|
||||
@@ -26,8 +34,9 @@ export async function createKnowledgeBase(
|
||||
});
|
||||
}
|
||||
|
||||
const userId = getUserId(request);
|
||||
const knowledgeBase = await knowledgeBaseService.createKnowledgeBase(
|
||||
MOCK_USER_ID,
|
||||
userId,
|
||||
name,
|
||||
description
|
||||
);
|
||||
@@ -49,12 +58,13 @@ export async function createKnowledgeBase(
|
||||
* 获取知识库列表
|
||||
*/
|
||||
export async function getKnowledgeBases(
|
||||
_request: FastifyRequest,
|
||||
request: FastifyRequest,
|
||||
reply: FastifyReply
|
||||
) {
|
||||
try {
|
||||
const userId = getUserId(request);
|
||||
const knowledgeBases = await knowledgeBaseService.getKnowledgeBases(
|
||||
MOCK_USER_ID
|
||||
userId
|
||||
);
|
||||
|
||||
return reply.send({
|
||||
@@ -84,8 +94,9 @@ export async function getKnowledgeBaseById(
|
||||
try {
|
||||
const { id } = request.params;
|
||||
|
||||
const userId = getUserId(request);
|
||||
const knowledgeBase = await knowledgeBaseService.getKnowledgeBaseById(
|
||||
MOCK_USER_ID,
|
||||
userId,
|
||||
id
|
||||
);
|
||||
|
||||
@@ -129,8 +140,9 @@ export async function updateKnowledgeBase(
|
||||
const { id } = request.params;
|
||||
const updateData = request.body;
|
||||
|
||||
const userId = getUserId(request);
|
||||
const knowledgeBase = await knowledgeBaseService.updateKnowledgeBase(
|
||||
MOCK_USER_ID,
|
||||
userId,
|
||||
id,
|
||||
updateData
|
||||
);
|
||||
@@ -170,7 +182,8 @@ export async function deleteKnowledgeBase(
|
||||
try {
|
||||
const { id } = request.params;
|
||||
|
||||
await knowledgeBaseService.deleteKnowledgeBase(MOCK_USER_ID, id);
|
||||
const userId = getUserId(request);
|
||||
await knowledgeBaseService.deleteKnowledgeBase(userId, id);
|
||||
|
||||
return reply.send({
|
||||
success: true,
|
||||
@@ -221,8 +234,9 @@ export async function searchKnowledgeBase(
|
||||
|
||||
const topK = top_k ? parseInt(top_k, 10) : 15; // Phase 1优化:默认从3增加到15
|
||||
|
||||
const userId = getUserId(request);
|
||||
const results = await knowledgeBaseService.searchKnowledgeBase(
|
||||
MOCK_USER_ID,
|
||||
userId,
|
||||
id,
|
||||
query,
|
||||
topK
|
||||
@@ -263,8 +277,9 @@ export async function getKnowledgeBaseStats(
|
||||
try {
|
||||
const { id } = request.params;
|
||||
|
||||
const userId = getUserId(request);
|
||||
const stats = await knowledgeBaseService.getKnowledgeBaseStats(
|
||||
MOCK_USER_ID,
|
||||
userId,
|
||||
id
|
||||
);
|
||||
|
||||
@@ -311,8 +326,9 @@ export async function getDocumentSelection(
|
||||
const maxFiles = max_files ? parseInt(max_files, 10) : undefined;
|
||||
const maxTokens = max_tokens ? parseInt(max_tokens, 10) : undefined;
|
||||
|
||||
const userId = getUserId(request);
|
||||
const selection = await knowledgeBaseService.getDocumentSelection(
|
||||
MOCK_USER_ID,
|
||||
userId,
|
||||
id,
|
||||
maxFiles,
|
||||
maxTokens
|
||||
|
||||
Reference in New Issue
Block a user