45 lines
1.7 KiB
Plaintext
45 lines
1.7 KiB
Plaintext
action = params_kw.get("action", "")
|
|
kb_id = params_kw.get("kb_id", "")
|
|
env = request._run_ns
|
|
|
|
if action == "create_dir":
|
|
dir_name = params_kw.get("dir_name", "")
|
|
parent_id = params_kw.get("parent_id", "")
|
|
if dir_name:
|
|
async with get_sor_context(env, 'rag') as sor:
|
|
dir_id = "dir_" + str(abs(hash(dir_name + parent_id)))[:12]
|
|
await sor.sqlExe(
|
|
"INSERT INTO document_chunks (id, doc_id, kb_id, chunk_index, chunk_type, content, description, created_at) "
|
|
"VALUES (${id}$, '', ${kb_id}$, 0, 'directory', ${name}$, ${parent}$, NOW())",
|
|
{"id": dir_id, "kb_id": kb_id, "name": dir_name, "parent": parent_id})
|
|
|
|
elif action == "delete_item":
|
|
item_id = params_kw.get("item_id", "")
|
|
if item_id:
|
|
async with get_sor_context(env, 'rag') as sor:
|
|
await sor.sqlExe("DELETE FROM document_chunks WHERE id=${id}$", {"id": item_id})
|
|
|
|
# Return refreshed folder content widget
|
|
folder_id = params_kw.get("folder_id", "")
|
|
folder_label = params_kw.get("folder_label", "")
|
|
folder_label = folder_label or dir_name or "全部文件"
|
|
|
|
result = {
|
|
"widgettype": "VBox",
|
|
"options": {"spacing": "12px"},
|
|
"subwidgets": [
|
|
{
|
|
"widgettype": "HBox",
|
|
"options": {"spacing": "4px"},
|
|
"subwidgets": [
|
|
{"widgettype": "Text", "options": {"text": "📂 " + str(folder_label), "cfontsize": 16, "fontWeight": "bold", "color": "#333"}},
|
|
{"widgettype": "Text", "options": {"text": "操作成功", "cfontsize": 12, "color": "#50b86c"}}
|
|
]
|
|
},
|
|
{
|
|
"widgettype": "Text",
|
|
"options": {"text": "操作已完成,请刷新目录树", "color": "#888", "cfontsize": 13}
|
|
}
|
|
]
|
|
}
|