fix: 文档翻译一直转圈 — relay分块并发翻译(8线程, 大文档从几分钟缩到几十秒), 前端fetch加8分钟超时+明确超时提示, nginx read/send timeout 300→600s

This commit is contained in:
personal82555 committed 2026-10-13 11:52:21 +08:00
1 parent 17c71d4259
commit 8538520548
3 files changed
+31 -7

No files matched your search

+17 -3
View File
@@ -173,7 +173,16 @@ async function translateDoc() {
const fd = new FormData();
fd.append('file', docFile.value);
fd.append('to', langName(docTo.value));
const res = await fetch('/relay/translate-doc', { method: 'POST', body: fd, headers: licenseHeaders('translator') });
// 前端超时保护:大文档超过 8 分钟视为失败,避免一直转圈
const ctrl = new AbortController();
const timer = setTimeout(() => ctrl.abort(), 8 * 60 * 1000);
let res: Response;
try {
res = await fetch('/relay/translate-doc', { method: 'POST', body: fd, headers: licenseHeaders('translator'), signal: ctrl.signal });
}
finally {
clearTimeout(timer);
}
const j = await res.json().catch(() => ({}));
if (!res.ok || j.code !== 200) {
throw new Error(j.message || `HTTP ${res.status}`);
@@ -183,7 +192,12 @@ async function translateDoc() {
genHist.add({ title: `文档翻译: ${docFile.value.name}`, detail: `${j.data.chars} 字 → ${langName(docTo.value)}` });
}
catch (e: any) {
docError.value = String(e?.message || e);
if (e?.name === 'AbortError') {
docError.value = '翻译超时(超过 8 分钟):文档过大,请拆分后重试,或减小文档篇幅。';
}
else {
docError.value = String(e?.message || e);
}
}
finally {
docLoading.value = false;
@@ -307,7 +321,7 @@ onUnmounted(() => {
</select>
</div>
<button class="doc-go" :disabled="docLoading || !docFile" @click="translateDoc()">
{{ docLoading ? '⏳ AI 整篇翻译中…(长文档请耐心等待)' : '🚀 翻译文档' }}
{{ docLoading ? '⏳ AI 并发翻译中…(大文档约需 1-2 分钟)' : '🚀 翻译文档' }}
</button>
</div>
</div>