Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/web/client/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -3180,7 +3180,7 @@ function initialize(): Promise<void> {
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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions apps/web/client/sourceCheck.tsx
Original file line number Diff line number Diff line change
@@ -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, () => string> = {
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions apps/web/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions apps/web/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion docs/archive.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ <h1 id="page-title">TheoremOS <span>证明档案</span></h1>
<div class="catalog-heading"><span>题目 / 来源</span><span>状态 / 更新</span></div>
<ul id="proof-list" class="proof-list" aria-label="证明列表"><li class="initial-loading" role="status">正在加载证明档案…</li></ul>
<div id="empty-state" class="empty-state" hidden><i data-lucide="search-x"></i><h2>没有匹配的题目</h2><button class="button" data-action="reset">清除筛选</button></div>
<div class="catalog-footer"><span id="result-count" aria-live="polite">7 条记录</span><a href="data/catalog.json" download="theoremos-archive.json" title="下载完整档案 JSON"><i data-lucide="download"></i>档案 JSON</a></div>
<div class="catalog-footer"><span id="result-count" aria-live="polite"></span><a href="data/catalog.json" download="theoremos-archive.json" title="下载完整档案 JSON"><i data-lucide="download"></i>档案 JSON</a></div>
</section>
<aside class="inspector" id="inspector" aria-label="题目详情" tabindex="-1"></aside>
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/en/archive.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ <h1 id="page-title">TheoremOS <span>Proof archive</span></h1>
<div class="catalog-heading"><span>Problem / source</span><span>Status / updated</span></div>
<ul id="proof-list" class="proof-list" aria-label="Proof list"><li class="initial-loading" role="status">Loading the proof archive…</li></ul>
<div id="empty-state" class="empty-state" hidden><i data-lucide="search-x"></i><h2>No matching problems</h2><button class="button" data-action="reset">Clear filters</button></div>
<div class="catalog-footer"><span id="result-count" aria-live="polite">7 records</span><a href="../data/catalog.json" download="theoremos-archive.json" title="Download the full archive as JSON"><i data-lucide="download"></i>Archive JSON</a></div>
<div class="catalog-footer"><span id="result-count" aria-live="polite"></span><a href="../data/catalog.json" download="theoremos-archive.json" title="Download the full archive as JSON"><i data-lucide="download"></i>Archive JSON</a></div>
</section>
<aside class="inspector" id="inspector" aria-label="Problem details" tabindex="-1"></aside>
</div>
Expand Down
Loading