原始文件气泡映射错误 + 多版本下载错版本

This commit is contained in:
runny committed 2026-06-02 21:07:04 +08:00
1 parent f877f61efd
commit 854bc8e4db
7 files changed
+203 -80

No files matched your search

@@ -177,6 +177,7 @@ def sync_document_version_to_dify(document_version_id: int, synced_by_id: int |
remote_document_id = None
remote_document_name = None
upload_name = version.source_file_name or document.title
if existing_record and existing_record.dataset_id == dataset_id and existing_record.sync_hash == sync_hash:
try:
payload = service.get_document(
@@ -184,23 +185,23 @@ def sync_document_version_to_dify(document_version_id: int, synced_by_id: int |
document_id=existing_record.remote_document_id,
)
remote_document_id = payload.get('id') or existing_record.remote_document_id
remote_document_name = payload.get('name') or existing_record.remote_document_name or document.title
remote_document_name = payload.get('name') or existing_record.remote_document_name or upload_name
except KbDifySyncError as exc:
if not _is_remote_document_missing(str(exc)):
raise
payload = service.create_document_by_text(
dataset_id=dataset_id,
name=document.title,
name=upload_name,
text=text,
)
remote_document_id = payload.get('document', {}).get('id') or payload.get('id')
remote_document_name = payload.get('document', {}).get('name') or document.title
remote_document_name = payload.get('document', {}).get('name') or upload_name
elif existing_record and existing_record.dataset_id == dataset_id:
try:
payload = service.update_document_by_text(
dataset_id=dataset_id,
document_id=existing_record.remote_document_id,
name=document.title,
name=upload_name,
text=text,
)
except KbDifySyncError as exc:
@@ -208,19 +209,19 @@ def sync_document_version_to_dify(document_version_id: int, synced_by_id: int |
raise
payload = service.create_document_by_text(
dataset_id=dataset_id,
name=document.title,
name=upload_name,
text=text,
)
remote_document_id = payload.get('document', {}).get('id') or payload.get('id') or existing_record.remote_document_id
remote_document_name = payload.get('document', {}).get('name') or document.title
remote_document_name = payload.get('document', {}).get('name') or upload_name
else:
payload = service.create_document_by_text(
dataset_id=dataset_id,
name=document.title,
name=upload_name,
text=text,
)
remote_document_id = payload.get('document', {}).get('id') or payload.get('id')
remote_document_name = payload.get('document', {}).get('name') or document.title
remote_document_name = payload.get('document', {}).get('name') or upload_name
if not remote_document_id:
raise KbDifySyncError('Dify 未返回远端文档 ID')