sync update from LAN repo (source dhk-1 @ 3e87be55)

This commit is contained in:
gozeros committed 2026-10-21 15:06:08 +08:00
1 parent ab6068a7c1
commit 42f2a26fa8
1482 files changed
+227759 -9584

No files matched your search

@@ -44,6 +44,16 @@ async def export_assistant(app, base_id, job_id):
raise ValueError("该助手知识库尚无可导出的 Wiki 向量,请先从已向量化的普通知识库同步")
await asyncio.to_thread(temp.replace, path)
_write_export_manifest(job_id=job_id, mapping_id=scope, status="completed", phase="package_ready", counts=counts)
except asyncio.CancelledError:
_write_export_manifest(
job_id=job_id,
mapping_id=scope,
status="failed",
phase="interrupted",
counts=counts,
error="服务停止,数据包任务已中断,请重新发起",
)
raise
except Exception as exc:
_write_export_manifest(job_id=job_id, mapping_id=scope, status="failed", phase="failed", counts=counts, error=str(exc))
@@ -148,6 +158,27 @@ async def restore_package(app, mapping, job_id, path: Path):
await sync_to_global(app, mapping)
_write_export_manifest(job_id=job_id, mapping_id=scope, status="completed", phase="completed", counts=counts)
except asyncio.CancelledError:
if leased:
await asyncio.shield(
store.finish_sync(
mapping["id"],
owner=owner,
sync_id=job_id,
success=False,
remote_page_count=counts["wiki_page"],
error="服务停止,数据包导入已中断",
)
)
_write_export_manifest(
job_id=job_id,
mapping_id=scope,
status="failed",
phase="interrupted",
counts=counts,
error="服务停止,数据包导入已中断,请在全新空库中重新发起",
)
raise
except Exception as exc:
if leased:
await store.finish_sync(mapping["id"], owner=owner, sync_id=job_id, success=False, remote_page_count=counts["wiki_page"], error=str(exc))
@@ -167,11 +198,25 @@ async def upload_restore(request: Request, mapping_id: str, file: UploadFile = F
remote = await client.get_knowledge_base(mapping["weknora_id"])
if not (remote.get("indexing_strategy") or {}).get("wiki_enabled"):
raise HTTPException(422, "请先开启目标知识库的 Wiki")
existing = await client.list_wiki_pages(mapping["weknora_id"], page_size=1)
if existing.get("total"):
raise HTTPException(409, "请导入到新建的空 Wiki 知识库,避免覆盖已有页面")
job_id = str(uuid4())
scope = f"restore:{mapping_id}"
active_jobs = await asyncio.to_thread(_list_export_manifests, scope, limit=100)
if any(row.get("status") in {"queued", "running"} for row in active_jobs):
raise HTTPException(409, "当前知识库已有数据包导入任务,请等待任务完成")
existing_pages, existing_documents = await asyncio.gather(
client.list_wiki_pages(mapping["weknora_id"], page_size=1),
client.list_documents(mapping["weknora_id"], page_size=1),
)
if (
existing_pages.get("total")
or existing_pages.get("pages")
or existing_documents.get("total")
or existing_documents.get("items")
):
raise HTTPException(
409,
"请导入到没有原始资料和 Wiki 页面的全新空库,避免与模型解析结果混合",
)
job_id = str(uuid4())
row = _write_export_manifest(job_id=job_id, mapping_id=scope, status="queued", phase="uploading")
path = package_path(_package_root(), job_id)
try: