重构媒体解析流程并完善相关功能

This commit is contained in:
ucmao
2026-09-08 09:34:14 +08:00
parent ea32e2e9d4
commit bdb64769d4
10 changed files with 2127 additions and 292 deletions
+121 -12
View File
@@ -269,9 +269,99 @@ def get_daily_trend(user_id=None, days=7):
for idx, item in enumerate(daily_stats):
item["show_label"] = (idx % step == 0) or (idx == num_points - 1)
y_max = max_val if max_val > 0 else 10
if y_max < 5:
y_max = 5
def _calc_nice_ticks(mv, top_m=20, h=160):
if mv <= 0:
ym = 10
raw_ticks = [10, 8, 6, 4, 2, 0]
elif mv <= 3:
ym = 3
raw_ticks = [3, 2, 1, 0]
elif mv <= 5:
ym = 5
raw_ticks = [5, 4, 3, 2, 1, 0]
elif mv <= 8:
ym = 8
raw_ticks = [8, 6, 4, 2, 0]
elif mv <= 12:
ym = 12
raw_ticks = [12, 9, 6, 3, 0]
elif mv <= 15:
ym = 15
raw_ticks = [15, 12, 9, 6, 3, 0]
elif mv <= 20:
ym = 20
raw_ticks = [20, 15, 10, 5, 0]
elif mv <= 30:
ym = 30
raw_ticks = [30, 24, 18, 12, 6, 0]
elif mv <= 50:
ym = math.ceil(mv / 10) * 10
step = 10 if ym <= 30 else (ym // 5)
raw_ticks = list(range(ym, -1, -step))
if raw_ticks[-1] != 0:
raw_ticks.append(0)
elif mv <= 100:
ym = math.ceil(mv / 10) * 10
step = max(10, ym // 5)
raw_ticks = list(range(ym, -1, -step))
if raw_ticks[-1] != 0:
raw_ticks.append(0)
else:
mag = 10 ** math.floor(math.log10(mv))
norm = mv / mag
if norm <= 1.5:
step = int(0.25 * mag) if mag >= 10 else 1
ym = int(1.5 * mag)
elif norm <= 2.0:
step = int(0.4 * mag) if mag >= 10 else 1
ym = int(2.0 * mag)
elif norm <= 5.0:
step = int(0.5 * mag) if mag >= 10 else 1
ym = int(math.ceil(norm) * mag)
else:
step = int(1.0 * mag) if mag >= 10 else 1
ym = int(math.ceil(norm / 2) * 2 * mag)
raw_ticks = list(range(ym, -1, -step))
if raw_ticks[-1] != 0:
raw_ticks.append(0)
ticks = []
for v in raw_ticks:
y_pos = round(top_m + h * (1 - v / ym), 1)
ticks.append({
"val": f"{v:,}",
"raw_val": v,
"y": y_pos,
})
return ym, ticks
def _points_to_bezier_path(coords, min_y=20, max_y=180, tension=0.2):
if not coords:
return ""
if len(coords) == 1:
return f"M {coords[0][0]:.1f} {coords[0][1]:.1f}"
if len(coords) == 2:
return f"M {coords[0][0]:.1f} {coords[0][1]:.1f} L {coords[1][0]:.1f} {coords[1][1]:.1f}"
path = [f"M {coords[0][0]:.1f} {coords[0][1]:.1f}"]
n = len(coords)
for i in range(n - 1):
p0 = coords[max(0, i - 1)]
p1 = coords[i]
p2 = coords[i + 1]
p3 = coords[min(n - 1, i + 2)]
if p1[1] == max_y and p2[1] == max_y:
path.append(f"L {p2[0]:.1f} {p2[1]:.1f}")
continue
cp1x = p1[0] + (p2[0] - p0[0]) * tension
cp1y = max(min_y, min(max_y, p1[1] + (p2[1] - p0[1]) * tension))
cp2x = p2[0] - (p3[0] - p1[0]) * tension
cp2y = max(min_y, min(max_y, p2[1] - (p3[1] - p1[1]) * tension))
path.append(f"C {cp1x:.1f} {cp1y:.1f}, {cp2x:.1f} {cp2y:.1f}, {p2[0]:.1f} {p2[1]:.1f}")
return " ".join(path)
width = 620
height = 160
@@ -279,6 +369,10 @@ def get_daily_trend(user_id=None, days=7):
top_margin = 20
bottom_y = top_margin + height
y_max, y_ticks = _calc_nice_ticks(max_val, top_margin, height)
coords_calls = []
coords_successes = []
points_calls = []
points_successes = []
@@ -289,14 +383,22 @@ def get_daily_trend(user_id=None, days=7):
item["x"] = x
item["y_calls"] = y_c
item["y_successes"] = y_s
coords_calls.append((x, y_c))
coords_successes.append((x, y_s))
points_calls.append(f"{x},{y_c}")
points_successes.append(f"{x},{y_s}")
calls_line = " ".join(points_calls)
successes_line = " ".join(points_successes)
calls_path = _points_to_bezier_path(coords_calls, min_y=top_margin, max_y=bottom_y)
successes_path = _points_to_bezier_path(coords_successes, min_y=top_margin, max_y=bottom_y)
first_x = daily_stats[0]["x"]
last_x = daily_stats[-1]["x"]
calls_area_path = f"{calls_path} L {last_x:.1f} {bottom_y:.1f} L {first_x:.1f} {bottom_y:.1f} Z"
successes_area_path = f"{successes_path} L {last_x:.1f} {bottom_y:.1f} L {first_x:.1f} {bottom_y:.1f} Z"
calls_line = " ".join(points_calls)
successes_line = " ".join(points_successes)
calls_area = f"{first_x},{bottom_y} {calls_line} {last_x},{bottom_y}"
successes_area = f"{first_x},{bottom_y} {successes_line} {last_x},{bottom_y}"
@@ -304,15 +406,15 @@ def get_daily_trend(user_id=None, days=7):
"trend": daily_stats,
"max_val": max_val,
"y_max": y_max,
"calls_path": calls_path,
"successes_path": successes_path,
"calls_area_path": calls_area_path,
"successes_area_path": successes_area_path,
"calls_line": calls_line,
"successes_line": successes_line,
"calls_area": calls_area,
"successes_area": successes_area,
"y_ticks": [
{"val": y_max, "y": top_margin},
{"val": round(y_max / 2), "y": top_margin + height / 2},
{"val": 0, "y": bottom_y},
],
"y_ticks": y_ticks,
}
@@ -343,13 +445,17 @@ def get_platform_distribution(user_id=None, days=7):
PALETTE = [
"#4f46e5", "#10b981", "#f59e0b", "#ec4899", "#8b5cf6",
"#06b6d4", "#ef4444", "#3b82f6", "#14b8a6", "#f97316",
"#64748b", "#84cc16", "#d946ef", "#6366f1"
"#6366f1", "#84cc16", "#d946ef", "#0284c7", "#e11d48",
"#7c3aed", "#059669", "#d97706", "#2563eb", "#db2777",
"#0891b2", "#ea580c", "#475569", "#65a30d", "#9333ea",
"#0d9488", "#c026d3", "#4338ca", "#16a34a", "#ca8a04",
"#e11d48", "#2563eb", "#7c2d12", "#4b5563", "#047857", "#b45309"
]
items = []
if total_calls > 0:
cx, cy = 100, 100
r_out, r_in = 80, 50
r_out, r_in = 86, 62
current_angle = 0.0 # radians
for idx, row in enumerate(rows):
@@ -390,6 +496,7 @@ def get_platform_distribution(user_id=None, days=7):
items.append({
"platform": name,
"calls": calls,
"calls_formatted": f"{calls:,}",
"successes": successes,
"percentage": percentage,
"color": color,
@@ -398,6 +505,8 @@ def get_platform_distribution(user_id=None, days=7):
return {
"total_calls": total_calls,
"total_calls_formatted": f"{total_calls:,}",
"platform_count": len(rows),
"items": items,
}
+1 -1
View File
@@ -109,7 +109,7 @@ def export_logs():
def generate():
writer = csv.writer(_CsvRowBuffer())
yield "\ufeff"
yield writer.writerow(("时间(北京时间)", "客户", "Key Prefix", "平台", "请求路径", "脱敏 URL", "状态码", "耗时(毫秒)", "错误码"))
yield writer.writerow(("时间", "客户", "Key Prefix", "平台", "请求路径", "脱敏 URL", "状态码", "耗时(毫秒)", "错误码"))
cursor = get_db().execute(
"SELECT l.*, u.username, k.key_prefix FROM request_logs l "
"LEFT JOIN users u ON u.id=l.user_id LEFT JOIN api_keys k ON k.id=l.api_key_id "
+1 -1
View File
@@ -82,7 +82,7 @@ def export_logs():
def generate():
writer = csv.writer(_CsvRowBuffer())
yield "\ufeff"
yield writer.writerow(("时间(北京时间)", "平台", "请求路径", "脱敏 URL", "状态码", "耗时(毫秒)", "错误码"))
yield writer.writerow(("时间", "平台", "请求路径", "脱敏 URL", "状态码", "耗时(毫秒)", "错误码"))
cursor = get_db().execute(
"SELECT * FROM request_logs WHERE user_id=? ORDER BY id DESC",
(g.user["id"],),
+1600 -180
View File
File diff suppressed because it is too large Load Diff
+67 -40
View File
@@ -14,12 +14,41 @@
<span class="badge">超级管理员</span>
</div>
<div class="stats">
<div class="card stat"><span class="muted">24 小时总调用</span><strong>{{ stats['calls'] or 0 }}</strong></div>
<div class="card stat"><span class="muted">成功调用</span><strong>{{ stats['successes'] or 0 }}</strong></div>
<div class="card stat"><span class="muted">活跃客户数</span><strong>{{ stats['users'] or 0 }}</strong></div>
<div class="card stat"><span class="muted">API 服务状态</span><strong
style="font-size:20px;margin-top:14px;color:{{ '#10b981' if settings.get('global_api_enabled')=='1' else '#ef4444' }}">{{
'正常服务' if settings.get('global_api_enabled')=='1' else '已暂停' }}</strong></div>
<div class="card stat">
<div class="stat-head">
<span class="stat-label">24 小时总调用</span>
<span class="stat-icon">{{ icon('chart') }}</span>
</div>
<strong>{{ stats['calls'] or 0 }}</strong>
<span class="stat-foot">近 24 小时接口请求</span>
</div>
<div class="card stat">
<div class="stat-head">
<span class="stat-label">成功调用</span>
<span class="stat-icon">{{ icon('check') }}</span>
</div>
<strong>{{ stats['successes'] or 0 }}</strong>
<span class="stat-foot">有效完成媒体直链解析</span>
</div>
<div class="card stat">
<div class="stat-head">
<span class="stat-label">活跃客户数</span>
<span class="stat-icon">{{ icon('users') }}</span>
</div>
<strong>{{ stats['users'] or 0 }}</strong>
<span class="stat-foot">已开通客户账号总数</span>
</div>
<div class="card stat">
<div class="stat-head">
<span class="stat-label">API 服务状态</span>
<span class="stat-icon">{{ icon('shield') }}</span>
</div>
<strong
style="font-size:22px;color:{{ '#059669' if settings.get('global_api_enabled')=='1' else '#dc2626' }}">
{{ '正常服务' if settings.get('global_api_enabled')=='1' else '已暂停' }}
</strong>
<span class="stat-foot">全局对外解析接口响应</span>
</div>
</div>
<!-- 动态周期筛选栏 -->
@@ -72,50 +101,46 @@
<!-- Y 轴网格辅助线与刻度 -->
{% for tick in chart_data['y_ticks'] %}
<line x1="50" y1="{{ tick['y'] }}" x2="670" y2="{{ tick['y'] }}" stroke="#f1f5f9" stroke-width="1"
stroke-dasharray="4 4" />
<text x="42" y="{{ tick['y'] + 4 }}" text-anchor="end" font-size="11" fill="#94a3b8">{{ tick['val']
}}</text>
<line x1="45" y1="{{ tick['y'] }}" x2="675" y2="{{ tick['y'] }}" stroke="#f1f5f9" stroke-width="0.8"
stroke-dasharray="3 3" />
<text x="38" y="{{ tick['y'] + 3.5 }}" text-anchor="end" font-size="9.5" fill="#94a3b8">{{ tick['val'] }}</text>
{% endfor %}
<!-- X 轴基线 -->
<line x1="50" y1="180" x2="670" y2="180" stroke="#e2e8f0" stroke-width="1" />
<line x1="45" y1="180" x2="675" y2="180" stroke="#e2e8f0" stroke-width="0.9" />
<!-- 鼠标悬浮对齐线 -->
<line class="chart-guide-line" x1="0" y1="20" x2="0" y2="180" stroke="#818cf8" stroke-width="1.2"
<line class="chart-guide-line" x1="0" y1="20" x2="0" y2="180" stroke="#818cf8" stroke-width="1"
stroke-dasharray="3 3" style="display:none;pointer-events:none" />
<!-- 渐变填充面 -->
<polygon points="{{ chart_data['calls_area'] }}" fill="url(#callsGradAdmin)" />
<polygon points="{{ chart_data['successes_area'] }}" fill="url(#succGradAdmin)" />
<!-- 平滑渐变填充面 -->
<path d="{{ chart_data['calls_area_path'] }}" fill="url(#callsGradAdmin)" />
<path d="{{ chart_data['successes_area_path'] }}" fill="url(#succGradAdmin)" />
<!-- 趋势平滑折线 -->
<polyline points="{{ chart_data['calls_line'] }}" fill="none" stroke="#4f46e5" stroke-width="1.8"
<!-- 趋势平滑贝塞尔曲线 (纤细大厂风格) -->
<path d="{{ chart_data['calls_path'] }}" fill="none" stroke="#4f46e5" stroke-width="1.5"
stroke-linecap="round" stroke-linejoin="round" />
<polyline points="{{ chart_data['successes_line'] }}" fill="none" stroke="#10b981"
stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" />
<path d="{{ chart_data['successes_path'] }}" fill="none" stroke="#10b981" stroke-width="1.3"
stroke-linecap="round" stroke-linejoin="round" />
<!-- 动态悬停聚焦光晕圆点 (初始隐藏) -->
<circle class="chart-hover-dot calls-dot" cx="0" cy="0" r="3.5" fill="#4f46e5" stroke="#ffffff"
stroke-width="1.8" style="display:none;pointer-events:none" />
<circle class="chart-hover-dot succ-dot" cx="0" cy="0" r="3" fill="#10b981" stroke="#ffffff"
stroke-width="1.6" style="display:none;pointer-events:none" />
<!-- X 轴刻度与交互节点 -->
{% for item in chart_data['trend'] %}
{% if item['show_label'] %}
<text x="{{ item['x'] }}" y="200" text-anchor="middle" font-size="10" fill="#94a3b8">{{
item['short_date'] }}</text>
<text x="{{ item['x'] }}" y="198" text-anchor="middle" font-size="9.5" font-weight="450" fill="#94a3b8">{{ item['short_date'] }}</text>
{% endif %}
<!-- 透明列触控透明矩形 -->
<rect class="chart-col-trigger" x="{{ item['x'] - 20 }}" y="20" width="40" height="160"
<rect class="chart-col-trigger" x="{{ item['x'] - 20 }}" y="15" width="40" height="170"
fill="transparent" style="cursor:pointer" data-date="{{ item['date'] }}"
data-calls="{{ item['calls'] }}" data-successes="{{ item['successes'] }}"
data-failures="{{ item['failures'] }}" data-cx="{{ item['x'] }}"
data-cy-calls="{{ item['y_calls'] }}" data-cy-succ="{{ item['y_successes'] }}" />
<!-- 总调用量节点 -->
<circle cx="{{ item['x'] }}" cy="{{ item['y_calls'] }}" r="3.5" fill="#ffffff" stroke="#4f46e5"
stroke-width="1.8" class="point-circle" style="pointer-events:none" />
<!-- 成功调用量节点 -->
<circle cx="{{ item['x'] }}" cy="{{ item['y_successes'] }}" r="2.5" fill="#ffffff" stroke="#10b981"
stroke-width="1.8" class="point-circle" style="pointer-events:none" />
{% endfor %}
</svg>
</div>
@@ -143,30 +168,29 @@
<div>当前时间范围内暂无调用记录</div>
</div>
{% else %}
<div class="pie-wrapper">
<div class="pie-wrapper" id="admin-platform-dist">
<div class="pie-svg-box">
<svg viewBox="0 0 200 200" style="width:100%;height:100%">
{% for item in pie_data['items'] %}
<path d="{{ item['path_d'] }}" fill="{{ item['color'] }}" class="pie-slice"
data-platform="{{ item['platform'] }}" data-calls="{{ item['calls'] }}"
data-platform="{{ item['platform'] }}" data-calls="{{ item['calls_formatted'] }}"
data-percent="{{ item['percentage'] }}%">
<title>{{ item['platform'] }}: {{ item['calls'] }} 次 ({{ item['percentage'] }}%)</title>
<title>{{ item['platform'] }}: {{ item['calls_formatted'] }} 次 ({{ item['percentage'] }}%)</title>
</path>
{% endfor %}
</svg>
<div class="pie-center-text">
<div class="pie-center-val">{{ pie_data['total_calls'] }}</div>
<div class="pie-center-lbl">总解析量</div>
<div class="pie-center-lbl" id="admin-pie-lbl">总解析量</div>
<div class="pie-center-val" id="admin-pie-val">{{ pie_data['total_calls_formatted'] or pie_data['total_calls'] }} 次</div>
</div>
</div>
<!-- 下方平铺胶囊图例 -->
<!-- 下方自适应平铺胶囊图例网格 (支持50+平台) -->
<div class="pie-pill-grid">
{% for item in pie_data['items'] %}
<div class="pie-pill-item">
<div class="pie-pill-item" data-platform="{{ item['platform'] }}" data-calls="{{ item['calls_formatted'] }}" data-percent="{{ item['percentage'] }}%" title="{{ item['platform'] }}: {{ item['calls_formatted'] }} 次 ({{ item['percentage'] }}%)">
<span class="pie-pill-dot" style="background:{{ item['color'] }}"></span>
<span class="pie-pill-name">{{ item['platform'] }}</span>
<span class="pie-pill-val">{{ item['percentage'] }}%</span>
</div>
{% endfor %}
</div>
@@ -198,7 +222,10 @@
{% for item in top_users %}
<div class="ranking-item">
<div class="ranking-head">
<span class="ranking-name">{{ item['username'] }}</span>
<span class="ranking-name">
<span class="ranking-badge">{{ loop.index }}</span>
{{ item['username'] }}
</span>
<span class="ranking-val">{{ item['calls'] }} 次</span>
</div>
<div class="ranking-bar-bg">
@@ -682,7 +709,7 @@
<table style="width:100%;min-width:1080px">
<thead>
<tr>
<th>时间(北京时间)</th>
<th>时间</th>
<th>客户 / Key Prefix</th>
<th>平台</th>
<th>脱敏 URL</th>
+57 -5
View File
@@ -1,5 +1,57 @@
{% extends 'base_console.html' %}{% block title %}登录{% endblock %}{% block body %}
<main class="auth-wrap"><div class="auth-card"><div class="card"><h1 class="title">登录控制台</h1><p class="subtitle">管理你的 API Key 和调用记录。</p>
{% for category,message in get_flashed_messages(with_categories=true) %}<div class="flash {{ category }}">{{ message }}</div>{% endfor %}
<form method="post"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><div class="field"><label>用户名</label><input name="username" autocomplete="username" required></div><div class="field"><label>密码</label><input name="password" type="password" autocomplete="current-password" required></div><button class="btn btn-primary btn-block">登录</button></form>
<p class="muted" style="text-align:center;font-size:13px;margin:18px 0 0">没有账号?<a style="color:#4f46e5" href="{{ url_for('auth.register') }}">立即注册</a>{% if not has_admin %} · <a style="color:#4f46e5" href="{{ url_for('auth.setup') }}">初始化管理员</a>{% endif %}</p></div></div></main>{% endblock %}
{% extends 'base_console.html' %}
{% block title %}登录控制台{% endblock %}
{% block body %}
<main class="auth-wrap">
<div class="auth-card">
<div class="auth-brand">
<a href="{{ url_for('web.index') }}" title="返回首页">
<img src="{{ url_for('static', filename='images/logo-web.png') }}" alt="Media Parser Logo">
</a>
<h2>Media Parser 控制台</h2>
<p class="muted" style="font-size:13px;margin:4px 0 0">统一多平台媒体解析与开放 API 服务</p>
</div>
<div class="card" style="box-shadow:var(--shadow-lg)">
<h1 class="title" style="font-size:20px;margin-bottom:4px">登录账号</h1>
<p class="subtitle" style="margin-bottom:20px">输入账号凭证以管理您的 API 密钥与调取监控。</p>
{% for category, message in get_flashed_messages(with_categories=true) %}
<div class="flash {{ category }}">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="flex-shrink:0"><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>
<span>{{ message }}</span>
</div>
{% endfor %}
<form method="post">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<div class="field">
<label>用户名</label>
<input name="username" placeholder="请输入用户名" autocomplete="username" required autofocus>
</div>
<div class="field">
<label>密码</label>
<input name="password" type="password" placeholder="请输入账户密码" autocomplete="current-password" required>
</div>
<div style="margin-top:24px">
<button type="submit" class="btn btn-primary btn-block" style="height:40px;font-size:14px">立即登录</button>
</div>
</form>
<div style="margin-top:20px;padding-top:16px;border-top:1px solid var(--line-subtle);text-align:center;font-size:13px" class="muted">
还没有账号?<a style="color:var(--brand);font-weight:600" href="{{ url_for('auth.register') }}">注册账号</a>
{% if not has_admin %}
<span style="margin:0 6px">·</span>
<a style="color:var(--brand);font-weight:600" href="{{ url_for('auth.setup') }}">初始化超级管理员</a>
{% endif %}
</div>
</div>
<div style="text-align:center;margin-top:20px">
<a href="{{ url_for('web.index') }}" class="muted" style="font-size:12.5px;display:inline-flex;align-items:center;gap:4px">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>
返回首页在线体验
</a>
</div>
</div>
</main>
{% endblock %}
+57 -4
View File
@@ -1,4 +1,57 @@
{% extends 'base_console.html' %}{% block title %}注册{% endblock %}{% block body %}
<main class="auth-wrap"><div class="auth-card"><div class="card"><h1 class="title">创建客户账号</h1><p class="subtitle">注册后由管理员设置有效期,无需在线充值。</p>
{% for category,message in get_flashed_messages(with_categories=true) %}<div class="flash {{ category }}">{{ message }}</div>{% endfor %}
<form method="post"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><div class="field"><label>用户名</label><input name="username" minlength="3" maxlength="40" autocomplete="username" required></div><div class="field"><label>密码(至少 8 位)</label><input name="password" type="password" minlength="8" autocomplete="new-password" required></div><div class="field"><label>确认密码</label><input name="confirm_password" type="password" minlength="8" autocomplete="new-password" required></div><button class="btn btn-primary btn-block">注册</button></form><p class="muted" style="text-align:center;font-size:13px;margin:18px 0 0">已有账号?<a style="color:#4f46e5" href="{{ url_for('auth.login') }}">返回登录</a></p></div></div></main>{% endblock %}
{% extends 'base_console.html' %}
{% block title %}注册客户账号{% endblock %}
{% block body %}
<main class="auth-wrap">
<div class="auth-card">
<div class="auth-brand">
<a href="{{ url_for('web.index') }}" title="返回首页">
<img src="{{ url_for('static', filename='images/logo-web.png') }}" alt="Media Parser Logo">
</a>
<h2>Media Parser 控制台</h2>
<p class="muted" style="font-size:13px;margin:4px 0 0">创建属于您的开发者控制台账号</p>
</div>
<div class="card" style="box-shadow:var(--shadow-lg)">
<h1 class="title" style="font-size:20px;margin-bottom:4px">注册新账号</h1>
<p class="subtitle" style="margin-bottom:20px">注册即享试用额度,开通后即可自主创建 API 密钥。</p>
{% for category, message in get_flashed_messages(with_categories=true) %}
<div class="flash {{ category }}">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="flex-shrink:0"><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>
<span>{{ message }}</span>
</div>
{% endfor %}
<form method="post">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<div class="field">
<label>用户名 <span class="muted">(3 ~ 40 位)</span></label>
<input name="username" minlength="3" maxlength="40" placeholder="请输入用户名" autocomplete="username" required autofocus>
</div>
<div class="field">
<label>设置密码 <span class="muted">(至少 8 位)</span></label>
<input name="password" type="password" minlength="8" placeholder="请输入至少 8 位密码" autocomplete="new-password" required>
</div>
<div class="field">
<label>确认密码</label>
<input name="confirm_password" type="password" minlength="8" placeholder="请再次输入密码" autocomplete="new-password" required>
</div>
<div style="margin-top:24px">
<button type="submit" class="btn btn-primary btn-block" style="height:40px;font-size:14px">立即注册</button>
</div>
</form>
<div style="margin-top:20px;padding-top:16px;border-top:1px solid var(--line-subtle);text-align:center;font-size:13px" class="muted">
已有账号?<a style="color:var(--brand);font-weight:600" href="{{ url_for('auth.login') }}">返回登录</a>
</div>
</div>
<div style="text-align:center;margin-top:20px">
<a href="{{ url_for('web.index') }}" class="muted" style="font-size:12.5px;display:inline-flex;align-items:center;gap:4px">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>
返回首页在线体验
</a>
</div>
</div>
</main>
{% endblock %}
+56 -4
View File
@@ -1,4 +1,56 @@
{% extends 'base_console.html' %}{% block title %}初始化管理员{% endblock %}{% block body %}
<main class="auth-wrap"><div class="auth-card"><div class="card"><h1 class="title">初始化管理员</h1><p class="subtitle">这是首次部署的一次性步骤。请设置一个强密码。</p>
{% for category,message in get_flashed_messages(with_categories=true) %}<div class="flash {{ category }}">{{ message }}</div>{% endfor %}
<form method="post"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><div class="field"><label>管理员用户名</label><input name="username" minlength="3" maxlength="40" required></div><div class="field"><label>管理员密码(至少 8 位)</label><input name="password" type="password" minlength="8" required></div><div class="field"><label>确认管理员密码</label><input name="confirm_password" type="password" minlength="8" required></div><button class="btn btn-primary btn-block">创建管理员</button></form></div></div></main>{% endblock %}
{% extends 'base_console.html' %}
{% block title %}初始化系统管理员{% endblock %}
{% block body %}
<main class="auth-wrap">
<div class="auth-card">
<div class="auth-brand">
<a href="{{ url_for('web.index') }}" title="返回首页">
<img src="{{ url_for('static', filename='images/logo-web.png') }}" alt="Media Parser Logo">
</a>
<h2>Media Parser 控制台</h2>
<p class="muted" style="font-size:13px;margin:4px 0 0">首次部署:创建超级管理员初始凭据</p>
</div>
<div class="card" style="box-shadow:var(--shadow-lg)">
<div class="row" style="gap:8px;align-items:center;margin-bottom:8px">
<span class="badge" style="background:#eef2ff;color:#4f46e5;border-color:#c7d2fe">首次初始化</span>
</div>
<h1 class="title" style="font-size:20px;margin-bottom:4px">初始化管理员</h1>
<p class="subtitle" style="margin-bottom:20px">该步骤仅在初次部署时执行一次,请务必设置强密码并妥善保管。</p>
{% for category, message in get_flashed_messages(with_categories=true) %}
<div class="flash {{ category }}">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="flex-shrink:0"><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>
<span>{{ message }}</span>
</div>
{% endfor %}
<form method="post">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<div class="field">
<label>管理员用户名 <span class="muted">(3 ~ 40 位)</span></label>
<input name="username" minlength="3" maxlength="40" placeholder="例如:admin" required autofocus>
</div>
<div class="field">
<label>管理员密码 <span class="muted">(至少 8 位)</span></label>
<input name="password" type="password" minlength="8" placeholder="请输入高强度管理员密码" required>
</div>
<div class="field">
<label>确认管理员密码</label>
<input name="confirm_password" type="password" minlength="8" placeholder="请再次输入管理员密码" required>
</div>
<div style="margin-top:24px">
<button type="submit" class="btn btn-primary btn-block" style="height:40px;font-size:14px">立即创建超级管理员</button>
</div>
</form>
</div>
<div style="text-align:center;margin-top:20px">
<a href="{{ url_for('web.index') }}" class="muted" style="font-size:12.5px;display:inline-flex;align-items:center;gap:4px">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>
返回首页在线体验
</a>
</div>
</div>
</main>
{% endblock %}
+92 -2
View File
@@ -89,7 +89,22 @@
</div>
<header class="main-topbar">
<h1 class="page-title" id="active-page-title">{% block page_title %}{% endblock %}</h1>
<div class="topbar-left">
<div class="topbar-breadcrumb">
<a href="{{ url_for('web.index') }}">Media Parser</a>
<span class="topbar-separator">/</span>
<span>{{ '管理后台' if g.user['role']=='admin' else '控制台' }}</span>
<span class="topbar-separator">/</span>
</div>
<h1 class="page-title" id="active-page-title">{% block page_title %}{% endblock %}</h1>
</div>
<div class="topbar-right">
<span class="status-pill online"><span class="status-dot pulse"></span>API 正常</span>
<a href="{{ url_for('web.index') }}" target="_blank" class="topbar-link" title="前往首页在线体验">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>
<span>在线体验</span>
</a>
</div>
</header>
{% block console_content %}{% endblock %}
</div>
@@ -191,6 +206,8 @@ function initChartInteractions() {
document.querySelectorAll('.chart-container').forEach(container => {
const tooltip = container.querySelector('.chart-tooltip');
const guideLine = container.querySelector('.chart-guide-line');
const callsDot = container.querySelector('.calls-dot');
const succDot = container.querySelector('.succ-dot');
const svg = container.querySelector('svg');
if (!tooltip || !svg) return;
@@ -202,6 +219,8 @@ function initChartInteractions() {
const successes = el.dataset.successes;
const failures = el.dataset.failures;
const cx = parseFloat(el.dataset.cx);
const cyCalls = parseFloat(el.dataset.cyCalls);
const cySucc = parseFloat(el.dataset.cySucc);
if (guideLine) {
guideLine.setAttribute('x1', cx);
@@ -209,6 +228,18 @@ function initChartInteractions() {
guideLine.style.display = 'block';
}
if (callsDot && !isNaN(cyCalls)) {
callsDot.setAttribute('cx', cx);
callsDot.setAttribute('cy', cyCalls);
callsDot.style.display = 'block';
}
if (succDot && !isNaN(cySucc)) {
succDot.setAttribute('cx', cx);
succDot.setAttribute('cy', cySucc);
succDot.style.display = 'block';
}
const failCount = parseInt(failures) || 0;
tooltip.innerHTML = `
<div class="tt-title">${date}</div>
@@ -242,12 +273,14 @@ function initChartInteractions() {
}
tooltip.style.left = left + 'px';
tooltip.style.top = '12px';
tooltip.style.top = '10px';
}
function hideTooltip() {
if (tooltip) tooltip.classList.remove('active');
if (guideLine) guideLine.style.display = 'none';
if (callsDot) callsDot.style.display = 'none';
if (succDot) succDot.style.display = 'none';
}
triggers.forEach(trig => {
@@ -481,10 +514,67 @@ function closeChangePasswordModal() {
setTimeout(() => { m.style.display = 'none'; }, 180);
}
function initDonutInteractions() {
document.querySelectorAll('.pie-wrapper').forEach(wrapper => {
const centerVal = wrapper.querySelector('.pie-center-val');
const centerLbl = wrapper.querySelector('.pie-center-lbl');
if (!centerVal || !centerLbl) return;
const defaultVal = centerVal.textContent;
const defaultLbl = centerLbl.textContent;
const slices = wrapper.querySelectorAll('.pie-slice');
const pills = wrapper.querySelectorAll('.pie-pill-item');
function activate(platform, calls, percent) {
centerLbl.textContent = `${platform} (${percent})`;
centerLbl.style.fontWeight = '600';
centerLbl.style.color = 'var(--brand)';
centerVal.textContent = `${calls} 次`;
centerVal.style.fontSize = calls.length > 7 ? '17px' : '20px';
slices.forEach(s => {
if (s.dataset.platform === platform) s.classList.add('active');
else s.classList.remove('active');
});
pills.forEach(p => {
if (p.dataset.platform === platform) p.classList.add('active');
else p.classList.remove('active');
});
}
function reset() {
centerLbl.textContent = defaultLbl;
centerLbl.style.fontWeight = '';
centerLbl.style.color = '';
centerVal.textContent = defaultVal;
centerVal.style.fontSize = '';
slices.forEach(s => s.classList.remove('active'));
pills.forEach(p => p.classList.remove('active'));
}
slices.forEach(slice => {
slice.addEventListener('mouseenter', () => {
activate(slice.dataset.platform, slice.dataset.calls, slice.dataset.percent);
});
slice.addEventListener('mouseleave', reset);
});
pills.forEach(pill => {
pill.addEventListener('mouseenter', () => {
activate(pill.dataset.platform, pill.dataset.calls, pill.dataset.percent);
});
pill.addEventListener('mouseleave', reset);
});
});
}
window.addEventListener('hashchange', switchConsoleTab);
window.addEventListener('DOMContentLoaded', () => {
switchConsoleTab();
initChartInteractions();
initDonutInteractions();
initToasts();
initConfirmInterceptions();
const cpm = document.getElementById('change-password-modal-backdrop');
+75 -43
View File
@@ -19,14 +19,48 @@
else '服务有效' }}</span>
</div>
<div class="stats">
<div class="card stat"><span class="muted">24 小时调用</span><strong>{{ stats['calls'] or 0 }}</strong></div>
<div class="card stat"><span class="muted">成功调用</span><strong>{{ stats['successes'] or 0 }}</strong></div>
<div class="card stat"><span class="muted">剩余解析积分</span><strong>{{ '不限制' if g.user['credits'] == -1 else
(g.user['credits'] or 0) }}</strong></div>
<div class="card stat"><span class="muted">账号 QPS 限制</span><strong>{{ g.user['qps_limit'] }}</strong></div>
<div class="card stat"><span class="muted">账号到期时间</span><strong
style="font-size:18px;margin-top:12px;color:{{ '#ef4444' if user_is_expired(g.user) else '#0f172a' }}">{{
format_user_expiry(g.user) }}</strong></div>
<div class="card stat">
<div class="stat-head">
<span class="stat-label">24 小时调用</span>
<span class="stat-icon">{{ icon('chart') }}</span>
</div>
<strong>{{ stats['calls'] or 0 }}</strong>
<span class="stat-foot">近 24 小时接口请求</span>
</div>
<div class="card stat">
<div class="stat-head">
<span class="stat-label">成功调用</span>
<span class="stat-icon">{{ icon('check') }}</span>
</div>
<strong>{{ stats['successes'] or 0 }}</strong>
<span class="stat-foot">有效完成媒体直链解析</span>
</div>
<div class="card stat">
<div class="stat-head">
<span class="stat-label">剩余解析积分</span>
<span class="stat-icon">{{ icon('tag') }}</span>
</div>
<strong>{{ '不限制' if g.user['credits'] == -1 else (g.user['credits'] or 0) }}</strong>
<span class="stat-foot">接口解析额度</span>
</div>
<div class="card stat">
<div class="stat-head">
<span class="stat-label">账号 QPS 上限</span>
<span class="stat-icon">{{ icon('shield') }}</span>
</div>
<strong>{{ g.user['qps_limit'] }}</strong>
<span class="stat-foot">每秒并发请求阈值</span>
</div>
<div class="card stat">
<div class="stat-head">
<span class="stat-label">账号到期时间</span>
<span class="stat-icon">{{ icon('scroll') }}</span>
</div>
<strong style="font-size:18px;color:{{ '#dc2626' if user_is_expired(g.user) else '#0f172a' }}">
{{ format_user_expiry(g.user) }}
</strong>
<span class="stat-foot">服务授权截止期</span>
</div>
</div>
<!-- 动态周期筛选栏 -->
@@ -78,50 +112,46 @@
<!-- Y 轴网格辅助线与刻度 -->
{% for tick in chart_data['y_ticks'] %}
<line x1="50" y1="{{ tick['y'] }}" x2="670" y2="{{ tick['y'] }}" stroke="#f1f5f9" stroke-width="1"
stroke-dasharray="4 4" />
<text x="42" y="{{ tick['y'] + 4 }}" text-anchor="end" font-size="11" fill="#94a3b8">{{ tick['val']
}}</text>
<line x1="45" y1="{{ tick['y'] }}" x2="675" y2="{{ tick['y'] }}" stroke="#f1f5f9" stroke-width="0.8"
stroke-dasharray="3 3" />
<text x="38" y="{{ tick['y'] + 3.5 }}" text-anchor="end" font-size="9.5" fill="#94a3b8">{{ tick['val'] }}</text>
{% endfor %}
<!-- X 轴基线 -->
<line x1="50" y1="180" x2="670" y2="180" stroke="#e2e8f0" stroke-width="1" />
<line x1="45" y1="180" x2="675" y2="180" stroke="#e2e8f0" stroke-width="0.9" />
<!-- 鼠标悬浮对齐线 -->
<line class="chart-guide-line" x1="0" y1="20" x2="0" y2="180" stroke="#818cf8" stroke-width="1.2"
<line class="chart-guide-line" x1="0" y1="20" x2="0" y2="180" stroke="#818cf8" stroke-width="1"
stroke-dasharray="3 3" style="display:none;pointer-events:none" />
<!-- 渐变填充面 -->
<polygon points="{{ chart_data['calls_area'] }}" fill="url(#callsGradPortal)" />
<polygon points="{{ chart_data['successes_area'] }}" fill="url(#succGradPortal)" />
<!-- 平滑渐变填充面 -->
<path d="{{ chart_data['calls_area_path'] }}" fill="url(#callsGradPortal)" />
<path d="{{ chart_data['successes_area_path'] }}" fill="url(#succGradPortal)" />
<!-- 趋势平滑折线 -->
<polyline points="{{ chart_data['calls_line'] }}" fill="none" stroke="#4f46e5" stroke-width="1.8"
<!-- 趋势平滑贝塞尔曲线 (纤细大厂风格) -->
<path d="{{ chart_data['calls_path'] }}" fill="none" stroke="#4f46e5" stroke-width="1.5"
stroke-linecap="round" stroke-linejoin="round" />
<polyline points="{{ chart_data['successes_line'] }}" fill="none" stroke="#10b981"
stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" />
<path d="{{ chart_data['successes_path'] }}" fill="none" stroke="#10b981" stroke-width="1.3"
stroke-linecap="round" stroke-linejoin="round" />
<!-- 动态悬停聚焦光晕圆点 (初始隐藏) -->
<circle class="chart-hover-dot calls-dot" cx="0" cy="0" r="3.5" fill="#4f46e5" stroke="#ffffff"
stroke-width="1.8" style="display:none;pointer-events:none" />
<circle class="chart-hover-dot succ-dot" cx="0" cy="0" r="3" fill="#10b981" stroke="#ffffff"
stroke-width="1.6" style="display:none;pointer-events:none" />
<!-- X 轴刻度与交互节点 -->
{% for item in chart_data['trend'] %}
{% if item['show_label'] %}
<text x="{{ item['x'] }}" y="200" text-anchor="middle" font-size="10" fill="#94a3b8">{{
item['short_date'] }}</text>
<text x="{{ item['x'] }}" y="198" text-anchor="middle" font-size="9.5" font-weight="450" fill="#94a3b8">{{ item['short_date'] }}</text>
{% endif %}
<!-- 透明列触控透明矩形 -->
<rect class="chart-col-trigger" x="{{ item['x'] - 20 }}" y="20" width="40" height="160"
<rect class="chart-col-trigger" x="{{ item['x'] - 20 }}" y="15" width="40" height="170"
fill="transparent" style="cursor:pointer" data-date="{{ item['date'] }}"
data-calls="{{ item['calls'] }}" data-successes="{{ item['successes'] }}"
data-failures="{{ item['failures'] }}" data-cx="{{ item['x'] }}"
data-cy-calls="{{ item['y_calls'] }}" data-cy-succ="{{ item['y_successes'] }}" />
<!-- 总调用量节点 -->
<circle cx="{{ item['x'] }}" cy="{{ item['y_calls'] }}" r="3.5" fill="#ffffff" stroke="#4f46e5"
stroke-width="1.8" class="point-circle" style="pointer-events:none" />
<!-- 成功调用量节点 -->
<circle cx="{{ item['x'] }}" cy="{{ item['y_successes'] }}" r="2.5" fill="#ffffff" stroke="#10b981"
stroke-width="1.8" class="point-circle" style="pointer-events:none" />
{% endfor %}
</svg>
</div>
@@ -150,30 +180,29 @@
<div>当前时间范围内暂无调用记录</div>
</div>
{% else %}
<div class="pie-wrapper">
<div class="pie-wrapper" id="portal-platform-dist">
<div class="pie-svg-box">
<svg viewBox="0 0 200 200" style="width:100%;height:100%">
{% for item in pie_data['items'] %}
<path d="{{ item['path_d'] }}" fill="{{ item['color'] }}" class="pie-slice"
data-platform="{{ item['platform'] }}" data-calls="{{ item['calls'] }}"
data-platform="{{ item['platform'] }}" data-calls="{{ item['calls_formatted'] }}"
data-percent="{{ item['percentage'] }}%">
<title>{{ item['platform'] }}: {{ item['calls'] }} 次 ({{ item['percentage'] }}%)</title>
<title>{{ item['platform'] }}: {{ item['calls_formatted'] }} 次 ({{ item['percentage'] }}%)</title>
</path>
{% endfor %}
</svg>
<div class="pie-center-text">
<div class="pie-center-val">{{ pie_data['total_calls'] }}</div>
<div class="pie-center-lbl">总解析量</div>
<div class="pie-center-lbl" id="portal-pie-lbl">总解析量</div>
<div class="pie-center-val" id="portal-pie-val">{{ pie_data['total_calls_formatted'] or pie_data['total_calls'] }} 次</div>
</div>
</div>
<!-- 下方平铺胶囊图例 -->
<!-- 下方自适应平铺胶囊图例网格 (支持50+平台) -->
<div class="pie-pill-grid">
{% for item in pie_data['items'] %}
<div class="pie-pill-item">
<div class="pie-pill-item" data-platform="{{ item['platform'] }}" data-calls="{{ item['calls_formatted'] }}" data-percent="{{ item['percentage'] }}%" title="{{ item['platform'] }}: {{ item['calls_formatted'] }} 次 ({{ item['percentage'] }}%)">
<span class="pie-pill-dot" style="background:{{ item['color'] }}"></span>
<span class="pie-pill-name">{{ item['platform'] }}</span>
<span class="pie-pill-val">{{ item['percentage'] }}%</span>
</div>
{% endfor %}
</div>
@@ -206,8 +235,11 @@
{% for item in top_keys %}
<div class="ranking-item">
<div class="ranking-head">
<span class="ranking-name">{{ item['name'] }} <span class="muted font-mono">({{
item['key_prefix'] }}...)</span></span>
<span class="ranking-name">
<span class="ranking-badge">{{ loop.index }}</span>
{{ item['name'] }} <span class="muted font-mono" style="font-size:11px">({{
item['key_prefix'] }}...)</span>
</span>
<span class="ranking-val">{{ item['calls'] }} 次</span>
</div>
<div class="ranking-bar-bg">
@@ -471,7 +503,7 @@ Authorization: Bearer mp_xxxxxxxxx</pre>
<table style="width:100%;min-width:920px">
<thead>
<tr>
<th style="width:28%">时间(北京时间)</th>
<th style="width:28%">时间</th>
<th>平台</th>
<th>脱敏 URL</th>
<th>状态</th>