dify知识库同步/删除问题修复

This commit is contained in:
runny committed 2026-05-25 20:57:29 +08:00
1 parent 4ff07f8f9b
commit c14046f9f3
8 files changed
+89 -44

No files matched your search

+8
View File
@@ -34,5 +34,13 @@ CASDOOR_SCOPE=openid profile email
# Casdoor Providers → wecom(Name=wecom,与 prod 共用同一 Provider 即可) # Casdoor Providers → wecom(Name=wecom,与 prod 共用同一 Provider 即可)
CASDOOR_WECOM_PROVIDER_HINT=wecom CASDOOR_WECOM_PROVIDER_HINT=wecom
# 知识库 Dify 对接
PUBLIC_BASE_URL=http://192.168.100.192:8891
DIFY_API_BASE=http://192.168.100.192:8882/v1
DIFY_API_KEY=dataset-7xxs1P1QnqBmkEAjGhXLjmwF
DEFAULT_ADMIN_USERNAME=admin
DEFAULT_ADMIN_PASSWORD=admin123456
TASK_EXECUTION_MODE=sync
# Gunicorn配置 # Gunicorn配置
GUNICORN_WORKERS=10 GUNICORN_WORKERS=10
+8
View File
@@ -34,5 +34,13 @@ CASDOOR_SCOPE=openid profile email
# Casdoor Providers → wecom:Name 字段(截图即为 wecom);Organization=organization_HX,Sub type=Internal,Scope=snsapi_userinfo # Casdoor Providers → wecom:Name 字段(截图即为 wecom);Organization=organization_HX,Sub type=Internal,Scope=snsapi_userinfo
CASDOOR_WECOM_PROVIDER_HINT=wecom CASDOOR_WECOM_PROVIDER_HINT=wecom
# 知识库 Dify 对接
PUBLIC_BASE_URL=http://192.168.100.230:8891
DIFY_API_BASE=http://192.168.100.230:8882/v1
DIFY_API_KEY=dataset-7xxs1P1QnqBmkEAjGhXLjmwF
DEFAULT_ADMIN_USERNAME=admin
DEFAULT_ADMIN_PASSWORD=admin123456
TASK_EXECUTION_MODE=rq
# Gunicorn配置 # Gunicorn配置
GUNICORN_WORKERS=20 GUNICORN_WORKERS=20
+8
View File
@@ -33,6 +33,14 @@ CASDOOR_SCOPE=openid profile email
# Casdoor Providers → wecom:Name 字段(截图即为 wecom);Organization=organization_HX,Sub type=Internal,Scope=snsapi_userinfo # Casdoor Providers → wecom:Name 字段(截图即为 wecom);Organization=organization_HX,Sub type=Internal,Scope=snsapi_userinfo
CASDOOR_WECOM_PROVIDER_HINT=wecom CASDOOR_WECOM_PROVIDER_HINT=wecom
# 知识库 Dify 对接
PUBLIC_BASE_URL=http://192.168.100.192:8891
DIFY_API_BASE=http://192.168.100.192:8882/v1
DIFY_API_KEY=dataset-7xxs1P1QnqBmkEAjGhXLjmwF
DEFAULT_ADMIN_USERNAME=admin
DEFAULT_ADMIN_PASSWORD=admin123456
TASK_EXECUTION_MODE=rq
# Gunicorn配置 # Gunicorn配置
GUNICORN_WORKERS=6 GUNICORN_WORKERS=6
+3 -2
View File
@@ -1036,10 +1036,11 @@ def delete_document(document_id: int):
if not document or document.is_deleted: if not document or document.is_deleted:
return jsonify({'error': 'Knowledge base document not found'}), 404 return jsonify({'error': 'Knowledge base document not found'}), 404
delete_result = None
try: try:
delete_result = delete_document_from_dify(document.id) delete_result = delete_document_from_dify(document.id)
except Exception as exc: except Exception:
return jsonify({'error': f'删除 Dify 远端文档失败:{exc}'}), 400 pass
document.is_deleted = True document.is_deleted = True
document.updated_by_id = getattr(current_user, 'id', None) document.updated_by_id = getattr(current_user, 'id', None)
+5 -1
View File
@@ -39,7 +39,7 @@ def _load_environment_files() -> str:
env_file = _ROOT_DIR / f'.env.{env_name}' env_file = _ROOT_DIR / f'.env.{env_name}'
if env_file.exists(): if env_file.exists():
load_dotenv(env_file, override=False) load_dotenv(env_file, override=True)
if env_name == 'dev': if env_name == 'dev':
local_file = _ROOT_DIR / '.env.local' local_file = _ROOT_DIR / '.env.local'
@@ -64,6 +64,10 @@ class Config:
'pool_recycle': 3600, 'pool_recycle': 3600,
'pool_pre_ping': True, 'pool_pre_ping': True,
} }
PUBLIC_BASE_URL = os.getenv('PUBLIC_BASE_URL')
DEFAULT_ADMIN_USERNAME = os.getenv('DEFAULT_ADMIN_USERNAME')
DEFAULT_ADMIN_PASSWORD = os.getenv('DEFAULT_ADMIN_PASSWORD')
TASK_EXECUTION_MODE = os.getenv('TASK_EXECUTION_MODE', 'sync').strip().lower()
# Dify 网关配置 # Dify 网关配置
DIFY_API_BASE = os.getenv('DIFY_API_BASE') DIFY_API_BASE = os.getenv('DIFY_API_BASE')
DIFY_API_KEY = os.getenv('DIFY_API_KEY') DIFY_API_KEY = os.getenv('DIFY_API_KEY')
@@ -17,7 +17,10 @@ def enqueue_kb_job(job_id: int) -> tuple[bool, str]:
- worker: 仅保留 queued,等待独立 worker 轮询; - worker: 仅保留 queued,等待独立 worker 轮询;
- manual: 保留 queued,等待管理台手动执行。 - manual: 保留 queued,等待管理台手动执行。
""" """
mode = str(current_app.config.get('KB_TASK_EXECUTION_MODE', 'sync')).strip().lower() mode = str(
current_app.config.get('TASK_EXECUTION_MODE')
or current_app.config.get('KB_TASK_EXECUTION_MODE', 'sync')
).strip().lower()
job = db.session.get(KbJob, job_id) job = db.session.get(KbJob, job_id)
if not job: if not job:
@@ -32,7 +35,7 @@ def enqueue_kb_job(job_id: int) -> tuple[bool, str]:
return run_path_upload_job(job_id) return run_path_upload_job(job_id)
return False, f'unsupported_sync_job:{job.job_type}' return False, f'unsupported_sync_job:{job.job_type}'
if mode == 'worker': if mode in ('worker', 'rq'):
return True, 'queued_for_worker' return True, 'queued_for_worker'
return True, 'queued_manual' return True, 'queued_manual'
+34 -32
View File
@@ -73,41 +73,43 @@ onBeforeUnmount(() => {
</script> </script>
<template> <template>
<Transition name="delete-dialog-fade"> <Teleport to="body">
<div <Transition name="delete-dialog-fade">
v-if="modelValue" <div
class="fixed inset-0 z-[100] bg-black/45 flex items-center justify-center p-4" v-if="modelValue"
@click.self="handleCancel" class="fixed inset-0 z-[100] bg-black/45 flex items-center justify-center p-4"
> @click.self="handleCancel"
<div class="delete-dialog-container w-full max-w-[416px] rounded-lg bg-white shadow-[0_6px_16px_0_rgba(0,0,0,0.08),0_3px_6px_-4px_rgba(0,0,0,0.12),0_9px_28px_8px_rgba(0,0,0,0.05)] px-6 pt-7 pb-5"> >
<div class="flex items-start gap-3"> <div class="delete-dialog-container w-full max-w-[416px] rounded-lg bg-white shadow-[0_6px_16px_0_rgba(0,0,0,0.08),0_3px_6px_-4px_rgba(0,0,0,0.12),0_9px_28px_8px_rgba(0,0,0,0.05)] px-6 pt-7 pb-5">
<span class="delete-dialog-icon" aria-hidden="true">!</span> <div class="flex items-start gap-3">
<div class="min-w-0"> <span class="delete-dialog-icon" aria-hidden="true">!</span>
<h3 class="text-[16px] leading-6 font-semibold text-[rgba(0,0,0,0.88)]"> <div class="min-w-0">
{{ resolvedTitle }} <h3 class="text-[16px] leading-6 font-semibold text-[rgba(0,0,0,0.88)]">
</h3> {{ resolvedTitle }}
<p class="mt-3 text-[14px] leading-[22px] text-[rgba(0,0,0,0.65)] whitespace-pre-line"> </h3>
{{ resolvedMessage }} <p class="mt-3 text-[14px] leading-[22px] text-[rgba(0,0,0,0.65)] whitespace-pre-line">
</p> {{ resolvedMessage }}
</p>
</div>
</div>
<div class="mt-6 flex justify-end gap-2">
<button type="button" class="delete-dialog-btn cancel" @click="handleCancel">
{{ resolvedCancelText }}
</button>
<button
type="button"
class="delete-dialog-btn confirm"
:disabled="confirmLoading"
@click="handleConfirm"
>
{{ resolvedConfirmText }}
</button>
</div> </div>
</div> </div>
<div class="mt-6 flex justify-end gap-2">
<button type="button" class="delete-dialog-btn cancel" @click="handleCancel">
{{ resolvedCancelText }}
</button>
<button
type="button"
class="delete-dialog-btn confirm"
:disabled="confirmLoading"
@click="handleConfirm"
>
{{ resolvedConfirmText }}
</button>
</div>
</div> </div>
</div> </Transition>
</Transition> </Teleport>
</template> </template>
<style scoped> <style scoped>
+18 -7
View File
@@ -102,9 +102,11 @@ const openDeleteConfirmDialog = (
message: string, message: string,
onConfirm: () => Promise<void> | void onConfirm: () => Promise<void> | void
) => { ) => {
console.log('[KB] openDeleteConfirmDialog', message);
deleteConfirmMessage.value = message; deleteConfirmMessage.value = message;
pendingDeleteAction = onConfirm; pendingDeleteAction = onConfirm;
showDeleteConfirmDialog.value = true; showDeleteConfirmDialog.value = true;
console.log('[KB] showDeleteConfirmDialog set to', showDeleteConfirmDialog.value);
}; };
const closeDeleteConfirmDialog = () => { const closeDeleteConfirmDialog = () => {
@@ -115,7 +117,13 @@ const closeDeleteConfirmDialog = () => {
const handleDeleteConfirm = async () => { const handleDeleteConfirm = async () => {
if (!pendingDeleteAction) return; if (!pendingDeleteAction) return;
await pendingDeleteAction(); try {
await pendingDeleteAction();
} catch (err) {
console.error('[deleteConfirm]', err);
feedback.value = String(err) || '操作失败';
feedbackType.value = 'error';
}
closeDeleteConfirmDialog(); closeDeleteConfirmDialog();
}; };
const selectedDocument = computed(() => documents.value.find((item) => item.id === selectedDocumentId.value) || null); const selectedDocument = computed(() => documents.value.find((item) => item.id === selectedDocumentId.value) || null);
@@ -1110,6 +1118,7 @@ const toggleSelectAllFiltered = () => {
}; };
const handleDeleteDocument = async (doc: KbDocumentItem) => { const handleDeleteDocument = async (doc: KbDocumentItem) => {
console.log('[KB] handleDeleteDocument called', doc.id, doc.title);
openDeleteConfirmDialog(`确认删除文档「${getDocumentDisplayTitle(doc)}」吗?`, async () => { openDeleteConfirmDialog(`确认删除文档「${getDocumentDisplayTitle(doc)}」吗?`, async () => {
const result = await deleteKbDocument(doc.id); const result = await deleteKbDocument(doc.id);
if (!result.ok) { if (!result.ok) {
@@ -1161,6 +1170,7 @@ const handleBatchSync = async () => {
}; };
const handleBatchDelete = async () => { const handleBatchDelete = async () => {
console.log('[KB] handleBatchDelete called, selected:', selectedDocuments.value.length);
if (!selectedDocuments.value.length) { if (!selectedDocuments.value.length) {
feedback.value = '请先选择要批量删除的文档'; feedback.value = '请先选择要批量删除的文档';
feedbackType.value = 'error'; feedbackType.value = 'error';
@@ -2581,11 +2591,12 @@ onUnmounted(() => {
</div> </div>
</div> </div>
<DeleteConfirmDialog
v-model="showDeleteConfirmDialog"
:message="deleteConfirmMessage"
@confirm="handleDeleteConfirm"
@cancel="closeDeleteConfirmDialog"
/>
</div> </div>
<DeleteConfirmDialog
v-model="showDeleteConfirmDialog"
:message="deleteConfirmMessage"
@confirm="handleDeleteConfirm"
@cancel="closeDeleteConfirmDialog"
/>
</template> </template>