tmwgsicp-wechat-download-api/static/admin.html

772 lines
27 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WeChat Download API</title>
<style>
:root {
--primary-color: #1890ff;
--success-color: #52c41a;
--warning-color: #fa8c16;
--error-color: #ff4d4f;
--text-primary: #262626;
--text-secondary: #595959;
--text-muted: #8c8c8c;
--bg-primary: #ffffff;
--bg-secondary: #fafafa;
--border-light: #f0f0f0;
--border-base: #d9d9d9;
--shadow-light: 0 2px 8px rgba(0, 0, 0, 0.06);
--shadow-base: 0 4px 12px rgba(0, 0, 0, 0.08);
--radius-small: 4px;
--radius-base: 8px;
--radius-large: 12px;
--font-xs: 12px;
--font-sm: 14px;
--font-base: 16px;
--font-lg: 20px;
--font-xl: 24px;
--space-xs: 4px;
--space-sm: 8px;
--space-md: 16px;
--space-lg: 24px;
--space-xl: 32px;
--duration-fast: 200ms;
--duration-normal: 300ms;
--ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', sans-serif;
background: var(--bg-secondary);
color: var(--text-primary);
line-height: 1.6;
min-height: 100vh;
}
.layout {
max-width: 1080px;
margin: 0 auto;
padding: var(--space-xl) var(--space-lg);
}
/* Header */
.header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: var(--space-xl);
}
.header-left h1 {
font-size: var(--font-xl);
font-weight: 700;
color: var(--text-primary);
}
.header-left p {
font-size: var(--font-sm);
color: var(--text-secondary);
margin-top: var(--space-xs);
}
.version-tag {
font-size: var(--font-xs);
color: var(--text-muted);
background: var(--border-light);
padding: 2px 10px;
border-radius: 10px;
font-weight: 500;
}
/* Status Card */
.status-card {
background: var(--bg-primary);
border: 1px solid var(--border-light);
border-radius: var(--radius-large);
box-shadow: var(--shadow-light);
padding: var(--space-lg);
margin-bottom: var(--space-lg);
display: flex;
align-items: center;
gap: var(--space-md);
}
.status-icon {
width: 48px;
height: 48px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.status-icon.online {
background: rgba(82, 196, 26, 0.1);
}
.status-icon.offline {
background: rgba(255, 77, 79, 0.1);
}
.status-icon.loading {
background: var(--border-light);
}
.status-icon svg {
width: 24px;
height: 24px;
}
.status-info {
flex: 1;
min-width: 0;
}
.status-info .label {
font-size: var(--font-xs);
color: var(--text-muted);
text-transform: uppercase;
letter-spacing: 0.5px;
margin-bottom: 2px;
}
.status-info .value {
font-size: var(--font-base);
font-weight: 600;
color: var(--text-primary);
}
.status-info .detail {
font-size: var(--font-xs);
color: var(--text-secondary);
margin-top: 2px;
}
.status-actions {
display: flex;
gap: var(--space-sm);
flex-shrink: 0;
}
.btn-sm {
padding: 6px 16px;
border-radius: var(--radius-base);
font-size: var(--font-xs);
font-weight: 600;
cursor: pointer;
border: 1px solid var(--border-base);
background: var(--bg-primary);
color: var(--text-primary);
transition: all var(--duration-fast) var(--ease-in-out);
white-space: nowrap;
}
.btn-sm:hover {
border-color: var(--primary-color);
color: var(--primary-color);
}
.btn-sm.btn-primary {
background: var(--primary-color);
color: #fff;
border-color: var(--primary-color);
}
.btn-sm.btn-primary:hover {
background: #096dd9;
border-color: #096dd9;
}
.btn-sm.btn-danger {
color: var(--error-color);
border-color: var(--error-color);
}
.btn-sm.btn-danger:hover {
background: var(--error-color);
color: #fff;
}
/* Grid */
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: var(--space-md);
margin-bottom: var(--space-lg);
}
@media (max-width: 768px) {
.grid { grid-template-columns: 1fr; }
.layout { padding: var(--space-lg) var(--space-md); }
.header { flex-direction: column; align-items: flex-start; gap: var(--space-sm); }
.status-card { flex-direction: column; text-align: center; }
.status-actions { width: 100%; justify-content: center; }
}
@media (min-width: 769px) and (max-width: 1024px) {
.grid { grid-template-columns: repeat(2, 1fr); }
}
/* Card */
.card {
background: var(--bg-primary);
border: 1px solid var(--border-light);
border-radius: var(--radius-large);
box-shadow: var(--shadow-light);
padding: var(--space-lg);
transition: box-shadow var(--duration-normal) var(--ease-in-out);
}
.card:hover {
box-shadow: var(--shadow-base);
}
.card-header {
display: flex;
align-items: center;
gap: var(--space-sm);
margin-bottom: var(--space-md);
}
.card-icon {
width: 36px;
height: 36px;
border-radius: var(--radius-base);
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.card-icon svg {
width: 20px;
height: 20px;
}
.card-icon.blue { background: rgba(24, 144, 255, 0.1); color: var(--primary-color); }
.card-icon.green { background: rgba(82, 196, 26, 0.1); color: var(--success-color); }
.card-icon.orange { background: rgba(250, 140, 22, 0.1); color: var(--warning-color); }
.card-title {
font-size: var(--font-sm);
font-weight: 600;
color: var(--text-primary);
}
.card-desc {
font-size: var(--font-xs);
color: var(--text-muted);
}
/* Nav List */
.nav-list {
list-style: none;
}
.nav-list li + li {
margin-top: var(--space-sm);
}
.nav-list a {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 12px;
color: var(--text-primary);
text-decoration: none;
font-size: var(--font-sm);
border-radius: var(--radius-base);
transition: all var(--duration-fast) var(--ease-in-out);
background: var(--bg-secondary);
}
.nav-list a:hover {
background: rgba(24, 144, 255, 0.06);
color: var(--primary-color);
}
.nav-list .arrow {
color: var(--text-muted);
font-size: var(--font-xs);
transition: transform var(--duration-fast) var(--ease-in-out);
}
.nav-list a:hover .arrow {
transform: translateX(4px);
color: var(--primary-color);
}
/* Test Section */
.test-section {
grid-column: 1 / -1;
}
.test-input-group {
display: flex;
gap: var(--space-sm);
}
.test-input-group input {
flex: 1;
padding: 10px 14px;
border: 1px solid var(--border-base);
border-radius: var(--radius-base);
font-size: var(--font-sm);
color: var(--text-primary);
outline: none;
transition: border-color var(--duration-fast) var(--ease-in-out);
}
.test-input-group input::placeholder {
color: var(--border-base);
}
.test-input-group input:focus {
border-color: var(--primary-color);
box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.1);
}
.btn {
padding: 10px 24px;
border: none;
border-radius: var(--radius-base);
font-size: var(--font-sm);
font-weight: 600;
cursor: pointer;
white-space: nowrap;
transition: all var(--duration-fast) var(--ease-in-out);
}
.btn-primary {
background: var(--primary-color);
color: #fff;
}
.btn-primary:hover {
background: #096dd9;
}
/* Result */
.result-panel {
margin-top: var(--space-md);
border-radius: var(--radius-base);
border: 1px solid var(--border-light);
overflow: hidden;
display: none;
}
.result-panel.visible { display: block; }
.result-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 16px;
background: var(--bg-secondary);
border-bottom: 1px solid var(--border-light);
}
.result-header .tag {
font-size: var(--font-xs);
font-weight: 600;
}
.result-header .tag.success { color: var(--success-color); }
.result-header .tag.error { color: var(--error-color); }
.result-header .time {
font-size: var(--font-xs);
color: var(--text-muted);
}
.result-body {
padding: var(--space-md);
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
font-size: var(--font-xs);
max-height: 400px;
overflow: auto;
white-space: pre-wrap;
word-break: break-all;
color: var(--text-secondary);
line-height: 1.7;
}
.result-meta {
padding: 10px 16px;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
gap: var(--space-sm);
border-bottom: 1px solid var(--border-light);
background: var(--bg-primary);
}
.result-meta-item .k {
font-size: 11px;
color: var(--text-muted);
}
.result-meta-item .v {
font-size: var(--font-sm);
font-weight: 600;
color: var(--text-primary);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* Footer */
.footer {
margin-top: var(--space-xl);
padding-top: var(--space-md);
border-top: 1px solid var(--border-light);
display: flex;
align-items: center;
justify-content: space-between;
font-size: var(--font-xs);
color: var(--text-muted);
}
.footer a {
color: var(--text-muted);
text-decoration: none;
transition: color var(--duration-fast) var(--ease-in-out);
}
.footer a:hover { color: var(--primary-color); }
.footer-links {
display: flex;
gap: var(--space-md);
}
/* Loading */
.loading-spinner {
display: inline-block;
width: 14px;
height: 14px;
border: 2px solid var(--border-light);
border-top-color: var(--primary-color);
border-radius: 50%;
animation: spin 0.6s linear infinite;
vertical-align: middle;
margin-right: 6px;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.tip {
margin-top: var(--space-sm);
padding: 10px 14px;
background: rgba(250, 140, 22, 0.06);
border-left: 3px solid var(--warning-color);
border-radius: 0 var(--radius-small) var(--radius-small) 0;
font-size: var(--font-xs);
color: var(--text-secondary);
line-height: 1.8;
}
</style>
</head>
<body>
<div class="layout">
<!-- Header -->
<div class="header">
<div class="header-left">
<h1>WeChat Download API</h1>
<p>微信公众号文章获取服务</p>
</div>
<span class="version-tag">v1.0.0</span>
</div>
<!-- Status -->
<div class="status-card" id="statusCard">
<div class="status-icon loading" id="statusIcon">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"/>
<line x1="12" y1="8" x2="12" y2="12"/>
<line x1="12" y1="16" x2="12.01" y2="16"/>
</svg>
</div>
<div class="status-info">
<div class="label">登录状态</div>
<div class="value" id="statusValue">检查中...</div>
<div class="detail" id="statusDetail"></div>
</div>
<div class="status-actions" id="statusActions">
<button class="btn-sm" onclick="checkStatus()">刷新</button>
</div>
</div>
<!-- Cards Grid -->
<div class="grid">
<!-- Quick Actions -->
<div class="card">
<div class="card-header">
<div class="card-icon blue">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M15 3h4a2 2 0 012 2v14a2 2 0 01-2 2h-4"/>
<polyline points="10 17 15 12 10 7"/>
<line x1="15" y1="12" x2="3" y2="12"/>
</svg>
</div>
<div>
<div class="card-title">快捷操作</div>
<div class="card-desc">登录与验证</div>
</div>
</div>
<ul class="nav-list">
<li><a href="/login.html"><span>扫码登录</span><span class="arrow">&#8250;</span></a></li>
<li><a href="/verify.html"><span>验证处理</span><span class="arrow">&#8250;</span></a></li>
<li><a href="/rss.html"><span>RSS 订阅</span><span class="arrow">&#8250;</span></a></li>
</ul>
</div>
<!-- API Docs -->
<div class="card">
<div class="card-header">
<div class="card-icon green">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/>
<polyline points="14 2 14 8 20 8"/>
<line x1="16" y1="13" x2="8" y2="13"/>
<line x1="16" y1="17" x2="8" y2="17"/>
<polyline points="10 9 9 9 8 9"/>
</svg>
</div>
<div>
<div class="card-title">接口文档</div>
<div class="card-desc">在线调试 API</div>
</div>
</div>
<ul class="nav-list">
<li><a href="/api/docs" target="_blank"><span>Swagger UI</span><span class="arrow">&#8250;</span></a></li>
<li><a href="/api/redoc" target="_blank"><span>ReDoc</span><span class="arrow">&#8250;</span></a></li>
</ul>
</div>
<!-- System -->
<div class="card">
<div class="card-header">
<div class="card-icon orange">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect x="2" y="3" width="20" height="14" rx="2" ry="2"/>
<line x1="8" y1="21" x2="16" y2="21"/>
<line x1="12" y1="17" x2="12" y2="21"/>
</svg>
</div>
<div>
<div class="card-title">系统</div>
<div class="card-desc">监控与调试</div>
</div>
</div>
<ul class="nav-list">
<li><a href="/api/health" target="_blank"><span>健康检查</span><span class="arrow">&#8250;</span></a></li>
<li><a href="/api/stats" target="_blank"><span>限频统计</span><span class="arrow">&#8250;</span></a></li>
</ul>
</div>
<!-- Test -->
<div class="card test-section">
<div class="card-header">
<div class="card-icon blue">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="16 18 22 12 16 6"/>
<polyline points="8 6 2 12 8 18"/>
</svg>
</div>
<div>
<div class="card-title">接口测试</div>
<div class="card-desc">输入文章 URL 测试获取功能</div>
</div>
</div>
<div class="test-input-group">
<input type="text" id="testUrl" placeholder="https://mp.weixin.qq.com/s/xxxxx">
<button class="btn btn-primary" id="testBtn" onclick="testArticle()">获取文章</button>
</div>
<div class="result-panel" id="resultPanel">
<div class="result-header">
<span class="tag" id="resultTag"></span>
<span class="time" id="resultTime"></span>
</div>
<div class="result-meta" id="resultMeta" style="display:none;"></div>
<div class="result-body" id="resultBody"></div>
</div>
</div>
</div>
<!-- Footer -->
<div class="footer">
<span>WeChat Download API v1.0.0</span>
<div class="footer-links">
<a href="/api/openapi.json" target="_blank">OpenAPI</a>
<a href="https://github.com/tmwgsicp/wechat-download-api" target="_blank">GitHub</a>
</div>
</div>
</div>
<script>
async function checkStatus() {
var icon = document.getElementById('statusIcon');
var val = document.getElementById('statusValue');
var detail = document.getElementById('statusDetail');
var actions = document.getElementById('statusActions');
icon.className = 'status-icon loading';
icon.innerHTML = '<svg viewBox="0 0 24 24" fill="none" stroke="#8c8c8c" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>';
val.textContent = '检查中...';
detail.textContent = '';
try {
var res = await fetch('/api/admin/status');
var data = await res.json();
if (data.authenticated) {
icon.className = 'status-icon online';
icon.innerHTML = '<svg viewBox="0 0 24 24" fill="none" stroke="#52c41a" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 11-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>';
val.textContent = data.nickname || data.account || '已登录';
var detailParts = [];
if (data.fakeid) detailParts.push('FakeID: ' + data.fakeid);
if (data.isExpired) {
detailParts.push('凭证可能已过期');
icon.className = 'status-icon offline';
icon.innerHTML = '<svg viewBox="0 0 24 24" fill="none" stroke="#fa8c16" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>';
} else {
detailParts.push(data.status);
}
detail.textContent = detailParts.join(' · ');
actions.innerHTML =
'<button class="btn-sm" onclick="checkStatus()">刷新</button>' +
'<button class="btn-sm btn-danger" onclick="doLogout()">退出登录</button>';
} else {
icon.className = 'status-icon offline';
icon.innerHTML = '<svg viewBox="0 0 24 24" fill="none" stroke="#ff4d4f" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>';
val.textContent = '未登录';
detail.textContent = '请先扫码登录后使用 API';
actions.innerHTML =
'<button class="btn-sm" onclick="checkStatus()">刷新</button>' +
'<a href="/login.html" class="btn-sm btn-primary" style="text-decoration:none;display:inline-block;">去登录</a>';
}
} catch (e) {
icon.className = 'status-icon offline';
icon.innerHTML = '<svg viewBox="0 0 24 24" fill="none" stroke="#ff4d4f" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>';
val.textContent = '连接失败';
detail.textContent = e.message;
actions.innerHTML = '<button class="btn-sm" onclick="checkStatus()">重试</button>';
}
}
async function doLogout() {
if (!confirm('确定退出登录?退出后需要重新扫码。')) return;
var val = document.getElementById('statusValue');
var actions = document.getElementById('statusActions');
val.textContent = '正在退出...';
actions.innerHTML = '';
try {
var res = await fetch('/api/admin/logout', { method: 'POST' });
var data = await res.json();
if (data.success) {
await checkStatus();
} else {
val.textContent = '退出失败';
actions.innerHTML = '<button class="btn-sm" onclick="checkStatus()">刷新</button>';
}
} catch (e) {
val.textContent = '退出失败: ' + e.message;
actions.innerHTML = '<button class="btn-sm" onclick="checkStatus()">刷新</button>';
}
}
async function testArticle() {
var url = document.getElementById('testUrl').value.trim();
var panel = document.getElementById('resultPanel');
var tag = document.getElementById('resultTag');
var timeEl = document.getElementById('resultTime');
var meta = document.getElementById('resultMeta');
var body = document.getElementById('resultBody');
var btn = document.getElementById('testBtn');
if (!url) return;
panel.className = 'result-panel visible';
meta.style.display = 'none';
tag.className = 'tag';
tag.textContent = '';
timeEl.textContent = '';
body.innerHTML = '<span class="loading-spinner"></span>正在获取文章...';
btn.disabled = true;
btn.textContent = '获取中...';
var startTime = Date.now();
try {
var res = await fetch('/api/article', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url: url })
});
var data = await res.json();
var elapsed = Date.now() - startTime;
timeEl.textContent = elapsed + 'ms';
if (data.success && data.data) {
tag.className = 'tag success';
tag.textContent = '成功';
var d = data.data;
meta.style.display = 'grid';
meta.innerHTML = '';
var fields = [
['标题', d.title || '-'],
['作者', d.author || '-'],
['时间', d.publish_time_str || (d.publish_time ? new Date(d.publish_time * 1000).toLocaleString('zh-CN') : '-')],
['正文', d.content ? d.content.length + ' 字符' : '-'],
['图片', d.images ? d.images.length + ' 张' : '0']
];
fields.forEach(function (f) {
meta.innerHTML += '<div class="result-meta-item"><div class="k">' + f[0] + '</div><div class="v">' + f[1] + '</div></div>';
});
body.textContent = JSON.stringify(data, null, 2);
} else {
tag.className = 'tag error';
tag.textContent = '失败';
meta.style.display = 'none';
var msg = data.error || '未知错误';
body.textContent = msg + '\n\n' + JSON.stringify(data, null, 2);
}
} catch (e) {
tag.className = 'tag error';
tag.textContent = '错误';
body.textContent = '请求失败: ' + e.message;
}
btn.disabled = false;
btn.textContent = '获取文章';
}
document.getElementById('testUrl').addEventListener('keydown', function (e) {
if (e.key === 'Enter') testArticle();
});
window.addEventListener('load', checkStatus);
</script>
</body>
</html>