chore: 初始提交 - 移除所有硬编码凭据,统一从环境变量读取

This commit is contained in:
yangxiangyuan
2026-06-11 17:10:58 +08:00
commit c223c79b36
1699 changed files with 313940 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+164
View File
@@ -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,9 @@
{
"_comment": "大乐透选号(dlt_draws)工具的鉴权配置",
"cookieName_comment": "用于识别已登录用户的 JWT cookie 名称",
"cookieName": "picker_jwt",
"enableCookieAuth_comment": "true:启用基于 cookie 的鉴权;false:不校验登录状态",
"enableCookieAuth": true,
"max_age_days_comment": "JWT cookie 的最大有效天数(1~365)",
"max_age_days": 30
}
+3
View File
@@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<text y=".9em" font-size="90">🎲</text>
</svg>

After

Width:  |  Height:  |  Size: 113 B

+153
View File
@@ -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; }
}
+256
View File
@@ -0,0 +1,256 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>智能投注辅助系统(仅供参考)</title>
<link rel="icon" href="/assets/picker.svg" type="image/svg+xml" />
<link rel="stylesheet" href="assets/style.css" />
<script>
window.API_BASE = '/api/dlt';
</script>
</head>
<body>
<header class="app-header">
<h1>超级大乐透智能投注辅助系统</h1>
<p class="disclaimer">
本系统用于数据分析与选号参考,严格遵循国家彩票管理条例,不承诺中奖,不支持自动投注或下单功能。
所有投注需前往官方销售网点完成。未成年人不得购彩,请理性参与,量力而行。
</p>
</header>
<nav class="tabs">
<button class="tab-btn active" data-target="data">数据管理</button>
<button class="tab-btn" data-target="ingest">官网数据解析入库</button>
<button class="tab-btn" data-target="analysis">智能分析</button>
<button class="tab-btn" data-target="picker">选号推荐</button>
<button class="tab-btn" data-target="calculator">投注计算器</button>
<button class="tab-btn" data-target="export">结果导出</button>
</nav>
<main>
<!-- 数据管理模块 -->
<section id="data" class="tab-panel">
<h2>数据采集与更新</h2>
<div class="card">
<div class="row gap">
<input type="file" id="csvFile" accept=".csv" />
<button id="btnImport">导入CSV</button>
<button id="btnClear" class="secondary">清空本地数据</button>
<button id="btnTemplate" class="ghost">下载CSV模板</button>
<button id="btnFetchSina" class="secondary">官网抓取中奖数据</button>
<button id="btnExportDraws" class="ghost danger">导出CSV</button>
</div>
<p class="muted">CSV字段:期号, 开奖日期, 前区, 后区, 奖池资金。示例:2024001, 2024-01-01, "01 02 03 04 05", "06 12", 100000000</p>
<div class="row">
<label>分析周期(最近期数)</label>
<input type="number" id="periodWindow" min="1" value="50" />
<button id="btnRefresh">更新分析</button>
</div>
<div class="row">
<span>本地已保存期数:<strong id="drawCount">0</strong></span>
<span>最近一期:<strong id="latestIssue">-</strong></span>
</div>
<div class="row gap">
<button id="btnLogClear" class="ghost">清空日志</button>
</div>
<h3>抓取日志</h3>
<pre id="fetchLog" class="log" aria-live="polite"></pre>
</div>
</section>
<!-- 官网数据解析入库模块 -->
<section id="ingest" class="tab-panel hidden">
<h2>官网数据解析入库</h2>
<div class="card">
<h3>备用方式:粘贴官网页面源码解析。网址是https://www.lottery.gov.cn/kj/kjlb.html?dlt</h3>
<p class="muted">可粘贴“查看源代码”或你复制的纯文本表格行(支持如下格式:期号 日期 前区(5) 后区(2) 其他列)。</p>
<textarea id="htmlPaste" class="paste" rows="10" placeholder="粘贴官网页面源代码或纯文本行,例如:\n25127\t2025-11-08\t04\t05\t19\t28\t29\t05\t08\t36 ..."></textarea>
<div class="row gap">
<button id="btnParseHtml" class="secondary">解析并入库</button>
<button id="btnParsePlain" class="secondary">解析纯文本并入库</button>
</div>
</div>
</section>
<!-- 智能分析模块 -->
<section id="analysis" class="tab-panel hidden">
<h2>基础统计分析</h2>
<div class="card">
<h3>号码冷热(前区 01-35)</h3>
<div id="frontFreq" class="bars"></div>
<h3>号码冷热(后区 01-12)</h3>
<div id="backFreq" class="bars"></div>
</div>
<div class="card">
<h3>号码遗漏</h3>
<div class="row">
<div class="col">
<h4>前区遗漏</h4>
<div id="frontMiss" class="grid"></div>
</div>
<div class="col">
<h4>后区遗漏</h4>
<div id="backMiss" class="grid"></div>
</div>
</div>
</div>
<div class="card">
<h3>和值、奇偶、大小、区间分布</h3>
<div id="summaryStats" class="summary"></div>
<div class="row gap">
<label>大小阈值(前区)</label>
<input type="number" id="frontSizeThreshold" value="18" />
<label>大小阈值(后区)</label>
<input type="number" id="backSizeThreshold" value="6" />
<button id="btnRecompute">重新统计</button>
</div>
</div>
</section>
<!-- 选号策略与推荐模块 -->
<section id="picker" class="tab-panel hidden">
<h2>选号策略与推荐</h2>
<div class="card">
<h3>随机选号</h3>
<div class="row gap">
<label>生成组数</label>
<input type="number" id="randomCount" min="1" value="3" />
<button id="btnRandom">生成随机号码</button>
</div>
<div id="randomOutput" class="list"></div>
</div>
<div class="card">
<h3>智能选号(偏好设置)</h3>
<div class="row gap">
<label>偏好热号(0-100)</label>
<input type="range" id="hotPref" min="0" max="100" value="60" />
<span id="hotPrefVal">60</span>
<label>偏好冷号(0-100)</label>
<input type="range" id="coldPref" min="0" max="100" value="40" />
<span id="coldPrefVal">40</span>
</div>
<div class="row gap">
<label>奇偶比(前区)</label>
<select id="parityFront">
<option value="3-2">3:2</option>
<option value="2-3">2:3</option>
<option value="4-1">4:1</option>
<option value="1-4">1:4</option>
</select>
<label>大小比(前区)</label>
<select id="sizeFront">
<option value="3-2">3:2</option>
<option value="2-3">2:3</option>
</select>
</div>
<div class="row gap">
<label>生成组数</label>
<input type="number" id="smartCount" min="1" value="3" />
<button id="btnSmart">生成智能推荐</button>
</div>
<div id="smartOutput" class="list"></div>
</div>
<div class="card">
<h3>AI快速五组号码(基于历史分析,仅供参考)</h3>
<div class="row gap">
<button id="btnQuickAI">DeepSeek智能五组号码</button>
<button id="btnQuickChatGPT">ChatGPT智能五组号码</button>
<button id="btnQuickKimi2">Kimi2智能五组号码</button>
<button id="btnQuickDoubao">豆包智能五组号码</button>
</div>
<div id="aiQuickOutput" class="list"></div>
</div>
</section>
<!-- 投注计算器模块 -->
<section id="calculator" class="tab-panel hidden">
<h2>投注计算器</h2>
<div class="card">
<div class="row gap">
<label>投注方式</label>
<select id="betType">
<option value="single">单式</option>
<option value="multiple">复式</option>
<option value="dantuo">胆拖</option>
</select>
<label class="switch">
<input type="checkbox" id="extraAdd" />
<span>追加投注</span>
</label>
</div>
<!-- 单式 -->
<div id="singleForm" class="form">
<div class="row gap">
<label>前区(5个,用逗号分隔)</label>
<input type="text" id="singleFront" placeholder="如:01,08,12,23,31" />
<label>后区(2个)</label>
<input type="text" id="singleBack" placeholder="如:03,09" />
<button id="btnCalcSingle">计算金额</button>
</div>
</div>
<!-- 复式 -->
<div id="multipleForm" class="form hidden">
<div class="row gap">
<label>前区(≥5个)</label>
<input type="text" id="multiFront" placeholder="如:01,08,12,23,31,35" />
<label>后区(≥2个)</label>
<input type="text" id="multiBack" placeholder="如:03,09,12" />
<button id="btnCalcMultiple">计算金额</button>
</div>
</div>
<!-- 胆拖 -->
<div id="dantuoForm" class="form hidden">
<div class="row gap">
<label>前区胆(1-4个)</label>
<input type="text" id="dtFrontDan" placeholder="如:01,08" />
<label>前区拖(≥1个)</label>
<input type="text" id="dtFrontTuo" placeholder="如:12,23,31" />
</div>
<div class="row gap">
<label>后区胆(0-1个)</label>
<input type="text" id="dtBackDan" placeholder="如:03" />
<label>后区拖(≥2个)</label>
<input type="text" id="dtBackTuo" placeholder="如:09,12" />
<button id="btnCalcDantuo">计算金额</button>
</div>
</div>
<div class="result">
<div>注数:<strong id="betCount">0</strong></div>
<div>金额:<strong id="betAmount">0</strong> 元</div>
<div class="muted">价格说明:基本每注2元,追加每注3元。</div>
<div class="warn" id="ticketLimitWarn" hidden>金额较高,可能超出单票打印限制,请分票购买。</div>
</div>
</div>
</section>
<!-- 导出模块 -->
<section id="export" class="tab-panel hidden">
<h2>结果导出</h2>
<div class="card">
<div class="row gap">
<button id="btnExportCSV">导出推荐为CSV</button>
<button id="btnPrint">打印/另存为PDF</button>
</div>
<p class="muted">提示:CSV可用Excel直接打开;打印可选择“另存为PDF”。</p>
<div id="exportPreview" class="list"></div>
</div>
</section>
</main>
<footer class="app-footer">
<small>© 智能投注辅助系统 · 仅供参考,请理性购彩</small>
</footer>
<script src="/assets/auth.js"></script>
<script src="assets/app.js"></script>
</body>
</html>