feat: 初始提交(仅核心代码,已排除大文件)
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,164 @@
|
||||
(() => {
|
||||
const originalFetch = window.fetch;
|
||||
window.fetch = (input, init = {}) => {
|
||||
const opts = Object.assign({}, init);
|
||||
if (!opts.credentials) opts.credentials = 'include';
|
||||
return originalFetch(input, opts);
|
||||
};
|
||||
const overlayId = 'authOverlay';
|
||||
const ensureOverlay = () => {
|
||||
let ov = document.getElementById(overlayId);
|
||||
if (ov) return ov;
|
||||
ov = document.createElement('div');
|
||||
ov.id = overlayId;
|
||||
ov.style.position = 'fixed';
|
||||
ov.style.left = '0'; ov.style.top = '0'; ov.style.right = '0'; ov.style.bottom = '0';
|
||||
ov.style.display = 'none';
|
||||
ov.style.alignItems = 'center';
|
||||
ov.style.justifyContent = 'center';
|
||||
ov.style.background = 'rgba(0,0,0,0.6)';
|
||||
ov.style.zIndex = '9999';
|
||||
const panel = document.createElement('div');
|
||||
panel.style.background = '#fff';
|
||||
panel.style.padding = '20px';
|
||||
panel.style.borderRadius = '8px';
|
||||
panel.style.boxShadow = '0 4px 12px rgba(0,0,0,0.2)';
|
||||
const title = document.createElement('div');
|
||||
title.textContent = '鉴权失败,请重新校验';
|
||||
title.style.fontSize = '16px';
|
||||
title.style.marginBottom = '12px';
|
||||
title.style.color = '#333';
|
||||
const debug = document.createElement('pre');
|
||||
debug.id = 'authDebug';
|
||||
debug.style.fontSize = '12px';
|
||||
debug.style.lineHeight = '1.5';
|
||||
debug.style.background = '#f7f7f8';
|
||||
debug.style.border = '1px solid #e3e3e7';
|
||||
debug.style.padding = '10px';
|
||||
debug.style.margin = '0 0 12px 0';
|
||||
debug.style.maxWidth = '520px';
|
||||
debug.style.maxHeight = '240px';
|
||||
debug.style.overflow = 'auto';
|
||||
debug.textContent = '正在收集诊断信息...';
|
||||
const btn = document.createElement('button');
|
||||
btn.textContent = '重新校验';
|
||||
btn.style.padding = '8px 16px';
|
||||
btn.addEventListener('click', async () => {
|
||||
await handshake();
|
||||
});
|
||||
panel.appendChild(title);
|
||||
panel.appendChild(debug);
|
||||
panel.appendChild(btn);
|
||||
ov.appendChild(panel);
|
||||
document.body.appendChild(ov);
|
||||
return ov;
|
||||
};
|
||||
const showOverlay = () => { ensureOverlay().style.display = 'flex'; };
|
||||
const hideOverlay = () => { const ov = ensureOverlay(); ov.style.display = 'none'; };
|
||||
let cfg = { enableCookieAuth: true, cookieName: 'picker_jwt' };
|
||||
const loadConfig = async () => {
|
||||
try {
|
||||
const res = await fetch('assets/auth_config.json', { cache: 'no-store' });
|
||||
if (!res.ok) return;
|
||||
const data = await res.json();
|
||||
cfg = Object.assign({}, cfg, data || {});
|
||||
} catch (_) {}
|
||||
};
|
||||
const debugState = {
|
||||
url: '',
|
||||
config: {},
|
||||
tokenInUrl: false,
|
||||
tokenCall: { tried: false, ok: false, status: 0 },
|
||||
handshake: { tried: false, ok: false, status: 0 },
|
||||
server: {}
|
||||
};
|
||||
const removeTokenFromUrl = () => {
|
||||
try {
|
||||
const nu = new URL(window.location.href);
|
||||
nu.searchParams.delete('token');
|
||||
window.history.replaceState(null, document.title, nu.toString());
|
||||
} catch (_) {}
|
||||
};
|
||||
const handleTokenInUrl = async () => {
|
||||
try {
|
||||
const u = new URL(window.location.href);
|
||||
const token = u.searchParams.get('token');
|
||||
debugState.url = u.toString();
|
||||
debugState.config = { enableCookieAuth: !!cfg.enableCookieAuth, cookieName: String(cfg.cookieName || '') };
|
||||
debugState.tokenInUrl = !!token;
|
||||
if (token) {
|
||||
if (cfg.enableCookieAuth) {
|
||||
const r = await fetch(`/auth/token?token=${encodeURIComponent(token)}`, { method: 'GET' });
|
||||
debugState.tokenCall.tried = true;
|
||||
debugState.tokenCall.ok = r.ok;
|
||||
debugState.tokenCall.status = r.status || 0;
|
||||
removeTokenFromUrl();
|
||||
return r.ok;
|
||||
} else {
|
||||
removeTokenFromUrl();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (_) {}
|
||||
return true;
|
||||
};
|
||||
const handshake = async () => {
|
||||
if (!cfg.enableCookieAuth) { hideOverlay(); return true; }
|
||||
try {
|
||||
const r = await fetch('/auth/handshake', { cache: 'no-store' });
|
||||
debugState.handshake.tried = true;
|
||||
debugState.handshake.ok = r.ok;
|
||||
debugState.handshake.status = r.status || 0;
|
||||
try {
|
||||
const dbgRes = await fetch('/auth/debug', { cache: 'no-store' });
|
||||
if (dbgRes.ok) {
|
||||
debugState.server = await dbgRes.json();
|
||||
} else {
|
||||
debugState.server = { error: 'debug endpoint unavailable', status: dbgRes.status || 0 };
|
||||
}
|
||||
} catch (e) {
|
||||
debugState.server = { error: 'debug request failed' };
|
||||
}
|
||||
const box = document.getElementById('authDebug');
|
||||
if (box) {
|
||||
const lines = [];
|
||||
lines.push(`URL: ${debugState.url}`);
|
||||
lines.push(`Config: enableCookieAuth=${debugState.config.enableCookieAuth} cookieName=${debugState.config.cookieName}`);
|
||||
lines.push(`TokenInUrl: ${debugState.tokenInUrl}`);
|
||||
lines.push(`TokenCall: tried=${debugState.tokenCall.tried} ok=${debugState.tokenCall.ok} status=${debugState.tokenCall.status}`);
|
||||
lines.push(`Handshake: tried=${debugState.handshake.tried} ok=${debugState.handshake.ok} status=${debugState.handshake.status}`);
|
||||
if (debugState.server && typeof debugState.server === 'object') {
|
||||
lines.push(`Server.enableAuth: ${debugState.server.enableAuth}`);
|
||||
lines.push(`Server.jwkLoaded: ${debugState.server.jwkLoaded}`);
|
||||
lines.push(`Server.cookieName: ${debugState.server.cookieName}`);
|
||||
lines.push(`Server.cookiePresent: ${debugState.server.cookiePresent}`);
|
||||
lines.push(`Server.verified: ${debugState.server.verified}`);
|
||||
const rq = debugState.server.request || {};
|
||||
lines.push(`Server.request.host: ${rq.host || ''}`);
|
||||
lines.push(`Server.request.path: ${rq.path || ''}`);
|
||||
lines.push(`Server.request.origin: ${rq.origin || ''}`);
|
||||
lines.push(`Server.request.secFetchMode: ${rq.secFetchMode || ''}`);
|
||||
lines.push(`Server.request.forwardedProto: ${rq.forwardedProto || ''}`);
|
||||
lines.push(`Server.request.secure: ${rq.secure}`);
|
||||
lines.push(`Server.request.proto: ${rq.proto || ''}`);
|
||||
} else {
|
||||
lines.push(`Server: ${String(debugState.server)}`);
|
||||
}
|
||||
lines.push(`Expected URLs: /auth/token?token=... , /auth/handshake , /api/...`);
|
||||
box.textContent = lines.join('\n');
|
||||
}
|
||||
if (r.ok) { hideOverlay(); return true; }
|
||||
showOverlay(); return false;
|
||||
} catch (_) { showOverlay(); return false; }
|
||||
};
|
||||
const init = async () => {
|
||||
await loadConfig();
|
||||
await handleTokenInUrl();
|
||||
await handshake();
|
||||
};
|
||||
if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
||||
init();
|
||||
} else {
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,153 @@
|
||||
:root {
|
||||
--bg: #0b0e11;
|
||||
--card: #151a21;
|
||||
--text: #e5eaf0;
|
||||
--muted: #9aa7b2;
|
||||
--primary: #3b82f6;
|
||||
--secondary: #64748b;
|
||||
--accent: #22c55e;
|
||||
--warn: #f59e0b;
|
||||
--danger: #ef4444;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
html, body { height: 100%; }
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.app-header { padding: 20px 16px 10px; border-bottom: 1px solid #1f2630; }
|
||||
.app-header h1 { margin: 0 0 8px; font-size: 20px; }
|
||||
.disclaimer { margin: 0; color: var(--muted); font-size: 13px; }
|
||||
|
||||
.tabs { display: flex; gap: 8px; padding: 10px 16px; border-bottom: 1px solid #1f2630; position: sticky; top: 0; background: var(--bg); z-index: 10; }
|
||||
.tab-btn {
|
||||
background: #11161d;
|
||||
color: var(--text);
|
||||
border: 1px solid #1f2630;
|
||||
border-radius: 6px;
|
||||
padding: 8px 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.tab-btn.active { background: var(--primary); border-color: var(--primary); }
|
||||
|
||||
main { padding: 16px; }
|
||||
.tab-panel { margin-bottom: 16px; }
|
||||
.hidden { display: none; }
|
||||
|
||||
h2 { font-size: 18px; margin: 0 0 10px; }
|
||||
h3 { font-size: 16px; margin: 0 0 10px; }
|
||||
h4 { font-size: 15px; margin: 0 0 8px; }
|
||||
|
||||
.card {
|
||||
background: var(--card);
|
||||
border: 1px solid #223043;
|
||||
border-radius: 10px;
|
||||
padding: 12px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
|
||||
.gap { gap: 10px; }
|
||||
.col { flex: 1; min-width: 260px; }
|
||||
|
||||
input[type="text"], input[type="number"], select {
|
||||
background: #0f141a;
|
||||
border: 1px solid #334155;
|
||||
color: var(--text);
|
||||
padding: 8px 10px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
input[type="file"] { color: var(--text); }
|
||||
|
||||
button {
|
||||
background: var(--primary);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
padding: 8px 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
button.secondary { background: var(--secondary); }
|
||||
button.ghost { background: transparent; border: 1px solid #334155; color: var(--text); }
|
||||
button.ghost.danger { border-color: var(--danger); color: var(--danger); }
|
||||
|
||||
.bars { display: grid; grid-template-columns: repeat(1, minmax(250px, 1fr)); gap: 6px; }
|
||||
.bar-row { display: flex; align-items: center; gap: 8px; }
|
||||
.bar-label { width: 40px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
|
||||
.bar {
|
||||
height: 18px;
|
||||
background: #0e1620;
|
||||
border: 1px solid #2b3b52;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
flex: 1;
|
||||
}
|
||||
.bar-fill { height: 100%; background: var(--accent); }
|
||||
.bar-value { width: 38px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
|
||||
|
||||
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
|
||||
.grid-item { background: #0e1620; border: 1px solid #2b3b52; border-radius: 6px; padding: 6px; text-align: center; }
|
||||
.grid-item .n { display: block; color: var(--muted); font-size: 12px; }
|
||||
.grid-item .v { display: block; font-variant-numeric: tabular-nums; font-size: 14px; }
|
||||
|
||||
.summary { display: grid; grid-template-columns: repeat(2, minmax(220px, 1fr)); gap: 8px; }
|
||||
.summary-item { background: #0e1620; border: 1px solid #2b3b52; border-radius: 6px; padding: 8px; }
|
||||
.summary-item h5 { margin: 0 0 6px; font-size: 14px; color: var(--muted); }
|
||||
.summary-item .content { font-variant-numeric: tabular-nums; }
|
||||
|
||||
.list { display: grid; grid-template-columns: repeat(1, minmax(260px, 1fr)); gap: 6px; }
|
||||
.ticket { background: #0e1620; border: 1px solid #2b3b52; border-radius: 8px; padding: 8px; }
|
||||
.ticket .title { color: var(--muted); margin-bottom: 6px; font-size: 13px; }
|
||||
.nums { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
.ball { background: #182231; color: #fff; border-radius: 999px; padding: 6px 8px; font-variant-numeric: tabular-nums; }
|
||||
.ball.back {
|
||||
background: transparent; /* 改为空心圆 */
|
||||
border: 1px solid #6e5aa1; /* 1px 圆边(偏紫,与原色系协调) */
|
||||
}
|
||||
|
||||
.result { display: flex; gap: 18px; align-items: center; margin-top: 8px; }
|
||||
.muted { color: var(--muted); }
|
||||
.warn { color: var(--warn); }
|
||||
.danger { color: var(--danger); }
|
||||
|
||||
.switch { display: inline-flex; align-items: center; gap: 6px; }
|
||||
|
||||
.app-footer { padding: 20px 16px; border-top: 1px solid #1f2630; color: var(--muted); text-align: center; }
|
||||
|
||||
.log {
|
||||
background: #0e1620;
|
||||
border: 1px solid #2b3b52;
|
||||
border-radius: 6px;
|
||||
padding: 8px;
|
||||
max-height: 200px;
|
||||
overflow: auto;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.paste {
|
||||
width: 100%;
|
||||
background: #0f141a;
|
||||
border: 1px solid #334155;
|
||||
color: var(--text);
|
||||
border-radius: 6px;
|
||||
padding: 8px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
|
||||
}
|
||||
|
||||
@media (min-width: 800px) {
|
||||
.bars { grid-template-columns: repeat(2, minmax(360px, 1fr)); }
|
||||
.list { grid-template-columns: repeat(2, minmax(320px, 1fr)); }
|
||||
}
|
||||
|
||||
@media print {
|
||||
body { background: #fff; color: #000; }
|
||||
.tabs, .app-footer, .disclaimer, .switch, button, input, select { display: none !important; }
|
||||
.card { border: 1px solid #999; }
|
||||
}
|
||||
Reference in New Issue
Block a user