mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-11-16 14:54:23 +08:00
feat(i18n): default to English, localize runtime text and add Russian (#52)
This commit is contained in:
+21
-14
@@ -1,3 +1,4 @@
|
||||
import { runtimeText } from '@/i18n/runtime';
|
||||
/**
|
||||
* Cap PoW (Proof-of-Work) 人机验证前端实现
|
||||
* 与后端 pkg/cap 算法完全对应
|
||||
@@ -78,7 +79,7 @@ async function solvePuzzle(token, index, size, difficulty) {
|
||||
for (let nonce = 0; nonce < 10_000_000; nonce++) {
|
||||
if ((await sha256Hex(salt + nonce)).startsWith(target)) return nonce;
|
||||
}
|
||||
throw new Error('无法在合理范围内求解第 ' + (index + 1) + ' 个难题');
|
||||
throw new Error('Could not solve puzzle ' + (index + 1) + ' within the allowed search range');
|
||||
}
|
||||
|
||||
// Entry point — receive task from main thread
|
||||
@@ -124,7 +125,11 @@ function solveInWorker(
|
||||
worker.onerror = (err) => {
|
||||
URL.revokeObjectURL(url);
|
||||
worker.terminate();
|
||||
reject(new Error(err.message || 'Worker 执行失败'));
|
||||
reject(
|
||||
new Error(
|
||||
err.message || runtimeText('worker_execution_failed_1877e35b'),
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
worker.postMessage({ token, count, size, difficulty });
|
||||
@@ -142,14 +147,14 @@ export async function getCapToken(scope = 'login'): Promise<string> {
|
||||
});
|
||||
const challenge = await readApiData<ChallengeResponse>(
|
||||
challengeRes,
|
||||
'获取人机验证难题失败',
|
||||
runtimeText('failed_to_fetch_the_verification_challenge_95553133'),
|
||||
);
|
||||
const { c: count, s: size, d: difficulty } = challenge.challenge;
|
||||
|
||||
console.groupCollapsed('[Cap] 人机验证 PoW 求解开始');
|
||||
console.log(` 难题数量 (count) : ${count}`);
|
||||
console.log(` 验证难度 (difficulty): ${difficulty}`);
|
||||
console.log(` 盐值长度 (size) : ${size}`);
|
||||
console.groupCollapsed('[Cap] Starting verification PoW solver');
|
||||
console.log(` Challenge count: ${count}`);
|
||||
console.log(` Difficulty: ${difficulty}`);
|
||||
console.log(` Salt size: ${size}`);
|
||||
console.groupEnd();
|
||||
|
||||
// 2. 在 Worker 中求解(不阻塞主线程)
|
||||
@@ -162,11 +167,11 @@ export async function getCapToken(scope = 'login'): Promise<string> {
|
||||
);
|
||||
const wallTime = ((performance.now() - t0) / 1000).toFixed(3);
|
||||
|
||||
console.groupCollapsed('[Cap] 人机验证 PoW 求解完成');
|
||||
console.log(` 难题数量 (count) : ${count}`);
|
||||
console.log(` 验证难度 (difficulty): ${difficulty}`);
|
||||
console.log(` Worker 耗时 : ${elapsed}s`);
|
||||
console.log(` 总耗时(含通信) : ${wallTime}s`);
|
||||
console.groupCollapsed('[Cap] Verification PoW solver completed');
|
||||
console.log(` Challenge count: ${count}`);
|
||||
console.log(` Difficulty: ${difficulty}`);
|
||||
console.log(` Worker duration: ${elapsed}s`);
|
||||
console.log(` Total duration (including communication): ${wallTime}s`);
|
||||
console.log(` Solutions :`, solutions);
|
||||
console.groupEnd();
|
||||
|
||||
@@ -178,10 +183,12 @@ export async function getCapToken(scope = 'login'): Promise<string> {
|
||||
});
|
||||
const redeemData = await readApiData<RedeemResponse>(
|
||||
redeemRes,
|
||||
'人机验证失败',
|
||||
runtimeText('verification_failed_d3925ab2'),
|
||||
);
|
||||
if (!redeemData.success || !redeemData.token) {
|
||||
throw new Error(redeemData.error || '人机验证失败');
|
||||
throw new Error(
|
||||
redeemData.error || runtimeText('verification_failed_d3925ab2'),
|
||||
);
|
||||
}
|
||||
|
||||
return redeemData.token;
|
||||
|
||||
@@ -1,170 +1,7 @@
|
||||
import { runtimeText } from '@/i18n/runtime';
|
||||
/** 内置离线页模板:baohaus */
|
||||
const html = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>离线页 | OpenFlare</title>
|
||||
<style>
|
||||
*, *::before, *::after {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
export default function getOfflineHTML() {
|
||||
const html = runtimeText.raw('doctype_html_html_lang_en_head_meta_3e4f5ecb');
|
||||
|
||||
body {
|
||||
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||||
background-color: #f4f3ef;
|
||||
color: #121212;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 48px 24px;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
.bauhaus-card {
|
||||
width: 100%;
|
||||
max-width: 580px;
|
||||
background: #ffffff;
|
||||
border: 3px solid #121212;
|
||||
box-shadow: 8px 8px 0px #121212;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.card-accent-bar {
|
||||
height: 12px;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.accent-red { flex: 2; background-color: #e63946; }
|
||||
.accent-blue { flex: 3; background-color: #1d3557; }
|
||||
.accent-yellow { flex: 1; background-color: #f1faee; }
|
||||
|
||||
.card-body {
|
||||
padding: 40px 32px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.tag {
|
||||
align-self: flex-start;
|
||||
background-color: #121212;
|
||||
color: #ffffff;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.1em;
|
||||
text-transform: uppercase;
|
||||
padding: 4px 10px;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 28px;
|
||||
font-weight: 800;
|
||||
line-height: 1.2;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.message {
|
||||
font-size: 15px;
|
||||
line-height: 1.6;
|
||||
color: #4a4a4a;
|
||||
}
|
||||
|
||||
.contact-box {
|
||||
border: 2px solid #121212;
|
||||
background-color: #f9f8f3;
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.contact-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.contact-line a {
|
||||
color: #e63946;
|
||||
text-decoration: none;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.contact-line a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.card-footer {
|
||||
border-top: 2px solid #121212;
|
||||
padding: 16px 32px;
|
||||
background-color: #faf9f6;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.brand-icon {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
fill: currentColor;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="bauhaus-card">
|
||||
<div class="card-accent-bar">
|
||||
<div class="accent-red"></div>
|
||||
<div class="accent-blue"></div>
|
||||
<div class="accent-yellow"></div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="tag">OFFLINE FALLBACK</div>
|
||||
<h1 class="title">离线联系站长</h1>
|
||||
<p class="message">
|
||||
源站网络临时不可达。离线 Service Worker 已拦截请求,您可以使用下方联系方式取得支持。
|
||||
</p>
|
||||
<div class="contact-box">
|
||||
<div class="contact-line">
|
||||
<span>站长邮箱</span>
|
||||
<a href="mailto:admin@example.com">admin@example.com</a>
|
||||
</div>
|
||||
<div class="contact-line">
|
||||
<span>服务监控</span>
|
||||
<a href="https://status.example.com" target="_blank" rel="noopener">status.example.com</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<div class="brand">
|
||||
<svg class="brand-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M13 2L3 14H12L11 22L21 10H12L13 2Z" />
|
||||
</svg>
|
||||
<span>OpenFlare Service Worker</span>
|
||||
</div>
|
||||
<span>OFFLINE MODE</span>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
export default html;
|
||||
return html;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { runtimeText } from '@/i18n/runtime';
|
||||
/**
|
||||
* 内置离线页 HTML 模板目录。
|
||||
*/
|
||||
@@ -17,29 +18,40 @@ export type OfflinePageTemplate = {
|
||||
export const OFFLINE_PAGE_TEMPLATES: OfflinePageTemplate[] = [
|
||||
{
|
||||
id: 'minimalist',
|
||||
name: '极简白底',
|
||||
html: minimalistHtml,
|
||||
get name() {
|
||||
return runtimeText('minimal_white_5636e8a9');
|
||||
},
|
||||
get html() {
|
||||
return minimalistHtml();
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'line-style',
|
||||
name: '线框拓扑',
|
||||
html: lineStyleHtml,
|
||||
get name() {
|
||||
return runtimeText('line_topology_22ad450c');
|
||||
},
|
||||
get html() {
|
||||
return lineStyleHtml();
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'baohaus',
|
||||
name: '包豪斯',
|
||||
html: baohausHtml,
|
||||
get name() {
|
||||
return runtimeText('bauhaus_5cc69781');
|
||||
},
|
||||
get html() {
|
||||
return baohausHtml();
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
/** 默认预制模板 */
|
||||
export const DEFAULT_OFFLINE_PAGE_TEMPLATE_ID = 'minimalist';
|
||||
|
||||
export const DEFAULT_OFFLINE_PAGE_HTML =
|
||||
getOfflinePageTemplate(DEFAULT_OFFLINE_PAGE_TEMPLATE_ID)?.html ?? '';
|
||||
|
||||
export function effectiveOfflinePageHTML(html: string): string {
|
||||
return html.trim() === '' ? DEFAULT_OFFLINE_PAGE_HTML : html;
|
||||
return html.trim() === ''
|
||||
? (getOfflinePageTemplate(DEFAULT_OFFLINE_PAGE_TEMPLATE_ID)?.html ?? '')
|
||||
: html;
|
||||
}
|
||||
|
||||
export function getOfflinePageTemplate(
|
||||
|
||||
@@ -1,193 +1,7 @@
|
||||
import { runtimeText } from '@/i18n/runtime';
|
||||
/** 内置离线页模板:line-style */
|
||||
const html = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>离线页 | OpenFlare</title>
|
||||
<style>
|
||||
*, *::before, *::after {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
export default function getOfflineHTML() {
|
||||
const html = runtimeText.raw('doctype_html_html_lang_en_head_meta_42a4f2da');
|
||||
|
||||
:root {
|
||||
--color-bg: #fcfcfc;
|
||||
--color-line: #e0e0e0;
|
||||
--color-line-hover: #1a1a1a;
|
||||
--color-text-main: #1a1a1a;
|
||||
--color-text-sub: #666666;
|
||||
--color-text-muted: #999999;
|
||||
--color-accent: #d4d4d4;
|
||||
--font-geo: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
||||
--transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: var(--font-geo);
|
||||
background-color: var(--color-bg);
|
||||
background-image: radial-gradient(circle, var(--color-accent) 0.8px, transparent 0.8px);
|
||||
background-size: 24px 24px;
|
||||
color: var(--color-text-main);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 48px 24px;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
letter-spacing: 0.01em;
|
||||
}
|
||||
|
||||
.main-container {
|
||||
width: 100%;
|
||||
max-width: 640px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 32px;
|
||||
}
|
||||
|
||||
.line-box {
|
||||
border: 1px solid var(--color-line);
|
||||
background: rgba(255, 255, 255, 0.7);
|
||||
backdrop-filter: blur(4px);
|
||||
padding: 32px;
|
||||
transition: all var(--transition-fast);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.line-box:hover {
|
||||
border-color: var(--color-line-hover);
|
||||
box-shadow: 0 0 0 1px var(--color-line-hover);
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.15em;
|
||||
text-transform: uppercase;
|
||||
color: var(--color-text-sub);
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.status-dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background-color: #f59e0b;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
letter-spacing: -0.02em;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
color: var(--color-text-sub);
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.contact-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
border-top: 1px dashed var(--color-line);
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.contact-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.contact-label {
|
||||
color: var(--color-text-muted);
|
||||
font-size: 12px;
|
||||
letter-spacing: 0.05em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.contact-value a {
|
||||
color: var(--color-text-main);
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
border-bottom: 1px solid var(--color-line);
|
||||
transition: border-color var(--transition-fast);
|
||||
}
|
||||
|
||||
.contact-value a:hover {
|
||||
border-color: var(--color-text-main);
|
||||
}
|
||||
|
||||
.footer-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-size: 11px;
|
||||
color: var(--color-text-muted);
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-weight: 600;
|
||||
color: var(--color-text-main);
|
||||
}
|
||||
|
||||
.brand-icon {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
fill: currentColor;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="main-container">
|
||||
<div class="line-box">
|
||||
<div class="status-badge">
|
||||
<span class="status-dot"></span>
|
||||
SERVICE WORKER OFFLINE CACHE
|
||||
</div>
|
||||
<h1 class="title">网络中断或源站不可达</h1>
|
||||
<p class="description">
|
||||
系统已自动启用 Service Worker 兜底保护。如需紧急联系站长,请通过以下渠道:
|
||||
</p>
|
||||
<div class="contact-list">
|
||||
<div class="contact-row">
|
||||
<span class="contact-label">Email Support</span>
|
||||
<span class="contact-value"><a href="mailto:admin@example.com">admin@example.com</a></span>
|
||||
</div>
|
||||
<div class="contact-row">
|
||||
<span class="contact-label">Status Page</span>
|
||||
<span class="contact-value"><a href="https://status.example.com" target="_blank" rel="noopener">status.example.com</a></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer-bar">
|
||||
<div class="brand">
|
||||
<svg class="brand-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M13 2L3 14H12L11 22L21 10H12L13 2Z" />
|
||||
</svg>
|
||||
<span>OpenFlare Edge</span>
|
||||
</div>
|
||||
<span>FALLBACK ACTIVE</span>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
export default html;
|
||||
return html;
|
||||
}
|
||||
|
||||
@@ -1,128 +1,7 @@
|
||||
import { runtimeText } from '@/i18n/runtime';
|
||||
/** 内置离线页模板:minimalist(默认) */
|
||||
const html = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>离线页 | OpenFlare</title>
|
||||
<style>
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||||
background-color: #ffffff;
|
||||
color: #333333;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
padding: 48px 24px;
|
||||
}
|
||||
.container {
|
||||
max-width: 560px;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 24px;
|
||||
}
|
||||
.badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 4px 12px;
|
||||
border-radius: 9999px;
|
||||
background-color: #f3f4f6;
|
||||
color: #4b5563;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
.title {
|
||||
font-size: 32px;
|
||||
font-weight: 700;
|
||||
color: #111827;
|
||||
line-height: 1.25;
|
||||
}
|
||||
.description {
|
||||
font-size: 15px;
|
||||
line-height: 1.6;
|
||||
color: #6b7280;
|
||||
max-width: 480px;
|
||||
}
|
||||
.contact-card {
|
||||
width: 100%;
|
||||
background: #f9fafb;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 12px;
|
||||
padding: 24px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
text-align: left;
|
||||
}
|
||||
.contact-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
font-size: 14px;
|
||||
color: #374151;
|
||||
}
|
||||
.contact-item svg {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
color: #6b7280;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.contact-item a {
|
||||
color: #2563eb;
|
||||
text-decoration: none;
|
||||
}
|
||||
.contact-item a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.footer {
|
||||
margin-top: 32px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
color: #9ca3af;
|
||||
font-size: 13px;
|
||||
}
|
||||
.brand-icon {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
fill: currentColor;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="badge">OFFLINE CONTACT</div>
|
||||
<h1 class="title">站点暂不可用,联系站长</h1>
|
||||
<p class="description">
|
||||
当前无法连接至源站。页面已开启 Service Worker 离线保护,您可以通过以下方式与站长取得联系。
|
||||
</p>
|
||||
<div class="contact-card">
|
||||
<div class="contact-item">
|
||||
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path></svg>
|
||||
<span>联系邮箱:<a href="mailto:admin@example.com">admin@example.com</a></span>
|
||||
</div>
|
||||
<div class="contact-item">
|
||||
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"></path></svg>
|
||||
<span>服务状态页:<a href="https://status.example.com" target="_blank" rel="noopener">status.example.com</a></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<svg class="brand-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M13 2L3 14H12L11 22L21 10H12L13 2Z" />
|
||||
</svg>
|
||||
<span>OpenFlare Protection</span>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
export default function getOfflineHTML() {
|
||||
const html = runtimeText.raw('doctype_html_html_lang_en_head_meta_505c1308');
|
||||
|
||||
export default html;
|
||||
return html;
|
||||
}
|
||||
|
||||
@@ -1,293 +1,5 @@
|
||||
/** 内置错误页模板:baohaus(包豪斯风格) */
|
||||
const html = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{status}} | OpenFlare</title>
|
||||
<style>
|
||||
:root {
|
||||
--color-red: #E53935;
|
||||
--color-yellow: #FDD835;
|
||||
--color-blue: #1E88E5;
|
||||
--color-black: #212121;
|
||||
--color-white: #FAFAFA;
|
||||
--color-grey: #9E9E9E;
|
||||
--font-primary: 'Futura', 'Century Gothic', 'Tw Cen MT', sans-serif;
|
||||
}
|
||||
import { runtimeText } from '@/i18n/runtime';
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: var(--color-white);
|
||||
color: var(--color-black);
|
||||
font-family: var(--font-primary);
|
||||
min-height: 100vh;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
body::before {
|
||||
content: "";
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: radial-gradient(var(--color-grey) 1px, transparent 1px);
|
||||
background-size: 20px 20px;
|
||||
opacity: 0.15;
|
||||
z-index: -1;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.layout-container {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1.618fr;
|
||||
grid-template-rows: 1fr 1fr;
|
||||
min-height: 100vh;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.zone-left {
|
||||
grid-column: 1 / 2;
|
||||
grid-row: 1 / 3;
|
||||
border-right: 4px solid var(--color-black);
|
||||
border-bottom: 4px solid var(--color-black);
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: var(--color-white);
|
||||
padding: 2rem;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.decor-circle {
|
||||
position: absolute;
|
||||
width: 40vh;
|
||||
height: 40vh;
|
||||
background-color: var(--color-yellow);
|
||||
border-radius: 50%;
|
||||
top: 15%;
|
||||
left: 10%;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.error-number {
|
||||
font-size: clamp(6rem, 12vw, 14rem);
|
||||
font-weight: 700;
|
||||
line-height: 0.9;
|
||||
letter-spacing: -0.04em;
|
||||
color: var(--color-black);
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.brand-footer {
|
||||
position: absolute;
|
||||
bottom: 2rem;
|
||||
left: 2rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
z-index: 3;
|
||||
}
|
||||
|
||||
.brand-icon {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
fill: var(--color-black);
|
||||
}
|
||||
|
||||
.brand-text {
|
||||
font-size: 0.85rem;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.15em;
|
||||
}
|
||||
|
||||
.zone-top-right {
|
||||
grid-column: 2 / 3;
|
||||
grid-row: 1 / 2;
|
||||
border-bottom: 4px solid var(--color-black);
|
||||
background-color: var(--color-white);
|
||||
padding: 4rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.error-title {
|
||||
font-size: clamp(1.5rem, 3vw, 2.5rem);
|
||||
text-transform: uppercase;
|
||||
font-weight: 700;
|
||||
margin-bottom: 1.5rem;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.error-desc {
|
||||
font-size: 1.1rem;
|
||||
line-height: 1.6;
|
||||
max-width: 450px;
|
||||
color: var(--color-black);
|
||||
}
|
||||
|
||||
.meta-data {
|
||||
margin-top: 2rem;
|
||||
font-family: monospace;
|
||||
font-size: 0.8rem;
|
||||
color: var(--color-grey);
|
||||
border-top: 1px solid var(--color-grey);
|
||||
padding-top: 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.35rem;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.zone-bottom-right {
|
||||
grid-column: 2 / 3;
|
||||
grid-row: 2 / 3;
|
||||
background-color: var(--color-white);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.geo-line {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 3px;
|
||||
background-color: var(--color-black);
|
||||
top: 50%;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.geo-triangle {
|
||||
position: absolute;
|
||||
right: 15%;
|
||||
bottom: 15%;
|
||||
width: 0;
|
||||
height: 0;
|
||||
border-left: 80px solid transparent;
|
||||
border-right: 80px solid transparent;
|
||||
border-bottom: 140px solid var(--color-blue);
|
||||
}
|
||||
|
||||
.geo-rect {
|
||||
position: absolute;
|
||||
top: 40%;
|
||||
left: 20%;
|
||||
width: 150px;
|
||||
height: 30px;
|
||||
background-color: var(--color-red);
|
||||
transform: rotate(-45deg);
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.layout-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.zone-left {
|
||||
border-right: none;
|
||||
border-bottom: 4px solid var(--color-black);
|
||||
min-height: 50vh;
|
||||
padding-top: 4rem;
|
||||
}
|
||||
|
||||
.decor-circle {
|
||||
width: 30vh;
|
||||
height: 30vh;
|
||||
top: 10%;
|
||||
}
|
||||
|
||||
.zone-top-right {
|
||||
border-bottom: 4px solid var(--color-black);
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.zone-bottom-right {
|
||||
min-height: 30vh;
|
||||
}
|
||||
|
||||
.geo-triangle {
|
||||
border-left-width: 50px;
|
||||
border-right-width: 50px;
|
||||
border-bottom-width: 90px;
|
||||
right: 10%;
|
||||
}
|
||||
|
||||
.geo-rect {
|
||||
width: 100px;
|
||||
height: 20px;
|
||||
left: 15%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="layout-container">
|
||||
<div class="zone-left">
|
||||
<div class="decor-circle"></div>
|
||||
<div class="error-number" aria-label="HTTP status">{{status}}</div>
|
||||
|
||||
<div class="brand-footer">
|
||||
<svg class="brand-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
||||
<path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"/>
|
||||
</svg>
|
||||
<span class="brand-text">OpenFlare</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="zone-top-right">
|
||||
<h1 class="error-title">Origin Unavailable</h1>
|
||||
<p class="error-desc">
|
||||
The server received an invalid response from the upstream server.
|
||||
<br><br>
|
||||
<strong>Form follows function:</strong> The connection path is broken. Please verify the origin server status.
|
||||
</p>
|
||||
<div class="meta-data">
|
||||
<div>ERR_CODE: {{status}}</div>
|
||||
<div>HOST: {{host}}</div>
|
||||
<div>PROXY: OPENFLARE_EDGE</div>
|
||||
<div id="timestamp">--:--:-- UTC</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="zone-bottom-right">
|
||||
<div class="geo-line"></div>
|
||||
<div class="geo-rect"></div>
|
||||
<div class="geo-triangle"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const tsElement = document.getElementById('timestamp');
|
||||
if (tsElement) {
|
||||
const now = new Date();
|
||||
tsElement.textContent = now.toISOString().split('T')[1].split('.')[0] + ' UTC';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
export default html;
|
||||
export default function getHTML() {
|
||||
return runtimeText.raw('origin_error_page_baohaus');
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { runtimeText } from '@/i18n/runtime';
|
||||
/**
|
||||
* 内置源站错误页 HTML 模板目录。
|
||||
* 每个模板对应本目录下一个独立 `.ts` 模块(export default 完整 HTML 字符串)。
|
||||
* 每个模板对应本目录下一个独立 `.ts` 模块(export default 返回完整 HTML 的函数)。
|
||||
* 新增模板:新增 `*.ts` 并在下方数组注册。
|
||||
*
|
||||
* 模板须使用占位符 {{status}} / {{host}},禁止写死状态码。
|
||||
@@ -21,18 +22,30 @@ export type OriginErrorPageTemplate = {
|
||||
export const ORIGIN_ERROR_PAGE_TEMPLATES: OriginErrorPageTemplate[] = [
|
||||
{
|
||||
id: 'minimalist',
|
||||
name: '极简白底',
|
||||
html: minimalistHtml,
|
||||
get name() {
|
||||
return runtimeText('minimal_white_5636e8a9');
|
||||
},
|
||||
get html() {
|
||||
return minimalistHtml();
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'line-style',
|
||||
name: '线框拓扑',
|
||||
html: lineStyleHtml,
|
||||
get name() {
|
||||
return runtimeText('line_topology_22ad450c');
|
||||
},
|
||||
get html() {
|
||||
return lineStyleHtml();
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'baohaus',
|
||||
name: '包豪斯',
|
||||
html: baohausHtml,
|
||||
get name() {
|
||||
return runtimeText('bauhaus_5cc69781');
|
||||
},
|
||||
get html() {
|
||||
return baohausHtml();
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -1,309 +1,5 @@
|
||||
/** 内置错误页模板:line-style */
|
||||
const html = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{status}} | OpenFlare</title>
|
||||
<style>
|
||||
*, *::before, *::after {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
import { runtimeText } from '@/i18n/runtime';
|
||||
|
||||
:root {
|
||||
--color-bg: #fcfcfc;
|
||||
--color-line: #e0e0e0;
|
||||
--color-line-hover: #1a1a1a;
|
||||
--color-text-main: #1a1a1a;
|
||||
--color-text-sub: #666666;
|
||||
--color-text-muted: #999999;
|
||||
--color-accent: #d4d4d4;
|
||||
--font-geo: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
||||
--transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: var(--font-geo);
|
||||
background-color: var(--color-bg);
|
||||
background-image: radial-gradient(circle, var(--color-accent) 0.8px, transparent 0.8px);
|
||||
background-size: 24px 24px;
|
||||
color: var(--color-text-main);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 48px 24px;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
letter-spacing: 0.01em;
|
||||
}
|
||||
|
||||
.main-container {
|
||||
width: 100%;
|
||||
max-width: 640px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 48px;
|
||||
}
|
||||
|
||||
.line-box {
|
||||
border: 1px solid var(--color-line);
|
||||
background: rgba(255, 255, 255, 0.6);
|
||||
backdrop-filter: blur(4px);
|
||||
padding: 32px;
|
||||
transition: all var(--transition-fast);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.line-box:hover {
|
||||
border-color: var(--color-line-hover);
|
||||
box-shadow: 0 0 0 1px var(--color-line-hover);
|
||||
}
|
||||
|
||||
.line-box:active {
|
||||
transform: scale(0.995);
|
||||
transition-duration: 100ms;
|
||||
}
|
||||
|
||||
.error-header {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.error-code {
|
||||
font-size: 64px;
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
letter-spacing: -0.03em;
|
||||
color: var(--color-text-main);
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.error-label {
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.2em;
|
||||
text-transform: uppercase;
|
||||
color: var(--color-text-sub);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.error-label::before,
|
||||
.error-label::after {
|
||||
content: '';
|
||||
width: 24px;
|
||||
height: 1px;
|
||||
background-color: var(--color-line);
|
||||
}
|
||||
|
||||
.topology-wrapper {
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.topology-svg {
|
||||
width: 100%;
|
||||
height: 140px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.node-circle {
|
||||
fill: var(--color-bg);
|
||||
stroke: var(--color-text-main);
|
||||
stroke-width: 1.5;
|
||||
transition: all var(--transition-fast);
|
||||
}
|
||||
|
||||
.node-circle.error {
|
||||
stroke: var(--color-text-muted);
|
||||
stroke-dasharray: 3 3;
|
||||
}
|
||||
|
||||
.flow-line {
|
||||
stroke: var(--color-accent);
|
||||
stroke-width: 1.5;
|
||||
fill: none;
|
||||
transition: stroke var(--transition-fast);
|
||||
}
|
||||
|
||||
.flow-line.error {
|
||||
stroke: var(--color-text-muted);
|
||||
stroke-dasharray: 4 4;
|
||||
}
|
||||
|
||||
.node-text {
|
||||
font-family: var(--font-geo);
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.1em;
|
||||
fill: var(--color-text-sub);
|
||||
text-anchor: middle;
|
||||
}
|
||||
|
||||
.status-text {
|
||||
font-family: var(--font-geo);
|
||||
font-size: 9px;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.05em;
|
||||
fill: var(--color-text-muted);
|
||||
text-anchor: middle;
|
||||
}
|
||||
|
||||
.status-text.error {
|
||||
fill: #b0b0b0;
|
||||
}
|
||||
|
||||
.description {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.desc-text {
|
||||
font-size: 18px;
|
||||
line-height: 1.6;
|
||||
color: var(--color-text-sub);
|
||||
font-weight: 400;
|
||||
max-width: 480px;
|
||||
margin: 0 auto 24px;
|
||||
}
|
||||
|
||||
.meta-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 16px;
|
||||
border-top: 1px solid var(--color-line);
|
||||
padding-top: 24px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.meta-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.meta-key {
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.1em;
|
||||
text-transform: uppercase;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.meta-val {
|
||||
font-size: 13px;
|
||||
font-family: 'SF Mono', 'Fira Code', monospace, var(--font-geo);
|
||||
color: var(--color-text-main);
|
||||
font-weight: 500;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.footer-brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
color: var(--color-text-muted);
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.05em;
|
||||
transition: color var(--transition-fast);
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.footer-brand:hover {
|
||||
color: var(--color-text-main);
|
||||
}
|
||||
|
||||
.brand-icon {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
stroke: currentColor;
|
||||
stroke-width: 1.5;
|
||||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
fill: none;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
body {
|
||||
padding: 32px 16px;
|
||||
}
|
||||
.error-code {
|
||||
font-size: 48px;
|
||||
}
|
||||
.line-box {
|
||||
padding: 24px 16px;
|
||||
}
|
||||
.meta-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="main-container">
|
||||
<div class="line-box error-header">
|
||||
<div class="error-code" aria-label="HTTP status">{{status}}</div>
|
||||
<div class="error-label">Origin Unavailable</div>
|
||||
</div>
|
||||
|
||||
<div class="line-box topology-wrapper">
|
||||
<svg class="topology-svg" viewBox="0 0 600 140" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
||||
<defs>
|
||||
<marker id="arrow" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
|
||||
<path d="M 0 1 L 8 5 L 0 9 z" fill="#d4d4d4" />
|
||||
</marker>
|
||||
<marker id="arrow-error" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
|
||||
<path d="M 0 1 L 8 5 L 0 9 z" fill="#999999" />
|
||||
</marker>
|
||||
</defs>
|
||||
|
||||
<line x1="135" y1="70" x2="265" y2="70" class="flow-line" marker-end="url(#arrow)" />
|
||||
<line x1="335" y1="70" x2="465" y2="70" class="flow-line error" marker-end="url(#arrow-error)" />
|
||||
|
||||
<circle cx="110" cy="70" r="20" class="node-circle" />
|
||||
<text x="110" y="74" class="node-text" style="font-size: 8px; fill: #1a1a1a;">CLI</text>
|
||||
<text x="110" y="115" class="node-text">CLIENT</text>
|
||||
<text x="110" y="130" class="status-text">REQ_SENT</text>
|
||||
|
||||
<circle cx="300" cy="70" r="20" class="node-circle" />
|
||||
<path d="M296 70 L304 64 L301 70 L305 70 L296 76 L299 70 Z" fill="none" stroke="#1a1a1a" stroke-width="1" stroke-linejoin="round"/>
|
||||
<text x="300" y="115" class="node-text">OPENFLARE</text>
|
||||
<text x="300" y="130" class="status-text">EDGE_PROXY</text>
|
||||
|
||||
<circle cx="490" cy="70" r="20" class="node-circle error" />
|
||||
<line x1="484" y1="64" x2="496" y2="76" stroke="#999" stroke-width="1.5" stroke-linecap="round"/>
|
||||
<line x1="496" y1="64" x2="484" y2="76" stroke="#999" stroke-width="1.5" stroke-linecap="round"/>
|
||||
<text x="490" y="115" class="node-text" style="fill: #999;">ORIGIN</text>
|
||||
<text x="490" y="130" class="status-text error">UNAVAILABLE</text>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="footer-brand">
|
||||
<svg class="brand-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
||||
<path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z" />
|
||||
</svg>
|
||||
<span>OpenFlare</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const tsEl = document.getElementById('timestamp');
|
||||
if (tsEl) {
|
||||
const now = new Date();
|
||||
tsEl.textContent = now.toISOString().replace('T', ' ').substring(0, 19) + ' UTC';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
export default html;
|
||||
export default function getHTML() {
|
||||
return runtimeText.raw('origin_error_page_line_style');
|
||||
}
|
||||
|
||||
@@ -1,109 +1,5 @@
|
||||
/** 内置错误页模板:minimalist(默认) */
|
||||
const html = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{status}} | OpenFlare</title>
|
||||
<style>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
import { runtimeText } from '@/i18n/runtime';
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
||||
background-color: #ffffff;
|
||||
color: #333333;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
padding: 48px 24px;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 600px;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.error-code {
|
||||
font-size: 48px;
|
||||
font-weight: 700;
|
||||
color: #333333;
|
||||
line-height: 1.2;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.error-description {
|
||||
font-size: 20px;
|
||||
line-height: 1.6;
|
||||
color: #666666;
|
||||
max-width: 480px;
|
||||
}
|
||||
|
||||
.host {
|
||||
font-size: 14px;
|
||||
color: #999999;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.footer {
|
||||
margin-top: 48px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
color: #999999;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.brand-icon {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
fill: currentColor;
|
||||
display: block;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.error-code {
|
||||
font-size: 36px;
|
||||
}
|
||||
|
||||
.error-description {
|
||||
font-size: 18px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1 class="error-code" aria-label="HTTP status">{{status}}</h1>
|
||||
<p class="error-description">
|
||||
The upstream server is unreachable. Please try again later or contact the site administrator if the problem persists.
|
||||
</p>
|
||||
<p class="host">{{host}}</p>
|
||||
<div class="footer">
|
||||
<svg class="brand-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
||||
<path d="M13 2L3 14H12L11 22L21 10H12L13 2Z" />
|
||||
</svg>
|
||||
<span>OpenFlare</span>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
export default html;
|
||||
export default function getHTML() {
|
||||
return runtimeText.raw('origin_error_page_minimalist');
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { runtimeText } from '@/i18n/runtime';
|
||||
/** Matches pkg/render/openresty StatusCodeMin / StatusCodeMax. */
|
||||
export const STATUS_CODE_MIN = 400;
|
||||
export const STATUS_CODE_MAX = 599;
|
||||
@@ -14,7 +15,7 @@ export function parseStatusCodeTag(tag: string): {
|
||||
} {
|
||||
const trimmed = tag.trim();
|
||||
if (!trimmed) {
|
||||
throw new Error('状态码标签不能为空');
|
||||
throw new Error(runtimeText('status_code_tag_must_not_be_empty_21235ebf'));
|
||||
}
|
||||
|
||||
let lo: number;
|
||||
@@ -25,22 +26,36 @@ export function parseStatusCodeTag(tag: string): {
|
||||
lo = Number.parseInt(trimmed.slice(0, dash), 10);
|
||||
hi = Number.parseInt(trimmed.slice(dash + 1), 10);
|
||||
if (Number.isNaN(lo) || Number.isNaN(hi)) {
|
||||
throw new Error(`无效状态码区间: ${trimmed}`);
|
||||
throw new Error(
|
||||
runtimeText('invalid_status_code_range_value0_8983e96e', {
|
||||
value0: trimmed,
|
||||
}),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
lo = Number.parseInt(trimmed, 10);
|
||||
if (Number.isNaN(lo)) {
|
||||
throw new Error(`无效状态码: ${trimmed}`);
|
||||
throw new Error(
|
||||
runtimeText('invalid_status_code_value0_0f206e48', { value0: trimmed }),
|
||||
);
|
||||
}
|
||||
hi = lo;
|
||||
}
|
||||
|
||||
if (lo > hi) {
|
||||
throw new Error(`状态码区间左右端点反序: ${trimmed}`);
|
||||
throw new Error(
|
||||
runtimeText('status_code_range_endpoints_are_reversed_value0_d92c2784', {
|
||||
value0: trimmed,
|
||||
}),
|
||||
);
|
||||
}
|
||||
if (lo < STATUS_CODE_MIN || hi > STATUS_CODE_MAX) {
|
||||
throw new Error(
|
||||
`状态码须在 ${STATUS_CODE_MIN}–${STATUS_CODE_MAX}: ${trimmed}`,
|
||||
runtimeText('status_code_must_be_between_value0_value1_c5b04822', {
|
||||
value0: STATUS_CODE_MIN,
|
||||
value1: STATUS_CODE_MAX,
|
||||
value2: trimmed,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -65,18 +80,22 @@ export function validateStatusCodeTagMessage(tag: string): string | null {
|
||||
parseStatusCodeTag(tag);
|
||||
return null;
|
||||
} catch (error) {
|
||||
return error instanceof Error ? error.message : '无效状态码标签';
|
||||
return error instanceof Error
|
||||
? error.message
|
||||
: runtimeText('invalid_status_code_tag_d16e85d7');
|
||||
}
|
||||
}
|
||||
|
||||
/** Validate a full tag list before save (must be non-empty and expand cleanly). */
|
||||
export function validateStatusCodeTags(tags: string[]): void {
|
||||
if (tags.length === 0) {
|
||||
throw new Error('请至少添加一个状态码标签');
|
||||
throw new Error(runtimeText('add_at_least_one_status_code_tag_b81b2696'));
|
||||
}
|
||||
const codes = expandStatusCodeTags(tags);
|
||||
if (codes.length === 0) {
|
||||
throw new Error('状态码展开结果为空');
|
||||
throw new Error(
|
||||
runtimeText('the_expanded_status_code_list_is_empty_47245f34'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { runtimeText } from '@/i18n/runtime';
|
||||
import { resolveClientLocale } from '@/i18n/client';
|
||||
import axios, {
|
||||
AxiosError,
|
||||
AxiosResponse,
|
||||
@@ -95,6 +97,7 @@ apiClient.interceptors.request.use(
|
||||
config.baseURL = getApiBaseUrl();
|
||||
}
|
||||
config.url = normalizeApiPath(config.url);
|
||||
config.headers['Accept-Language'] ??= resolveClientLocale();
|
||||
|
||||
const requestKey = getRequestKey(config);
|
||||
const source = axios.CancelToken.source();
|
||||
@@ -152,7 +155,7 @@ apiClient.interceptors.response.use(
|
||||
/* 请求被取消时静默处理 */
|
||||
if (axios.isCancel(error)) {
|
||||
const cancelError = new Error(
|
||||
error.message || '请求已被取消',
|
||||
error.message || runtimeText('request_canceled_5892f9b1'),
|
||||
) as Error & { __CANCEL__?: boolean };
|
||||
cancelError.__CANCEL__ = true;
|
||||
return Promise.reject(cancelError);
|
||||
@@ -167,7 +170,10 @@ apiClient.interceptors.response.use(
|
||||
if (error.response?.status === 403) {
|
||||
return Promise.reject(
|
||||
new ForbiddenError(
|
||||
error.response.data?.error_msg || '权限不足,请过盾后重试',
|
||||
error.response.data?.error_msg ||
|
||||
runtimeText(
|
||||
'insufficient_permissions_complete_verification_and_try_again_73719073',
|
||||
),
|
||||
error.response.data?.error_code,
|
||||
error.response.data?.details,
|
||||
),
|
||||
@@ -177,7 +183,10 @@ apiClient.interceptors.response.use(
|
||||
/* 404 资源未找到错误 */
|
||||
if (error.response?.status === 404) {
|
||||
return Promise.reject(
|
||||
new NotFoundError(error.response.data?.error_msg || '请求的资源不存在'),
|
||||
new NotFoundError(
|
||||
error.response.data?.error_msg ||
|
||||
runtimeText('the_requested_resource_was_not_found_aecc0681'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -185,7 +194,8 @@ apiClient.interceptors.response.use(
|
||||
if (error.response?.status === 400) {
|
||||
return Promise.reject(
|
||||
new ValidationError(
|
||||
error.response.data?.error_msg || '请求参数验证失败',
|
||||
error.response.data?.error_msg ||
|
||||
runtimeText('request_parameter_validation_failed_60ef7c51'),
|
||||
error.response.data?.details,
|
||||
),
|
||||
);
|
||||
@@ -196,9 +206,13 @@ apiClient.interceptors.response.use(
|
||||
const retryAfter = error.response.headers?.['retry-after'];
|
||||
const message =
|
||||
error.response.data?.error_msg ||
|
||||
`请求过于频繁,请 ${retryAfter || '稍后'} 秒后重试`;
|
||||
(retryAfter
|
||||
? runtimeText('too_many_requests_retry_in_value0_seconds_ab5e78f1', {
|
||||
value0: retryAfter,
|
||||
})
|
||||
: runtimeText('rate_limit_retry_later'));
|
||||
|
||||
toast.error('请求频率限制', {
|
||||
toast.error(runtimeText('request_rate_limit_ad4f0f8b'), {
|
||||
description: message,
|
||||
id: 'rate-limit-error',
|
||||
});
|
||||
@@ -210,7 +224,8 @@ apiClient.interceptors.response.use(
|
||||
if (error.response && error.response.status >= 500) {
|
||||
return Promise.reject(
|
||||
new ServerError(
|
||||
error.response.data?.error_msg || '服务器内部错误,请稍后重试',
|
||||
error.response.data?.error_msg ||
|
||||
runtimeText('internal_server_error_try_again_later_4f0dd7e9'),
|
||||
error.response.status,
|
||||
),
|
||||
);
|
||||
@@ -230,7 +245,9 @@ apiClient.interceptors.response.use(
|
||||
error.message?.includes('Failed to fetch')
|
||||
) {
|
||||
return Promise.reject(
|
||||
new NetworkError('无法连接到服务器,请确认后端服务已启动'),
|
||||
new NetworkError(
|
||||
runtimeText('cannot_connect_to_the_server_check_that_5551f4fc'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -247,7 +264,11 @@ apiClient.interceptors.response.use(
|
||||
}
|
||||
|
||||
/* 兜底错误 */
|
||||
return Promise.reject(new ApiErrorBase(error.message || '网络请求失败'));
|
||||
return Promise.reject(
|
||||
new ApiErrorBase(
|
||||
error.message || runtimeText('network_request_failed_8407ceab'),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -260,7 +281,7 @@ export function cancelRequest(method: string, url: string): void {
|
||||
const requestKey = `${method.toUpperCase()}_${url}`;
|
||||
const source = cancelTokens.get(requestKey);
|
||||
if (source) {
|
||||
source.cancel('请求已被手动取消');
|
||||
source.cancel(runtimeText('request_canceled_manually_7ba622e6'));
|
||||
cancelTokens.delete(requestKey);
|
||||
}
|
||||
}
|
||||
@@ -270,7 +291,7 @@ export function cancelRequest(method: string, url: string): void {
|
||||
*/
|
||||
export function cancelAllRequests(): void {
|
||||
cancelTokens.forEach((source) => {
|
||||
source.cancel('所有请求已被取消');
|
||||
source.cancel(runtimeText('all_requests_canceled_72f8fa9a'));
|
||||
});
|
||||
cancelTokens.clear();
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { locales } from '@/i18n/config';
|
||||
import { getRuntimeTranslator, runtimeText } from '@/i18n/runtime';
|
||||
/**
|
||||
* API 错误类型定义
|
||||
*/
|
||||
@@ -22,7 +24,11 @@ export class ApiErrorBase extends Error {
|
||||
* 网络错误
|
||||
*/
|
||||
export class NetworkError extends ApiErrorBase {
|
||||
constructor(message = '网络连接失败,请检查您的网络') {
|
||||
constructor(
|
||||
message = runtimeText(
|
||||
'network_connection_failed_check_your_network_cbf47b07',
|
||||
),
|
||||
) {
|
||||
super(message);
|
||||
this.name = 'NetworkError';
|
||||
Object.setPrototypeOf(this, NetworkError.prototype);
|
||||
@@ -33,7 +39,9 @@ export class NetworkError extends ApiErrorBase {
|
||||
* 超时错误
|
||||
*/
|
||||
export class TimeoutError extends ApiErrorBase {
|
||||
constructor(message = '请求超时,请稍后重试') {
|
||||
constructor(
|
||||
message = runtimeText('request_timed_out_try_again_later_6c3465f6'),
|
||||
) {
|
||||
super(message);
|
||||
this.name = 'TimeoutError';
|
||||
Object.setPrototypeOf(this, TimeoutError.prototype);
|
||||
@@ -44,7 +52,7 @@ export class TimeoutError extends ApiErrorBase {
|
||||
* 未授权错误 (401)
|
||||
*/
|
||||
export class UnauthorizedError extends ApiErrorBase {
|
||||
constructor(message = '未授权,请先登录') {
|
||||
constructor(message = runtimeText('unauthorized_sign_in_first_466879f5')) {
|
||||
super(message, 'UNAUTHORIZED', 401);
|
||||
this.name = 'UnauthorizedError';
|
||||
Object.setPrototypeOf(this, UnauthorizedError.prototype);
|
||||
@@ -55,7 +63,11 @@ export class UnauthorizedError extends ApiErrorBase {
|
||||
* 权限不足错误 (403)
|
||||
*/
|
||||
export class ForbiddenError extends ApiErrorBase {
|
||||
constructor(message = '权限不足', code = 'FORBIDDEN', details?: unknown) {
|
||||
constructor(
|
||||
message = runtimeText('insufficient_permissions_5e3c8a26'),
|
||||
code = 'FORBIDDEN',
|
||||
details?: unknown,
|
||||
) {
|
||||
super(message, code, 403, details);
|
||||
this.name = 'ForbiddenError';
|
||||
Object.setPrototypeOf(this, ForbiddenError.prototype);
|
||||
@@ -66,7 +78,9 @@ export class ForbiddenError extends ApiErrorBase {
|
||||
* 资源未找到错误 (404)
|
||||
*/
|
||||
export class NotFoundError extends ApiErrorBase {
|
||||
constructor(message = '请求的资源不存在') {
|
||||
constructor(
|
||||
message = runtimeText('the_requested_resource_was_not_found_aecc0681'),
|
||||
) {
|
||||
super(message, 'NOT_FOUND', 404);
|
||||
this.name = 'NotFoundError';
|
||||
Object.setPrototypeOf(this, NotFoundError.prototype);
|
||||
@@ -77,7 +91,10 @@ export class NotFoundError extends ApiErrorBase {
|
||||
* 服务器错误 (5xx)
|
||||
*/
|
||||
export class ServerError extends ApiErrorBase {
|
||||
constructor(message = '服务器内部错误,请稍后重试', statusCode = 500) {
|
||||
constructor(
|
||||
message = runtimeText('internal_server_error_try_again_later_4f0dd7e9'),
|
||||
statusCode = 500,
|
||||
) {
|
||||
super(message, 'SERVER_ERROR', statusCode);
|
||||
this.name = 'ServerError';
|
||||
Object.setPrototypeOf(this, ServerError.prototype);
|
||||
@@ -88,7 +105,10 @@ export class ServerError extends ApiErrorBase {
|
||||
* 验证错误 (400)
|
||||
*/
|
||||
export class ValidationError extends ApiErrorBase {
|
||||
constructor(message = '请求参数验证失败', details?: unknown) {
|
||||
constructor(
|
||||
message = runtimeText('request_parameter_validation_failed_60ef7c51'),
|
||||
details?: unknown,
|
||||
) {
|
||||
super(message, 'VALIDATION_ERROR', 400, details);
|
||||
this.name = 'ValidationError';
|
||||
Object.setPrototypeOf(this, ValidationError.prototype);
|
||||
@@ -107,6 +127,10 @@ export function isCancelError(error: unknown): boolean {
|
||||
(('__CANCEL__' in error &&
|
||||
(error as { __CANCEL__?: boolean }).__CANCEL__ === true) ||
|
||||
('message' in error &&
|
||||
(error as { message?: string }).message === '请求已被取消'))
|
||||
locales.some(
|
||||
(locale) =>
|
||||
(error as { message?: string }).message ===
|
||||
getRuntimeTranslator(locale)('request_canceled_5892f9b1'),
|
||||
)))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { runtimeText } from '@/i18n/runtime';
|
||||
/**
|
||||
* task-param-utils.ts
|
||||
*
|
||||
@@ -46,7 +47,12 @@ function coerceParamValue(
|
||||
}
|
||||
const num = Number(trimmed);
|
||||
if (Number.isNaN(num)) {
|
||||
return { error: `「${param.label}」必须是有效的数字`, ok: false };
|
||||
return {
|
||||
error: runtimeText('value0_must_be_a_valid_number_1d79f887', {
|
||||
value0: param.label,
|
||||
}),
|
||||
ok: false,
|
||||
};
|
||||
}
|
||||
return { value: num, ok: true };
|
||||
}
|
||||
@@ -61,7 +67,12 @@ function coerceParamValue(
|
||||
} else if (val === 'false') {
|
||||
return { value: false, ok: true };
|
||||
}
|
||||
return { error: `「${param.label}」必须是 true 或 false`, ok: false };
|
||||
return {
|
||||
error: runtimeText('value0_must_be_true_or_false_23cce68e', {
|
||||
value0: param.label,
|
||||
}),
|
||||
ok: false,
|
||||
};
|
||||
}
|
||||
case 'string':
|
||||
case 'text':
|
||||
@@ -96,7 +107,12 @@ export function buildTaskPayload(
|
||||
|
||||
// 必填项空值检查
|
||||
if (param.required && raw.trim() === '') {
|
||||
return { payload: null, error: `「${param.label}」不能为空` };
|
||||
return {
|
||||
payload: null,
|
||||
error: runtimeText('value0_must_not_be_empty_8bf3a929', {
|
||||
value0: param.label,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
const result = coerceParamValue(param, raw);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { getFormattingLocale } from '@/i18n/format';
|
||||
import { runtimeText } from '@/i18n/runtime';
|
||||
import { type ClassValue, clsx } from 'clsx';
|
||||
import { twMerge } from 'tailwind-merge';
|
||||
|
||||
@@ -8,7 +10,7 @@ export function cn(...inputs: ClassValue[]) {
|
||||
export function formatDateTime(dateStr: string | Date) {
|
||||
try {
|
||||
const date = typeof dateStr === 'string' ? new Date(dateStr) : dateStr;
|
||||
return new Intl.DateTimeFormat('zh-CN', {
|
||||
return new Intl.DateTimeFormat(getFormattingLocale(), {
|
||||
timeZone: 'Asia/Shanghai',
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
@@ -61,7 +63,9 @@ export function encodeBase64(value: string): string {
|
||||
return bufferConstructor.from(value, 'utf-8').toString('base64');
|
||||
}
|
||||
|
||||
throw new Error('当前环境不支持 Base64 编码');
|
||||
throw new Error(
|
||||
runtimeText('base64_encoding_is_not_supported_in_this_7642d848'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { runtimeText } from '@/i18n/runtime';
|
||||
import { isCancelError } from '@/lib/services/core';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
@@ -9,6 +10,7 @@ interface HandleContextErrorOptions {
|
||||
showToast?: boolean;
|
||||
/** 是否在控制台记录错误 */
|
||||
logError?: boolean;
|
||||
logMessage?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,11 +39,15 @@ export function handleContextError(
|
||||
defaultMessage: string,
|
||||
options: HandleContextErrorOptions = {},
|
||||
): Error {
|
||||
const { showToast = false, logError = true } = options;
|
||||
const {
|
||||
showToast = false,
|
||||
logError = true,
|
||||
logMessage = 'Context operation failed',
|
||||
} = options;
|
||||
|
||||
// 取消的请求不算错误
|
||||
if (isCancelError(error)) {
|
||||
return new Error('请求已取消');
|
||||
return new Error(runtimeText('request_canceled_282c4cfb'));
|
||||
}
|
||||
|
||||
const errorMessage = error instanceof Error ? error.message : defaultMessage;
|
||||
@@ -49,7 +55,7 @@ export function handleContextError(
|
||||
error instanceof Error ? error : new Error(defaultMessage);
|
||||
|
||||
if (logError) {
|
||||
console.error(defaultMessage, error);
|
||||
console.error(logMessage, error);
|
||||
}
|
||||
|
||||
if (showToast) {
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
const compactNumberFormatter = new Intl.NumberFormat('zh-CN', {
|
||||
maximumFractionDigits: 1,
|
||||
});
|
||||
import { getFormattingLocale } from '@/i18n/format';
|
||||
const compactNumberFormatters = new Map<string, Intl.NumberFormat>();
|
||||
|
||||
function compactNumberFormatter() {
|
||||
const locale = getFormattingLocale();
|
||||
let formatter = compactNumberFormatters.get(locale);
|
||||
if (!formatter) {
|
||||
formatter = new Intl.NumberFormat(locale, { maximumFractionDigits: 1 });
|
||||
compactNumberFormatters.set(locale, formatter);
|
||||
}
|
||||
return formatter;
|
||||
}
|
||||
|
||||
type FormatBytesOptions = {
|
||||
emptyText?: string;
|
||||
@@ -11,7 +20,7 @@ export function formatCompactNumber(value?: number | null) {
|
||||
if (value === undefined || value === null || Number.isNaN(value)) {
|
||||
return '—';
|
||||
}
|
||||
return compactNumberFormatter.format(value);
|
||||
return compactNumberFormatter().format(value);
|
||||
}
|
||||
|
||||
export function formatPercent(value?: number | null) {
|
||||
@@ -43,7 +52,7 @@ export function formatBytes(
|
||||
}
|
||||
|
||||
const digits = current >= 100 || index === 0 ? 0 : 1;
|
||||
return `${new Intl.NumberFormat('zh-CN', {
|
||||
return `${new Intl.NumberFormat(getFormattingLocale(), {
|
||||
maximumFractionDigits: digits,
|
||||
minimumFractionDigits: 0,
|
||||
}).format(current)} ${units[index]}`;
|
||||
|
||||
@@ -35,11 +35,12 @@ export interface SearchItemSource {
|
||||
descriptionKey: string;
|
||||
url: string;
|
||||
category: 'page' | 'feature' | 'setting' | 'admin';
|
||||
keywords: string[];
|
||||
keywordKey: string;
|
||||
icon?: string;
|
||||
}
|
||||
|
||||
export interface SearchItem extends SearchItemSource {
|
||||
export interface SearchItem extends Omit<SearchItemSource, 'keywordKey'> {
|
||||
keywords: string[];
|
||||
title: string;
|
||||
description: string;
|
||||
matchRange?: [number, number];
|
||||
@@ -57,7 +58,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.homeDesc',
|
||||
url: '/',
|
||||
category: 'page',
|
||||
keywords: ['home', '主页', '首页', 'dashboard', '总览'],
|
||||
keywordKey: 'search.keywords.home',
|
||||
},
|
||||
|
||||
// ==================== 文档库 ====================
|
||||
@@ -67,7 +68,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.usageDocsDesc',
|
||||
url: 'https://openflare.fyrn.link/',
|
||||
category: 'page',
|
||||
keywords: ['docs', '文档', '使用', 'how to', 'tutorial', '教程', 'help'],
|
||||
keywordKey: 'search.keywords.docs-how-to-use',
|
||||
},
|
||||
|
||||
// ==================== 业务控制台 ====================
|
||||
@@ -77,15 +78,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.nodesDesc',
|
||||
url: '/nodes',
|
||||
category: 'page',
|
||||
keywords: [
|
||||
'node',
|
||||
'节点',
|
||||
'边缘节点',
|
||||
'中继',
|
||||
'内网穿透',
|
||||
'tunnel',
|
||||
'服务器',
|
||||
],
|
||||
keywordKey: 'search.keywords.console-nodes',
|
||||
},
|
||||
{
|
||||
id: 'console-proxy-routes',
|
||||
@@ -93,7 +86,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.proxyRoutesDesc',
|
||||
url: '/proxy-routes',
|
||||
category: 'page',
|
||||
keywords: ['route', '规则', '路由', '代理', '反向代理', 'proxy'],
|
||||
keywordKey: 'search.keywords.console-proxy-routes',
|
||||
},
|
||||
{
|
||||
id: 'console-websites',
|
||||
@@ -101,7 +94,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.websitesDesc',
|
||||
url: '/websites',
|
||||
category: 'page',
|
||||
keywords: ['website', 'domain', '网站', '域名', '站点'],
|
||||
keywordKey: 'search.keywords.console-websites',
|
||||
},
|
||||
{
|
||||
id: 'console-certificates',
|
||||
@@ -109,7 +102,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.certificatesDesc',
|
||||
url: '/certificates',
|
||||
category: 'page',
|
||||
keywords: ['certificate', 'ssl', 'tls', '证书', 'https', '加密'],
|
||||
keywordKey: 'search.keywords.console-certificates',
|
||||
},
|
||||
{
|
||||
id: 'console-dns-accounts',
|
||||
@@ -117,15 +110,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.dnsAccountsDesc',
|
||||
url: '/dns-accounts',
|
||||
category: 'page',
|
||||
keywords: [
|
||||
'dns',
|
||||
'dns account',
|
||||
'账号',
|
||||
'域名解析',
|
||||
'cloudflare',
|
||||
'aliyun',
|
||||
'tencent',
|
||||
],
|
||||
keywordKey: 'search.keywords.console-dns-accounts',
|
||||
},
|
||||
{
|
||||
id: 'console-origins',
|
||||
@@ -133,7 +118,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.originsDesc',
|
||||
url: '/origins',
|
||||
category: 'page',
|
||||
keywords: ['origin', '源站', '后端', 'backend', '服务器', '负载均衡'],
|
||||
keywordKey: 'search.keywords.console-origins',
|
||||
},
|
||||
{
|
||||
id: 'console-responses',
|
||||
@@ -141,18 +126,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.responsesDesc',
|
||||
url: '/responses',
|
||||
category: 'page',
|
||||
keywords: [
|
||||
'响应页面',
|
||||
'错误页',
|
||||
'联系页',
|
||||
'源站',
|
||||
'502',
|
||||
'503',
|
||||
'5xx',
|
||||
'Service Worker',
|
||||
'离线兜底',
|
||||
'error page',
|
||||
],
|
||||
keywordKey: 'search.keywords.console-responses',
|
||||
},
|
||||
{
|
||||
id: 'console-waf',
|
||||
@@ -160,7 +134,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.wafDesc',
|
||||
url: '/waf',
|
||||
category: 'page',
|
||||
keywords: ['waf', '防火墙', '安全', 'security', '拦截', '规则'],
|
||||
keywordKey: 'search.keywords.console-waf',
|
||||
},
|
||||
{
|
||||
id: 'console-ip-groups',
|
||||
@@ -168,7 +142,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.ipGroupsDesc',
|
||||
url: '/ip-groups',
|
||||
category: 'page',
|
||||
keywords: ['ip', 'ip group', 'ip组', '黑名单', '白名单', '访问控制'],
|
||||
keywordKey: 'search.keywords.console-ip-groups',
|
||||
},
|
||||
{
|
||||
id: 'console-rate-limits',
|
||||
@@ -176,14 +150,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.rateLimitsDesc',
|
||||
url: '/rate-limits',
|
||||
category: 'page',
|
||||
keywords: [
|
||||
'限流',
|
||||
'rate limit',
|
||||
'limit_conn',
|
||||
'limit_rate',
|
||||
'并发',
|
||||
'带宽',
|
||||
],
|
||||
keywordKey: 'search.keywords.console-rate-limits',
|
||||
},
|
||||
{
|
||||
id: 'console-pages',
|
||||
@@ -191,7 +158,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.pagesDesc',
|
||||
url: '/pages',
|
||||
category: 'page',
|
||||
keywords: ['pages', '静态托管', 'cdn', '网站', '部署', 'static'],
|
||||
keywordKey: 'search.keywords.console-pages',
|
||||
},
|
||||
{
|
||||
id: 'console-config-versions',
|
||||
@@ -199,7 +166,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.configVersionsDesc',
|
||||
url: '/config-versions',
|
||||
category: 'page',
|
||||
keywords: ['version', 'config', '版本', '发布', '回滚', '对比', '部署'],
|
||||
keywordKey: 'search.keywords.console-config-versions',
|
||||
},
|
||||
{
|
||||
id: 'console-access-logs',
|
||||
@@ -207,7 +174,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.accessLogsDesc',
|
||||
url: '/access-logs',
|
||||
category: 'page',
|
||||
keywords: ['log', 'logs', '访问日志', '分析', '流量', '请求'],
|
||||
keywordKey: 'search.keywords.console-access-logs',
|
||||
},
|
||||
{
|
||||
id: 'console-apply-logs',
|
||||
@@ -215,15 +182,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.applyLogsDesc',
|
||||
url: '/apply-logs',
|
||||
category: 'page',
|
||||
keywords: [
|
||||
'apply',
|
||||
'log',
|
||||
'logs',
|
||||
'应用记录',
|
||||
'配置下发',
|
||||
'同步',
|
||||
'部署历史',
|
||||
],
|
||||
keywordKey: 'search.keywords.console-apply-logs',
|
||||
},
|
||||
{
|
||||
id: 'console-performance',
|
||||
@@ -231,7 +190,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.performanceDesc',
|
||||
url: '/performance',
|
||||
category: 'page',
|
||||
keywords: ['performance', '性能', '调优', '优化', '参数', '连接', '超时'],
|
||||
keywordKey: 'search.keywords.console-performance',
|
||||
},
|
||||
|
||||
// ==================== 个人设置 ====================
|
||||
@@ -241,7 +200,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.settingsDesc',
|
||||
url: '/settings',
|
||||
category: 'setting',
|
||||
keywords: ['settings', '设置', '偏好', 'preferences'],
|
||||
keywordKey: 'search.keywords.settings',
|
||||
},
|
||||
{
|
||||
id: 'settings-profile',
|
||||
@@ -249,7 +208,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.profileDesc',
|
||||
url: '/settings/profile',
|
||||
category: 'setting',
|
||||
keywords: ['profile', '资料', '个人', '我的', '信息', 'avatar'],
|
||||
keywordKey: 'search.keywords.settings-profile',
|
||||
},
|
||||
{
|
||||
id: 'settings-appearance',
|
||||
@@ -257,7 +216,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.appearanceDesc',
|
||||
url: '/settings/appearance',
|
||||
category: 'setting',
|
||||
keywords: ['appearance', '外观', '主题', 'theme', 'dark', 'light'],
|
||||
keywordKey: 'search.keywords.settings-appearance',
|
||||
},
|
||||
{
|
||||
id: 'admin-settings',
|
||||
@@ -265,15 +224,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.adminSettingsDesc',
|
||||
url: '/admin/settings',
|
||||
category: 'admin',
|
||||
keywords: [
|
||||
'admin',
|
||||
'管理员',
|
||||
'系统设置',
|
||||
'安全',
|
||||
'security',
|
||||
'oidc',
|
||||
'login',
|
||||
],
|
||||
keywordKey: 'search.keywords.admin-settings',
|
||||
},
|
||||
{
|
||||
id: 'admin-system',
|
||||
@@ -281,7 +232,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.systemDesc',
|
||||
url: '/admin/system',
|
||||
category: 'admin',
|
||||
keywords: ['admin', '管理员', '系统', '配置', 'system', 'configurations'],
|
||||
keywordKey: 'search.keywords.admin-system',
|
||||
},
|
||||
{
|
||||
id: 'admin-users',
|
||||
@@ -289,7 +240,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.usersDesc',
|
||||
url: '/admin/users',
|
||||
category: 'admin',
|
||||
keywords: ['admin', '管理员', '用户', '管理', 'users', 'status'],
|
||||
keywordKey: 'search.keywords.admin-users',
|
||||
},
|
||||
{
|
||||
id: 'admin-tasks',
|
||||
@@ -297,15 +248,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.tasksDesc',
|
||||
url: '/admin/tasks',
|
||||
category: 'admin',
|
||||
keywords: [
|
||||
'admin',
|
||||
'管理员',
|
||||
'任务',
|
||||
'异步',
|
||||
'tasks',
|
||||
'scheduler',
|
||||
'worker',
|
||||
],
|
||||
keywordKey: 'search.keywords.admin-tasks',
|
||||
},
|
||||
{
|
||||
id: 'admin-files',
|
||||
@@ -313,7 +256,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.storageDesc',
|
||||
url: '/admin/files',
|
||||
category: 'admin',
|
||||
keywords: ['admin', '管理员', '存储', '文件', 'files', 'upload', 's3'],
|
||||
keywordKey: 'search.keywords.admin-files',
|
||||
},
|
||||
{
|
||||
id: 'admin-database',
|
||||
@@ -321,7 +264,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.databaseDesc',
|
||||
url: '/admin/database',
|
||||
category: 'admin',
|
||||
keywords: ['admin', '管理员', '数据库', 'database', 'sql', 'query', 'gorm'],
|
||||
keywordKey: 'search.keywords.admin-database',
|
||||
},
|
||||
{
|
||||
id: 'admin-push',
|
||||
@@ -329,16 +272,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.pushDesc',
|
||||
url: '/admin/push',
|
||||
category: 'admin',
|
||||
keywords: [
|
||||
'admin',
|
||||
'管理员',
|
||||
'推送',
|
||||
'通知',
|
||||
'push',
|
||||
'mail',
|
||||
'telegram',
|
||||
'lark',
|
||||
],
|
||||
keywordKey: 'search.keywords.admin-push',
|
||||
},
|
||||
{
|
||||
id: 'admin-logs',
|
||||
@@ -346,7 +280,7 @@ export const searchData: SearchItemSource[] = [
|
||||
descriptionKey: 'search.items.logsDesc',
|
||||
url: '/admin/logs',
|
||||
category: 'admin',
|
||||
keywords: ['admin', '管理员', '日志', 'logs', 'system log', 'terminal'],
|
||||
keywordKey: 'search.keywords.admin-logs',
|
||||
},
|
||||
];
|
||||
|
||||
@@ -369,10 +303,11 @@ export function searchItems(
|
||||
? searchData
|
||||
: searchData.filter((item) => item.category !== 'admin');
|
||||
|
||||
const resolved = filteredData.map((item) => ({
|
||||
const resolved: SearchItem[] = filteredData.map((item) => ({
|
||||
...item,
|
||||
title: t(item.titleKey),
|
||||
description: t(item.descriptionKey),
|
||||
keywords: t(item.keywordKey).split('|'),
|
||||
}));
|
||||
|
||||
if (!trimmedQuery) {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { formatSystemMetric } from './system-metrics';
|
||||
|
||||
describe('system metric presentation', () => {
|
||||
it('formats live values and legacy concatenated English durations', () => {
|
||||
expect(formatSystemMetric(50425, 'ru')).toBe('50\u00a0425');
|
||||
expect(formatSystemMetric('28 minutes41 seconds', 'ru')).toBe(
|
||||
'28 мин 41 с',
|
||||
);
|
||||
expect(formatSystemMetric('1 day 2 hours', 'ru')).toBe('1 дн. 2 ч');
|
||||
expect(formatSystemMetric('28 minutes41 seconds', 'en')).toBe('28m 41s');
|
||||
expect(formatSystemMetric('43 seconds', 'zh-CN')).toBe('43秒');
|
||||
expect(formatSystemMetric('5.8 MiB', 'ru')).toBe('5,8 MiB');
|
||||
expect(formatSystemMetric('0.001s', 'ru')).toBe('0,001 с');
|
||||
expect(formatSystemMetric('None', 'ru')).toBe('Нет');
|
||||
expect(formatSystemMetric('custom metric 42', 'ru')).toBe(
|
||||
'custom metric 42',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
import type { AppLocale } from '@/i18n/config';
|
||||
import { getRuntimeTranslator } from '@/i18n/runtime';
|
||||
|
||||
const durationKeys = {
|
||||
day: 'system_metric_day',
|
||||
hour: 'system_metric_hour',
|
||||
minute: 'system_metric_minute',
|
||||
second: 'system_metric_second',
|
||||
} as const;
|
||||
|
||||
// The status API owns these English diagnostic values. Localize their display
|
||||
// without changing the raw values used by memory calculations or other clients.
|
||||
export function formatSystemMetric(
|
||||
value: string | number,
|
||||
locale: AppLocale,
|
||||
): string {
|
||||
const number = (n: number, digits = 0) =>
|
||||
new Intl.NumberFormat(locale, {
|
||||
minimumFractionDigits: digits,
|
||||
maximumFractionDigits: Math.max(digits, 3),
|
||||
}).format(n);
|
||||
if (typeof value === 'number') return number(value);
|
||||
const t = getRuntimeTranslator(locale);
|
||||
if (value === 'Unknown') return t('system_metric_unknown');
|
||||
if (value === 'None') return t('system_metric_none');
|
||||
const size = /^(\d+(?:\.\d+)?) (B|KiB|MiB|GiB|TiB)$/.exec(value);
|
||||
if (size) return `${number(Number(size[1]))} ${size[2]}`;
|
||||
const seconds = /^(\d+(?:\.\d+)?)s$/.exec(value);
|
||||
if (seconds) {
|
||||
const digits = seconds[1].split('.')[1]?.length ?? 0;
|
||||
return t('system_metric_second', {
|
||||
count: number(Number(seconds[1]), digits),
|
||||
});
|
||||
}
|
||||
const parts = [
|
||||
...value.matchAll(/(\d+)\s*(days?|hours?|minutes?|seconds?)/g),
|
||||
];
|
||||
if (
|
||||
!parts.length ||
|
||||
parts
|
||||
.map((part) => part[0])
|
||||
.join('')
|
||||
.replaceAll(/\s/g, '') !== value.replaceAll(/\s/g, '')
|
||||
)
|
||||
return value;
|
||||
return parts
|
||||
.map((part) => {
|
||||
const unit = part[2].replace(/s$/, '') as keyof typeof durationKeys;
|
||||
return t(durationKeys[unit], { count: number(Number(part[1])) });
|
||||
})
|
||||
.join(' ');
|
||||
}
|
||||
Reference in New Issue
Block a user