diff --git a/apps/web/client/app.ts b/apps/web/client/app.ts index ef92cc5f..c33e408f 100644 --- a/apps/web/client/app.ts +++ b/apps/web/client/app.ts @@ -82,7 +82,7 @@ import { installTermHints, renderGlossary } from './termHints'; import { renderAdminPanel } from './ui/AdminPanel'; import { feedbackUrl, localizeSiteLinks } from './feedback'; import type { TermId } from './glossary'; -import { locale, localeTag, localizeMessage, localizeText, otherLocale, sentences, switchLocale, t } from '../i18n'; +import { clause, locale, localeTag, localizeMessage, localizeText, otherLocale, sentences, switchLocale, t } from '../i18n'; import { tx } from './researchShared'; import { historyStorageKey, markHistoryCollapsed, readHistoryCollapsed } from './historyPreference'; import { detailLevel, onDetailLevel } from './detailLevel'; @@ -2991,7 +2991,7 @@ async function poll(force = false) { catch (error) { if (!currentConnection(epoch)) return; if (sessionFailure(error)) { - disconnected(t('{0}。未提交内容已保留。', message(error))); + disconnected(t('{0}。未提交内容已保留。', clause(message(error)))); await initialize(); return; } @@ -3180,7 +3180,7 @@ function initialize(): Promise { setGlobalNotice(session.runtime.ready && session.providers.length ? '' : localizeText(session.runtime.message) || t('运行环境未就绪')); } catch (error) { if (currentConnection(epoch)) { - disconnected(t('{0}。未提交内容已保留。', message(error))); + disconnected(t('{0}。未提交内容已保留。', clause(message(error)))); if (!state.session) renderRunList(true); } } diff --git a/apps/web/client/sourceCheck.tsx b/apps/web/client/sourceCheck.tsx index f079a5f7..4ef7f637 100644 --- a/apps/web/client/sourceCheck.tsx +++ b/apps/web/client/sourceCheck.tsx @@ -1,7 +1,7 @@ import { render } from 'preact'; import type { WebEnvironment, WebPrecheck, WebPrecheckDiagnostic } from '../shared'; import { Icon, Spinner } from './ui/Icon'; -import { sentences, t } from '../i18n'; +import { clause, sentences, t } from '../i18n'; /** Structural findings carry a code; Lean's own diagnostics keep Lean's wording. */ const codeMessages: Record string> = { @@ -123,7 +123,7 @@ function summary(check: SourceCheck): { tone: Tone; title: string; detail: strin const { state } = check; if (state.phase === 'idle') return check.stale() ? { tone: 'neutral', title: t('源码已修改,稍后自动检查'), detail: '', chip: t('待检查') } : undefined; if (state.phase === 'checking') return { tone: 'busy', title: t('正在用 Lean 检查原题'), detail: t('引入 Mathlib 时首次检查约需半分钟。'), chip: t('检查中') }; - if (state.phase === 'failed') return { tone: 'warn', title: t('检查未完成'), detail: t('{0}。仍可提交。', state.message), chip: t('未检查') }; + if (state.phase === 'failed') return { tone: 'warn', title: t('检查未完成'), detail: t('{0}。仍可提交。', clause(state.message)), chip: t('未检查') }; if (check.stale()) return { tone: 'neutral', title: t('源码已修改,稍后自动检查'), detail: t('下方是修改前的检查结果。'), chip: t('待检查') }; const { result } = state; const errors = result.diagnostics.filter(item => item.severity === 'error').length; diff --git a/apps/web/i18n.ts b/apps/web/i18n.ts index 65a6cc4e..7eab6566 100644 --- a/apps/web/i18n.ts +++ b/apps/web/i18n.ts @@ -44,6 +44,9 @@ export const t = translator(locale); /** Joins translated sentences: Chinese runs them together after their 。, English needs a space between them. */ export const sentences = (...parts: string[]) => parts.filter(Boolean).join(locale === 'en' ? ' ' : ''); +/** Drops a message's closing punctuation so a template such as '{0}。…' can supply its own. */ +export const clause = (text: string) => text.replace(/[\s。..!!??]+$/u, ''); + const detail = /^(.*?)( · [^·]+)$/u; /** * Translates text produced elsewhere in Chinese, such as stored event messages and share labels, when it matches a key diff --git a/apps/web/server.ts b/apps/web/server.ts index c903f8b7..6a764f25 100644 --- a/apps/web/server.ts +++ b/apps/web/server.ts @@ -506,6 +506,8 @@ export function createWebService(config: WebConfig, runner: WebRunner = new Dock if (request.headers.origin && request.headers.origin !== origin.origin) throw new HttpError(403, '跨站请求已拒绝。'); const url = new URL(request.url || '/', origin); if (url.origin !== origin.origin) throw new HttpError(403, '访问地址无效。'); + // Routes decode path segments themselves; a malformed escape such as %E0%A4%A is the client's error, not a 500. + try { decodeURIComponent(url.pathname); } catch { throw new HttpError(400, '访问地址无效。'); } if (url.pathname.startsWith('/api/')) { prune(); // Behind a tunnel every request comes from the proxy, so the configured proxy header names the visitor. @@ -1495,6 +1497,11 @@ export function createWebService(config: WebConfig, runner: WebRunner = new Dock { error: known ? error.message : invalidKnowledgeInput ? '知识查询或分页参数无效。' : '服务暂时不可用。', ...(error instanceof HttpError && error.code ? { code: error.code } : {}) }); else response.end(); + if (!known && !invalidKnowledgeInput) { + // The query string and share tokens stay out of the log. + const route = (request.url || '/').split('?')[0].replace(/^\/api\/share\/[^/]+/u, '/api/share/:token'); + console.error(`[web_request_failed] ${request.method} ${route}`, error instanceof Error ? error.stack ?? error.message : typeof error); + } } }); server.requestTimeout = 15_000; server.headersTimeout = 10_000; diff --git a/docs/archive.html b/docs/archive.html index d496e1d6..6fa1cbd2 100644 --- a/docs/archive.html +++ b/docs/archive.html @@ -91,7 +91,7 @@

TheoremOS 证明档案

题目 / 来源状态 / 更新
- + diff --git a/docs/en/archive.html b/docs/en/archive.html index 042a173a..e9322b36 100644 --- a/docs/en/archive.html +++ b/docs/en/archive.html @@ -91,7 +91,7 @@

TheoremOS Proof archive

Problem / sourceStatus / updated
- +