temp:临时备份,完成一半知识库管理模块

This commit is contained in:
PingChuan
2025-12-01 12:33:53 +08:00
parent 754ec2c7b5
commit 0c1b81cfb2
25 changed files with 3564 additions and 560 deletions
+26 -20
View File
@@ -54,27 +54,15 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
}
/**
* PATCH /api/dataset/datasets/:datasetId - 修改知识库详情
* PATCH /api/dataset/datasets/:datasetId - 修改知识库名称
*
* Dify API: PATCH /datasets/{dataset_id}
*
* 请求体示例:
* {
* "name": "知识库名称",
* "description": "描述",
* "indexing_technique": "high_quality",
* "permission": "only_me",
* "embedding_model_provider": "zhipuai",
* "embedding_model": "embedding-3",
* "retrieval_model": {
* "search_method": "semantic_search",
* "reranking_enable": false,
* "top_k": 2,
* "score_threshold_enabled": false
* }
* }
* 请求体: { "name": "新的知识库名称" }
*
* 注意:删除知识库功能不对外开放
* 注意:
* - 仅允许修改知识库名称,其他字段不开放修改
* - 删除知识库功能不对外开放
*/
export async function action({ request, params }: ActionFunctionArgs) {
try {
@@ -99,9 +87,27 @@ export async function action({ request, params }: ActionFunctionArgs) {
const method = request.method;
if (method === 'PATCH') {
// 修改知识库详情
const body = await request.json();
console.log('[API] Update Dataset:', { datasetId, body });
// 只允许修改 name 字段
if (!body.name || typeof body.name !== 'string') {
return new Response(
JSON.stringify({ error: '请提供有效的知识库名称 (name)' }),
{ status: 400, headers: { 'Content-Type': 'application/json' } }
);
}
// 只传递 name 字段,忽略其他字段
const allowedBody = { name: body.name.trim() };
if (allowedBody.name.length === 0) {
return new Response(
JSON.stringify({ error: '知识库名称不能为空' }),
{ status: 400, headers: { 'Content-Type': 'application/json' } }
);
}
console.log('[API] Update Dataset Name:', { datasetId, name: allowedBody.name });
const apiUrl = `${API_BASE_URL}/dify_dataset/datasets/${datasetId}`;
const response = await fetch(apiUrl, {
@@ -110,7 +116,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
'Content-Type': 'application/json',
'Authorization': `Bearer ${frontendJWT}`,
},
body: JSON.stringify(body),
body: JSON.stringify(allowedBody),
});
const data = await response.json();