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 documentService from '../services/documentService.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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文档
|
||||
@@ -69,8 +77,9 @@ export async function uploadDocument(
|
||||
|
||||
// 上传文档(这里fileUrl暂时为空,实际应该上传到对象存储)
|
||||
console.log(`⚙️ 调用文档服务上传文件...`);
|
||||
const userId = getUserId(request);
|
||||
const document = await documentService.uploadDocument(
|
||||
MOCK_USER_ID,
|
||||
userId,
|
||||
kbId,
|
||||
file,
|
||||
filename,
|
||||
@@ -123,7 +132,8 @@ export async function getDocuments(
|
||||
try {
|
||||
const { kbId } = request.params;
|
||||
|
||||
const documents = await documentService.getDocuments(MOCK_USER_ID, kbId);
|
||||
const userId = getUserId(request);
|
||||
const documents = await documentService.getDocuments(userId, kbId);
|
||||
|
||||
return reply.send({
|
||||
success: true,
|
||||
@@ -160,7 +170,8 @@ export async function getDocumentById(
|
||||
try {
|
||||
const { id } = request.params;
|
||||
|
||||
const document = await documentService.getDocumentById(MOCK_USER_ID, id);
|
||||
const userId = getUserId(request);
|
||||
const document = await documentService.getDocumentById(userId, id);
|
||||
|
||||
return reply.send({
|
||||
success: true,
|
||||
@@ -197,7 +208,8 @@ export async function deleteDocument(
|
||||
try {
|
||||
const { id } = request.params;
|
||||
|
||||
await documentService.deleteDocument(MOCK_USER_ID, id);
|
||||
const userId = getUserId(request);
|
||||
await documentService.deleteDocument(userId, id);
|
||||
|
||||
return reply.send({
|
||||
success: true,
|
||||
@@ -234,7 +246,8 @@ export async function reprocessDocument(
|
||||
try {
|
||||
const { id } = request.params;
|
||||
|
||||
await documentService.reprocessDocument(MOCK_USER_ID, id);
|
||||
const userId = getUserId(request);
|
||||
await documentService.reprocessDocument(userId, id);
|
||||
|
||||
return reply.send({
|
||||
success: true,
|
||||
@@ -271,7 +284,8 @@ export async function getDocumentFullText(
|
||||
try {
|
||||
const { id } = request.params;
|
||||
|
||||
const document = await documentService.getDocumentById(MOCK_USER_ID, id);
|
||||
const userId = getUserId(request);
|
||||
const document = await documentService.getDocumentById(userId, id);
|
||||
|
||||
// 返回完整的文档信息
|
||||
return reply.send({
|
||||
|
||||
Reference in New Issue
Block a user