dify知识库同步/删除问题修复
This commit is contained in:
1 parent
4ff07f8f9b
commit
c14046f9f3
8 files changed
+89
-44
No files matched your search
@@ -34,5 +34,13 @@ CASDOOR_SCOPE=openid profile email
|
||||
# Casdoor Providers → wecom(Name=wecom,与 prod 共用同一 Provider 即可)
|
||||
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_WORKERS=10
|
||||
@@ -34,5 +34,13 @@ CASDOOR_SCOPE=openid profile email
|
||||
# Casdoor Providers → wecom:Name 字段(截图即为 wecom);Organization=organization_HX,Sub type=Internal,Scope=snsapi_userinfo
|
||||
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_WORKERS=20
|
||||
@@ -33,6 +33,14 @@ CASDOOR_SCOPE=openid profile email
|
||||
# Casdoor Providers → wecom:Name 字段(截图即为 wecom);Organization=organization_HX,Sub type=Internal,Scope=snsapi_userinfo
|
||||
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_WORKERS=6
|
||||
|
||||
|
||||
@@ -1036,10 +1036,11 @@ def delete_document(document_id: int):
|
||||
if not document or document.is_deleted:
|
||||
return jsonify({'error': 'Knowledge base document not found'}), 404
|
||||
|
||||
delete_result = None
|
||||
try:
|
||||
delete_result = delete_document_from_dify(document.id)
|
||||
except Exception as exc:
|
||||
return jsonify({'error': f'删除 Dify 远端文档失败:{exc}'}), 400
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
document.is_deleted = True
|
||||
document.updated_by_id = getattr(current_user, 'id', None)
|
||||
|
||||
@@ -39,7 +39,7 @@ def _load_environment_files() -> str:
|
||||
|
||||
env_file = _ROOT_DIR / f'.env.{env_name}'
|
||||
if env_file.exists():
|
||||
load_dotenv(env_file, override=False)
|
||||
load_dotenv(env_file, override=True)
|
||||
|
||||
if env_name == 'dev':
|
||||
local_file = _ROOT_DIR / '.env.local'
|
||||
@@ -64,6 +64,10 @@ class Config:
|
||||
'pool_recycle': 3600,
|
||||
'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_API_BASE = os.getenv('DIFY_API_BASE')
|
||||
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 轮询;
|
||||
- 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)
|
||||
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 False, f'unsupported_sync_job:{job.job_type}'
|
||||
|
||||
if mode == 'worker':
|
||||
if mode in ('worker', 'rq'):
|
||||
return True, 'queued_for_worker'
|
||||
|
||||
return True, 'queued_manual'
|
||||
|
||||
@@ -73,41 +73,43 @@ onBeforeUnmount(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Transition name="delete-dialog-fade">
|
||||
<div
|
||||
v-if="modelValue"
|
||||
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">
|
||||
<span class="delete-dialog-icon" aria-hidden="true">!</span>
|
||||
<div class="min-w-0">
|
||||
<h3 class="text-[16px] leading-6 font-semibold text-[rgba(0,0,0,0.88)]">
|
||||
{{ resolvedTitle }}
|
||||
</h3>
|
||||
<p class="mt-3 text-[14px] leading-[22px] text-[rgba(0,0,0,0.65)] whitespace-pre-line">
|
||||
{{ resolvedMessage }}
|
||||
</p>
|
||||
<Teleport to="body">
|
||||
<Transition name="delete-dialog-fade">
|
||||
<div
|
||||
v-if="modelValue"
|
||||
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">
|
||||
<span class="delete-dialog-icon" aria-hidden="true">!</span>
|
||||
<div class="min-w-0">
|
||||
<h3 class="text-[16px] leading-6 font-semibold text-[rgba(0,0,0,0.88)]">
|
||||
{{ resolvedTitle }}
|
||||
</h3>
|
||||
<p class="mt-3 text-[14px] leading-[22px] text-[rgba(0,0,0,0.65)] whitespace-pre-line">
|
||||
{{ 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 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>
|
||||
</Transition>
|
||||
</Transition>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@@ -102,9 +102,11 @@ const openDeleteConfirmDialog = (
|
||||
message: string,
|
||||
onConfirm: () => Promise<void> | void
|
||||
) => {
|
||||
console.log('[KB] openDeleteConfirmDialog', message);
|
||||
deleteConfirmMessage.value = message;
|
||||
pendingDeleteAction = onConfirm;
|
||||
showDeleteConfirmDialog.value = true;
|
||||
console.log('[KB] showDeleteConfirmDialog set to', showDeleteConfirmDialog.value);
|
||||
};
|
||||
|
||||
const closeDeleteConfirmDialog = () => {
|
||||
@@ -115,7 +117,13 @@ const closeDeleteConfirmDialog = () => {
|
||||
|
||||
const handleDeleteConfirm = async () => {
|
||||
if (!pendingDeleteAction) return;
|
||||
await pendingDeleteAction();
|
||||
try {
|
||||
await pendingDeleteAction();
|
||||
} catch (err) {
|
||||
console.error('[deleteConfirm]', err);
|
||||
feedback.value = String(err) || '操作失败';
|
||||
feedbackType.value = 'error';
|
||||
}
|
||||
closeDeleteConfirmDialog();
|
||||
};
|
||||
const selectedDocument = computed(() => documents.value.find((item) => item.id === selectedDocumentId.value) || null);
|
||||
@@ -1110,6 +1118,7 @@ const toggleSelectAllFiltered = () => {
|
||||
};
|
||||
|
||||
const handleDeleteDocument = async (doc: KbDocumentItem) => {
|
||||
console.log('[KB] handleDeleteDocument called', doc.id, doc.title);
|
||||
openDeleteConfirmDialog(`确认删除文档「${getDocumentDisplayTitle(doc)}」吗?`, async () => {
|
||||
const result = await deleteKbDocument(doc.id);
|
||||
if (!result.ok) {
|
||||
@@ -1161,6 +1170,7 @@ const handleBatchSync = async () => {
|
||||
};
|
||||
|
||||
const handleBatchDelete = async () => {
|
||||
console.log('[KB] handleBatchDelete called, selected:', selectedDocuments.value.length);
|
||||
if (!selectedDocuments.value.length) {
|
||||
feedback.value = '请先选择要批量删除的文档';
|
||||
feedbackType.value = 'error';
|
||||
@@ -2581,11 +2591,12 @@ onUnmounted(() => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="showDeleteConfirmDialog"
|
||||
:message="deleteConfirmMessage"
|
||||
@confirm="handleDeleteConfirm"
|
||||
@cancel="closeDeleteConfirmDialog"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="showDeleteConfirmDialog"
|
||||
:message="deleteConfirmMessage"
|
||||
@confirm="handleDeleteConfirm"
|
||||
@cancel="closeDeleteConfirmDialog"
|
||||
/>
|
||||
</template>
|
||||
Reference in new issue
Block a user