From 24bc017e1f96cd7308d85bb065567f5b9ee38ec3 Mon Sep 17 00:00:00 2001 From: ymq Date: Fri, 7 Aug 2026 16:47:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=89=80=E6=9C=89id=E7=BB=9F=E4=B8=8032?= =?UTF-8?q?=E5=AD=97=E8=8A=82=20=E2=80=94=20init.py=E5=8E=BB=E6=8E=89[:16]?= =?UTF-8?q?,=20DSPY=E6=96=87=E4=BB=B6=E6=94=B9=E7=94=A8getID(32)=E5=8E=BBi?= =?UTF-8?q?mport=20uuid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag/init.py | 10 +++++----- wwwroot/knowledge_bases_list/create_kb.dspy | 3 +-- wwwroot/knowledge_bases_list/new_tree_item.dspy | 3 +-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/rag/init.py b/rag/init.py index 28a7d8a..d51a74b 100644 --- a/rag/init.py +++ b/rag/init.py @@ -322,7 +322,7 @@ async def doc_upload_handler(request, params_kw, *args, **kwargs): "message": "存储配额超限:机构已用 " + _fmt_bytes(used) + ",限额 " + _fmt_bytes(quota_limit) + ",本文件 " + _fmt_bytes(file_size)}, ensure_ascii=False) # Save file via FileStorage (layered dir layout, returns web path e.g. /191/193/197/97/xxx.txt) - doc_id = uuid.uuid4().hex[:16] + doc_id = uuid.uuid4().hex web_path = await env.save_file(file_data, file_name) file_type = _detect_file_type(file_name, "application/octet-stream") @@ -615,7 +615,7 @@ async def dir_create_handler(request, params_kw, *args, **kwargs): if not kb_id or not dir_name: return json.dumps({"error": "kb_id and dir_name required"}) async with get_sor_context(env, 'rag') as sor: - dir_id = uuid.uuid4().hex[:16] + dir_id = uuid.uuid4().hex 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())", @@ -685,7 +685,7 @@ async def tag_create_handler(request, params_kw, *args, **kwargs): if existing: return json.dumps({"status": "SUCCEEDED", "tag_id": existing[0].id, "name": name, "color": existing[0].color, "duplicate": True}, ensure_ascii=False) - tag_id = uuid.uuid4().hex[:16] + tag_id = uuid.uuid4().hex await sor.sqlExe( "INSERT INTO tags (id, kb_id, name, color, org_id, created_at) " "VALUES (${id}$, ${kb_id}$, ${name}$, ${color}$, ${org_id}$, NOW())", @@ -742,7 +742,7 @@ async def tag_assign_handler(request, params_kw, *args, **kwargs): if media_type not in ("document", "face", "voice"): return json.dumps({"error": "media_type must be document/face/voice"}) async with get_sor_context(env, 'rag') as sor: - mt_id = uuid.uuid4().hex[:16] + mt_id = uuid.uuid4().hex await sor.sqlExe( "INSERT INTO media_tags (id, kb_id, media_type, media_id, tag_id, created_at) " "VALUES (${id}$, ${kb_id}$, ${type}$, ${mid}$, ${tid}$, NOW())", @@ -897,7 +897,7 @@ async def tag_sync_handler(request, params_kw, *args, **kwargs): added = 0 for tid in wanted_ids: if tid not in current: - mt_id = uuid.uuid4().hex[:16] + mt_id = uuid.uuid4().hex await sor.sqlExe( "INSERT INTO media_tags (id, kb_id, media_type, media_id, tag_id, created_at) " "VALUES (${id}$, ${kb_id}$, ${type}$, ${mid}$, ${tid}$, NOW())", diff --git a/wwwroot/knowledge_bases_list/create_kb.dspy b/wwwroot/knowledge_bases_list/create_kb.dspy index 2a3cffa..be2e6a9 100644 --- a/wwwroot/knowledge_bases_list/create_kb.dspy +++ b/wwwroot/knowledge_bases_list/create_kb.dspy @@ -2,10 +2,9 @@ ns = params_kw.copy() db = DBPools() dbname = get_module_dbname('rag') async with db.sqlorContext(dbname) as sor: - import uuid env = request._run_ns userorgid = await env.get_userorgid() - kb_id = uuid.uuid4().hex[:12] + kb_id = getID(32) name = ns.get("name", "") desc = ns.get("description", "") await sor.sqlExe( diff --git a/wwwroot/knowledge_bases_list/new_tree_item.dspy b/wwwroot/knowledge_bases_list/new_tree_item.dspy index c56173d..e1de163 100644 --- a/wwwroot/knowledge_bases_list/new_tree_item.dspy +++ b/wwwroot/knowledge_bases_list/new_tree_item.dspy @@ -2,8 +2,7 @@ ns = params_kw.copy() db = DBPools() dbname = get_module_dbname('rag') async with db.sqlorContext(dbname) as sor: - import uuid - dir_id = uuid.uuid4().hex[:16] + dir_id = getID(32) name = ns.get("name", "") parent_id = ns.get("parentid", "") kb_id = ns.get("kb_id", "")