fix: 支持原文件下载,同时将postgres地址由localhost变更为8.152.207.171

This commit is contained in:
sophie committed 2026-04-03 11:30:49 +08:00
1 parent 70f95e9f5c
commit c380248502
12 files changed
+1273 -273

No files matched your search

+68 -28
View File
@@ -63,6 +63,12 @@ interface SourceFileLink {
url: string;
}
const PREFERRED_SOURCE_EXTS = new Set([
'pdf', 'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'csv',
'jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'bmp',
'txt', 'rtf', 'md', 'markdown',
]);
const safeDecode = (value: string) => {
try {
return decodeURIComponent(value);
@@ -92,6 +98,43 @@ const normalizeUrl = (url: string) => {
return '';
};
const getUrlExt = (url: string) => {
const clean = (url.split('?')[0] || '').toLowerCase();
const idx = clean.lastIndexOf('.');
if (idx < 0) return '';
return clean.slice(idx + 1);
};
const isChunkLikeLink = (url: string) => {
// Keep original Markdown files; only filter explicit chunk/segment-style links.
return /segment|chunk|fragments?|split/i.test(url);
};
const isPreferredSourceLink = (url: string) => {
const ext = getUrlExt(url);
return PREFERRED_SOURCE_EXTS.has(ext);
};
const isNoisySourceUrl = (url: string) => {
// Raw signed download links are noisy in UI (e.g. download?version_id=...&token=...).
return /(?:^|\/)download\?/i.test(url) || /[?&](token|version_id|kind)=/i.test(url);
};
const isNoisySourceName = (name: string) => {
// Guard against names that are actually query strings instead of human-readable filenames.
const n = (name || '').trim().toLowerCase();
return n.startsWith('download?') || n.includes('token=') || n.includes('version_id=');
};
const looksLikeFileName = (name: string) => {
const n = (name || '').trim();
if (!n) return false;
// Keep Chinese/English file labels such as 员工手册.doc
return /\.[A-Za-z0-9]{2,8}$/.test(n);
};
const isMarkdownFileName = (name: string) => /\.(md|markdown)$/i.test((name || '').trim());
const extractUrlsFromText = (text: string) => {
if (!text) return [];
const urls: string[] = [];
@@ -139,11 +182,13 @@ const getSourceLinks = (resources: any[] = []): SourceFileLink[] => {
const map = new Map<string, SourceFileLink>();
for (const item of resources) {
const directCandidates = [
item?.source_download_url,
item?.url,
item?.file_url,
item?.document_url,
item?.source_url,
item?.download_url,
item?.metadata?.source_download_url,
item?.metadata?.url,
item?.metadata?.file_url,
item?.metadata?.document_url,
@@ -167,14 +212,21 @@ const getSourceLinks = (resources: any[] = []): SourceFileLink[] => {
}
for (const url of discovered) {
const name = item?.document_name || item?.title || decodeURIComponent(url.split('/').pop() || 'source-file');
if (isChunkLikeLink(url)) continue;
// If URL is noisy and we don't have an explicit filename from metadata, skip it.
if (isNoisySourceUrl(url) && !item?.source_filename && !item?.document_name) continue;
const name = item?.source_filename || item?.document_name || item?.title || safeDecode(url.split('/').pop() || 'source-file');
// Skip links whose display name itself is noisy.
if (isNoisySourceName(name)) continue;
const key = `${name}|${url}`;
if (!map.has(key)) {
map.set(key, { name, url });
}
}
}
return Array.from(map.values());
const links = Array.from(map.values());
const preferred = links.filter((l) => isPreferredSourceLink(l.url));
return preferred.length > 0 ? preferred : links;
};
const getMessageLinks = (msg: any): SourceFileLink[] => {
@@ -182,41 +234,29 @@ const getMessageLinks = (msg: any): SourceFileLink[] => {
const merge = (links: SourceFileLink[]) => {
for (const link of links) {
if (isChunkLikeLink(link.url)) continue;
// Keep file buttons if name is valid, even when URL is signed/temporary.
if (isNoisySourceName(link.name)) continue;
if (isMarkdownFileName(link.name)) {
const key = `${link.name}|${link.url}`;
if (!map.has(key)) map.set(key, link);
continue;
}
if (isNoisySourceUrl(link.url) && !looksLikeFileName(link.name)) continue;
const key = `${link.name}|${link.url}`;
if (!map.has(key)) map.set(key, link);
}
};
if (msg?.retriever_resources) {
// Only use structured retriever resources for source buttons,
// so we don't accidentally show random URLs from answer text.
merge(getSourceLinks(msg.retriever_resources));
}
const contentLinks = extractUrlsFromText(msg?.content || '');
for (const url of contentLinks) {
const name = safeDecode(url.split('/').pop() || 'source-file');
merge([{ name, url }]);
}
if (Array.isArray(msg?.attribution_parts)) {
for (const part of msg.attribution_parts) {
const urls = extractUrlsFromText(typeof part === 'string' ? part : JSON.stringify(part));
for (const url of urls) {
const name = safeDecode(url.split('/').pop() || 'source-file');
merge([{ name, url }]);
}
}
}
// 5) 最后兜底:扫描整条 assistant 消息的 JSON 字符串。
// 用途:覆盖 Dify 在未知嵌套字段里返回链接但未被上面路径命中的情况。
const fullMessageText = JSON.stringify(msg || {});
const allUrls = extractUrlsFromText(fullMessageText);
for (const url of allUrls) {
const name = safeDecode(url.split('/').pop() || 'source-file');
merge([{ name, url }]);
}
return Array.from(map.values());
const links = Array.from(map.values());
const preferred = links.filter((l) => isPreferredSourceLink(l.url));
return preferred.length > 0 ? preferred : links;
};
const filePreviewVisible = ref(false);
+36 -35
View File
@@ -1,8 +1,8 @@
<script setup lang="ts">
/**
* WorkspaceView.vue
* 文件用途:用户工作台,支持自定义布局、收藏、嵌入 Agent
* 引用文件:vue, vue-router, lucide-vue-next, 后端 /api/user 接口
* 鏂囦欢鐢ㄩ€旓細鐢ㄦ埛宸ヤ綔鍙帮紝鏀寔鑷畾涔夊竷灞€銆佹敹钘忋€佸祵鍏?Agent
* 寮曠敤鏂囦欢锛歷ue, vue-router, lucide-vue-next, 鍚庣 /api/user 鎺ュ彛
*/
import { ref, onMounted, computed, watch } from 'vue';
import { useRouter } from 'vue-router';
@@ -19,6 +19,7 @@ import {
Edit,
ExternalLink,
Bot,
Lock,
User,
LogOut,
Megaphone,
@@ -120,7 +121,7 @@ const isWecomLoggingIn = ref(false);
const handleForgotPassword = async () => {
if (!forgotPasswordForm.value.email) {
alert(t('register.email') + ' is required');
alert(t('register.emailRequired'));
return;
}
@@ -133,21 +134,21 @@ const handleForgotPassword = async () => {
const data = await res.json();
if (res.ok) {
alert(t('login.passwordResetEmailSent') || 'If the account exists, a reset link has been sent to your email.');
alert(t('login.passwordResetEmailSent'));
showForgotPasswordModal.value = false;
forgotPasswordForm.value = { email: '' };
} else {
alert(data.error || 'Failed to request password reset');
alert(data.error || t('login.passwordResetRequestFailed'));
}
} catch (e) {
console.error('Password reset error', e);
alert('An error occurred');
alert(t('common.errorOccurred'));
}
};
/*
const showLoginTip = () => {
alert(t('login.pleaseLoginFirst') || 'Please login to access this agent.');
alert(t('login.pleaseLoginFirst'));
};
*/
const userReport = ref<any>(null);
@@ -399,11 +400,11 @@ const handleLogin = async () => {
const err = await res.json();
// Handle specific error messages if needed, or just alert
let msg = err.error || t('login.failed');
if (err.error === 'User not found') msg = t('login.userNotFound') || 'User not found';
if (err.error === 'Incorrect password') msg = t('login.incorrectPassword') || 'Incorrect password';
if (err.error === 'Account is disabled') msg = t('login.accountDisabled') || 'Account is disabled';
if (err.error === 'Database connection failed') msg = t('login.dbConnectionFailed') || 'Database connection failed';
if (err.error === 'Internal server error') msg = t('login.internalError') || 'Internal server error';
if (err.error === 'User not found') msg = t('login.userNotFound');
if (err.error === 'Incorrect password') msg = t('login.incorrectPassword');
if (err.error === 'Account is disabled') msg = t('login.accountDisabled');
if (err.error === 'Database connection failed') msg = t('login.dbConnectionFailed');
if (err.error === 'Internal server error') msg = t('login.internalError');
alert(msg);
return;
@@ -426,7 +427,7 @@ const handleLogin = async () => {
}
} catch (e) {
console.error(e);
alert(t('login.requestFailed') || 'Login request failed. Please check your network or server status.');
alert(t('login.requestFailed'));
}
};
@@ -438,7 +439,7 @@ const handleWecomLogin = async () => {
const res = await fetch(`${api}?redirect_uri=${encodeURIComponent(redirectUri)}`);
const data = await res.json();
if (!res.ok || !data.url) {
alert(data.error || 'Failed to start WeCom login');
alert(data.error || t('login.wecomStartFailed'));
return;
}
if (data.state) {
@@ -447,7 +448,7 @@ const handleWecomLogin = async () => {
window.location.href = data.url;
} catch (e) {
console.error(e);
alert('Failed to start WeCom login');
alert(t('login.wecomStartFailed'));
}
};
@@ -461,7 +462,7 @@ const tryWecomCallbackLogin = async () => {
const expectedState = sessionStorage.getItem('hxops_wecom_state');
if (expectedState && state && state !== expectedState) {
alert('Invalid WeCom login state');
alert(t('login.wecomInvalidState'));
return true;
}
@@ -476,13 +477,13 @@ const tryWecomCallbackLogin = async () => {
const data = await res.json();
if (!res.ok) {
const rawError = String(data.error || '');
let friendly = rawError || 'WeCom login failed';
let friendly = rawError || t('login.wecomLoginFailed');
if (rawError.includes('Invalid or expired WeCom state')) {
friendly = '企业微信登录会话已过期,请重新点击企业微信登录';
friendly = t('login.wecomStateExpired');
} else if (rawError.includes('bind WeCom account') || rawError.includes('No linked account found')) {
friendly = '当前企业微信账号未绑定本系统用户,请联系管理员在后台完成绑定';
friendly = t('login.wecomBindRequired');
} else if (rawError.includes('Account is disabled')) {
friendly = '账号已被禁用,请联系管理员';
friendly = t('login.wecomAccountDisabled');
}
alert(friendly);
return true;
@@ -495,7 +496,7 @@ const tryWecomCallbackLogin = async () => {
return true;
} catch (e) {
console.error(e);
alert('WeCom login failed');
alert(t('login.wecomLoginFailed'));
return true;
} finally {
isWecomLoggingIn.value = false;
@@ -587,7 +588,7 @@ const toggleFavorite = async (agentId: number) => {
// Quick Questions
const getAgentName = (agentId: number) => {
const agent = agents.value.find(a => a.id === agentId);
return agent ? agent.name : t('workspace.unknownAgent', 'Unknown Agent');
return agent ? agent.name : t('workspace.unknownAgent');
};
const openAddQuestionForm = () => {
@@ -614,7 +615,7 @@ const cancelAddQuestion = () => {
const saveQuickQuestion = async () => {
if (!newQuestion.value.title || !newQuestion.value.question || !newQuestion.value.agent_id) {
alert(t('workspace.quickQuestions.addTitle') + ' (Please fill all fields)');
alert(t('workspace.quickQuestions.msg.fillAll'));
return;
}
@@ -737,7 +738,7 @@ onMounted(async () => {
<button @click="showUserDropdown = !showUserDropdown" class="flex items-center gap-3 pl-3 pr-2 py-1.5 rounded-full hover:bg-slate-50 dark:hover:bg-slate-800 transition-colors border border-transparent hover:border-slate-200 dark:hover:border-slate-700">
<div class="text-right hidden sm:block">
<div class="text-sm font-bold text-slate-900 dark:text-slate-100 leading-tight">{{ currentUser?.username }}</div>
<div class="text-[10px] font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide">{{ currentUser?.role === 'admin' ? 'Admin' : 'User' }}</div>
<div class="text-[10px] font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide">{{ currentUser?.role }}</div>
</div>
<div class="w-9 h-9 bg-brand-100 rounded-full flex items-center justify-center text-brand-600 font-bold border-2 border-white shadow-sm">
{{ (currentUser?.username || 'U').charAt(0).toUpperCase() }}
@@ -755,7 +756,7 @@ onMounted(async () => {
<button @click="navigateToProfile" class="w-full text-left px-4 py-2 text-sm text-slate-700 dark:text-slate-300 hover:bg-slate-50 dark:hover:bg-slate-800 hover:text-brand-600 flex items-center gap-2">
<User class="w-4 h-4" />
{{ $t('profile.title') || 'My Profile' }}
{{ $t('profile.title') }}
</button>
<button v-if="currentUser?.role === 'admin'" @click="router.push('/admin')" class="w-full text-left px-4 py-2 text-sm text-slate-700 dark:text-slate-300 hover:bg-slate-50 dark:hover:bg-slate-800 hover:text-brand-600 flex items-center gap-2">
@@ -795,21 +796,21 @@ onMounted(async () => {
<span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-brand-400 opacity-75"></span>
<span class="relative inline-flex rounded-full h-2 w-2 bg-brand-500"></span>
</span>
Enterprise AI Gateway
{{ $t('title') }}
</div>
<h1 class="text-5xl font-bold text-slate-900 leading-tight">
Unleash the Power of <br/>
<span class="text-transparent bg-clip-text bg-gradient-to-r from-brand-600 to-purple-600">Generative AI</span>
{{ $t('landing.hero.prefix') }} <br/>
<span class="text-transparent bg-clip-text bg-gradient-to-r from-brand-600 to-purple-600">{{ $t('landing.hero.highlight') }}</span>
</h1>
<p class="text-lg text-slate-600 max-w-md leading-relaxed">
Access a suite of powerful AI agents tailored for your enterprise needs. Secure, scalable, and intelligent.
{{ $t('landing.hero.subtitle') }}
</p>
<!-- Announcements List -->
<div v-if="announcements.length > 0" class="bg-white/60 dark:bg-slate-900/70 backdrop-blur-sm rounded-2xl border border-slate-100 dark:border-slate-700 p-6 shadow-sm">
<h3 class="text-sm font-bold text-slate-900 mb-4 flex items-center gap-2">
<Megaphone class="w-4 h-4 text-brand-600" />
{{ $t('login.announcements') || 'Announcements' }}
{{ $t('login.announcements') }}
</h3>
<div class="space-y-3">
<div v-for="ann in announcements.slice(0, 3)" :key="ann.id"
@@ -832,7 +833,7 @@ onMounted(async () => {
</div>
<div class="truncate">
<div class="font-semibold text-slate-900 text-sm truncate">{{ agent.name }}</div>
<div class="text-xs text-slate-500 truncate">AI Assistant</div>
<div class="text-xs text-slate-500 truncate">{{ $t('landing.agent.role') }}</div>
</div>
</div>
@@ -864,7 +865,7 @@ onMounted(async () => {
<div class="flex items-center gap-2 mt-2">
<input type="checkbox" id="rememberMe" v-model="rememberMe" class="rounded border-slate-300 text-brand-600 focus:ring-brand-500 w-4 h-4" />
<label for="rememberMe" class="text-sm text-slate-600 cursor-pointer select-none">{{ $t('login.rememberMe') || 'Remember me for 30 days' }}</label>
<label for="rememberMe" class="text-sm text-slate-600 cursor-pointer select-none">{{ $t('login.rememberMe') }}</label>
</div>
<button @click="handleLogin" class="btn-primary w-full py-3 text-base shadow-brand-500/40 hover:shadow-brand-500/50 transform hover:-translate-y-0.5 transition-all mt-4">
@@ -877,7 +878,7 @@ onMounted(async () => {
:disabled="isWecomLoggingIn"
class="btn-secondary w-full py-3 text-base mt-3 disabled:opacity-60 disabled:cursor-not-allowed"
>
{{ isWecomLoggingIn ? ($t('login.wecomConnecting') || 'Connecting to WeCom...') : ($t('login.wecomLogin') || 'Login with WeCom') }}
{{ isWecomLoggingIn ? $t('login.wecomConnecting') : $t('login.wecomLogin') }}
</button>
<div class="flex justify-between items-center pt-4 mt-2 border-t border-slate-100/50">
@@ -1097,7 +1098,7 @@ onMounted(async () => {
<Lock class="w-6 h-6" />
</div>
<h3 class="text-xl font-bold text-slate-900 dark:text-slate-100">{{ $t('login.forgotPassword') }}</h3>
<p class="text-slate-500 dark:text-slate-400 text-sm mt-2">{{ $t('login.forgotPasswordDesc') || 'Enter your email to reset your password' }}</p>
<p class="text-slate-500 dark:text-slate-400 text-sm mt-2">{{ $t('login.forgotPasswordDesc') }}</p>
</div>
<div class="space-y-4">
@@ -1107,7 +1108,7 @@ onMounted(async () => {
<div class="flex justify-end gap-3 mt-8">
<button @click="showForgotPasswordModal = false" class="btn-secondary flex-1">{{ $t('register.cancel') }}</button>
<button @click="handleForgotPassword" class="btn-primary flex-1">{{ $t('login.findPassword') || 'Find Password' }}</button>
<button @click="handleForgotPassword" class="btn-primary flex-1">{{ $t('login.findPassword') }}</button>
</div>
</div>
</div>