refactor: 拆分 middleware/router 为单一职责文件,新增站点设置管理页面

middleware:
- 拆分 auth.go → auth.go + auth_token.go + auth_parser.go + auth_admin.go
- 拆分 csrf.go → csrf.go + csrf_token.go
- 拆分 ratelimit.go → ratelimit.go + ratelimit_core.go + ratelimit_cleanup.go
- 修复 import 未使用/缺失问题

router:
- 拆分 router.go → admin.go + api.go + frontend.go + deps_core.go + deps_extra.go

feat(admin): 站点设置管理页面
- 新增 SSR 页面 /admin/site-settings(仅 Owner)
- 审核开关 Toggle 即时保存
- 通用设置展示
- 侧边栏新增站点设置入口
- 注册 UpdateBoolSetting/GetBoolSetting API 路由
This commit is contained in:
2026-05-27 15:03:04 +08:00
parent a19b1fcb51
commit 7bc2dbd970
20 changed files with 774 additions and 446 deletions

View File

@ -0,0 +1,83 @@
/* =====================================================
MetaLab 管理面板 - 站点设置
单一职责:设置页面布局、表单分组、开关组件
===================================================== */
/* --- 设置区块 --- */
.settings-section {
background: var(--bg-card);
border-radius: var(--radius);
box-shadow: var(--shadow);
margin-bottom: 20px;
overflow: hidden;
}
.section-title {
font-size: 15px; font-weight: 600;
color: var(--text);
padding: 16px 20px;
border-bottom: 1px solid var(--border);
background: #fafafa;
}
.section-body { padding: 4px 0; }
/* --- 设置条目 --- */
.setting-item {
display: flex; align-items: center; justify-content: space-between;
padding: 14px 20px;
border-bottom: 1px solid #f5f5f5;
gap: 20px;
}
.setting-item:last-child { border-bottom: none; }
.setting-info { flex: 1; min-width: 0; }
.setting-label {
font-size: 13px; font-weight: 500;
color: var(--text); display: block;
}
.setting-desc {
font-size: 12px; color: var(--text-muted);
margin-top: 2px;
}
.setting-value {
font-size: 12px; color: var(--text-muted);
margin-top: 2px; font-family: monospace;
background: #f5f6fa; padding: 2px 6px; border-radius: 3px;
display: inline-block;
word-break: break-all;
}
/* --- 空状态 --- */
.settings-empty {
text-align: center; padding: 28px 20px;
color: var(--text-muted); font-size: 13px;
}
/* --- Toggle 开关 --- */
.toggle-switch {
position: relative; display: inline-block;
width: 44px; height: 24px; flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
position: absolute; cursor: pointer;
top: 0; left: 0; right: 0; bottom: 0;
background: #ccc;
border-radius: 24px;
transition: background 0.2s;
}
.toggle-slider::before {
position: absolute; content: "";
height: 18px; width: 18px;
left: 3px; bottom: 3px;
background: #fff;
border-radius: 50%;
transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider {
background: var(--primary);
}
.toggle-switch input:checked + .toggle-slider::before {
transform: translateX(20px);
}
.toggle-switch input:disabled + .toggle-slider {
opacity: 0.4; cursor: not-allowed;
}

View File

@ -0,0 +1,87 @@
/* =====================================================
MetaLab 管理面板 - 站点设置
单一职责:加载/保存站点设置,开关即时生效
===================================================== */
(function() {
'use strict';
const TOGGLE_KEYS = [
{ id: 'audit-enabled', key: 'audit.enabled' },
{ id: 'audit-username', key: 'audit.username_audit' },
{ id: 'audit-avatar', key: 'audit.avatar_audit' },
{ id: 'audit-bio', key: 'audit.bio_audit' }
];
// --- 初始加载 ---
async function loadSettings() {
try {
const res = await api.get('/api/admin/site-settings');
if (!res.success) return;
// 审核开关
const audit = res.data.audit || {};
TOGGLE_KEYS.forEach(function(t) {
var el = document.getElementById(t.id);
if (el) {
el.checked = audit[t.key.split('.')[1]] === true;
el.addEventListener('change', function() {
updateBoolSetting(t.key, el.checked, el);
});
}
});
// 通用设置
renderGeneralSettings(res.data.all || {});
} catch (e) {
showToast('加载设置失败', 'error');
}
}
// --- 更新布尔设置 ---
async function updateBoolSetting(key, value, toggle) {
toggle.disabled = true;
try {
var res = await api.put('/api/admin/site-settings/bool', {
key: key,
value: String(value)
});
if (res.success) {
showToast('设置已更新', 'success');
} else {
showToast(res.message || '保存失败', 'error');
toggle.checked = !value; // 回滚
}
} catch (e) {
showToast('保存失败', 'error');
toggle.checked = !value; // 回滚
} finally {
toggle.disabled = false;
}
}
// --- 渲染通用设置 ---
function renderGeneralSettings(all) {
var container = document.getElementById('general-settings');
var keys = Object.keys(all);
if (keys.length === 0) {
container.innerHTML = '<div class="settings-empty">暂无其他设置</div>';
return;
}
container.innerHTML = '';
keys.forEach(function(key) {
var val = all[key] || '';
var item = document.createElement('div');
item.className = 'setting-item';
item.innerHTML =
'<div class="setting-info">' +
'<span class="setting-label">' + escapeHtml(key) + '</span>' +
'<span class="setting-value">' + escapeHtml(val.length > 80 ? val.slice(0, 80) + '...' : val) + '</span>' +
'</div>';
container.appendChild(item);
});
}
// --- 入口 ---
loadSettings();
})();