feat: 监控面板 / 登录鉴权 / 多平台切换 / MySQL
在上游 MediaCrawler 之上新增一层: - 监控层 api/monitor/ —— 多博主/多笔记的定时采集、指标快照差分、报表、 企业微信通知。每轮采集写入独立目录,差分才成立。 - WebUI 登录鉴权 api/auth.py —— PBKDF2 口令 + 服务端会话,/api 全接口防护。 WebSocket 单独加依赖:BaseHTTPMiddleware 对 ws 作用域直接放行,覆盖不到。 - 全局平台切换 + 能力矩阵 —— 如实区分「爬虫模块支持」与「监控层已接线」, 未接通的平台直接拒绝建任务,而不是静默跑空。 - 监控库改用 MySQL 5.7(可回退 SQLite 供测试):逐表强制 utf8mb4 (服务端与库默认都是 latin1),启动校验所连 schema 以防写错库, 连接池 recycle + pre_ping 应对 MySQL 的 8 小时空闲断连。 修复上游缺陷: - xhs/core.py: 主页抓取失败会跳掉整个博主,导致一条作品都抓不到, 而那份资料只喂给一个空函数。改为尽力而为,失败不中断。 - xhs/login.py: cookie 登录只注入 web_session,冷启动签名会失败。 新增 INJECT_ALL_COOKIES 开关(默认关闭,原有行为不变)。 - requirements.txt: 补上 websockets。它在上游 pyproject.toml 里有声明、 这里漏了,导致 uvicorn 没有 WebSocket 能力,实时日志流从未工作。 改动过的上游文件清单及合并方式见 UPSTREAM.md。 测试:492 passed(另有 1 个既有的 Windows/gbk 上游测试失败,与本改动无关)
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
import { useState } from 'react'
|
||||
import { KeyRound, Loader2, ShieldAlert } from 'lucide-react'
|
||||
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { authApi } from '@/lib/api'
|
||||
|
||||
interface LoginProps {
|
||||
onSuccess: () => void
|
||||
}
|
||||
|
||||
/**
|
||||
* Full-screen login gate.
|
||||
*
|
||||
* Never an overlay on top of the app: the authenticated tree owns the log
|
||||
* WebSocket, and mounting it behind a modal would open the socket before the
|
||||
* user is authenticated. App.tsx therefore renders this *instead of* the app.
|
||||
*/
|
||||
export function Login({ onSuccess }: LoginProps) {
|
||||
const [password, setPassword] = useState('')
|
||||
const [error, setError] = useState('')
|
||||
const [busy, setBusy] = useState(false)
|
||||
|
||||
const handleSubmit = async (event: React.FormEvent) => {
|
||||
event.preventDefault()
|
||||
if (!password || busy) return
|
||||
|
||||
setBusy(true)
|
||||
setError('')
|
||||
try {
|
||||
await authApi.login(password)
|
||||
setPassword('')
|
||||
onSuccess()
|
||||
} catch (err: unknown) {
|
||||
const response = (err as { response?: { status?: number; data?: { detail?: string } } })
|
||||
?.response
|
||||
if (response?.status === 429) {
|
||||
// Throttled, not wrong -- say so rather than implying a bad password.
|
||||
setError(response.data?.detail ?? '尝试过于频繁,请稍后再试')
|
||||
} else {
|
||||
setError(response?.data?.detail ?? '登录失败')
|
||||
}
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 cyber-grid bg-cyber-bg-primary flex items-center justify-center z-[100]">
|
||||
<form
|
||||
onSubmit={handleSubmit}
|
||||
className="relative w-full max-w-md mx-4 p-6 rounded-lg glass-panel float-panel"
|
||||
>
|
||||
{/* Corner accents, matching the other full-screen gates */}
|
||||
<div className="absolute top-0 left-0 w-6 h-6 border-t-2 border-l-2 border-cyber-neon-cyan/60" />
|
||||
<div className="absolute top-0 right-0 w-6 h-6 border-t-2 border-r-2 border-cyber-neon-cyan/60" />
|
||||
<div className="absolute bottom-0 left-0 w-6 h-6 border-b-2 border-l-2 border-cyber-neon-cyan/60" />
|
||||
<div className="absolute bottom-0 right-0 w-6 h-6 border-b-2 border-r-2 border-cyber-neon-cyan/60" />
|
||||
|
||||
<div className="flex items-center justify-center gap-2 mb-1">
|
||||
<KeyRound className="w-5 h-5 text-cyber-neon-cyan" />
|
||||
<span className="font-mono font-bold tracking-wider text-cyber-text-primary">
|
||||
综合采集平台
|
||||
</span>
|
||||
</div>
|
||||
<p className="text-center text-[11px] font-mono text-cyber-text-muted mb-5">
|
||||
需要登录才能访问控制面板
|
||||
</p>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label className="text-xs font-mono text-cyber-text-secondary" htmlFor="password">
|
||||
登录密码
|
||||
</Label>
|
||||
<Input
|
||||
id="password"
|
||||
type="password"
|
||||
autoFocus
|
||||
autoComplete="current-password"
|
||||
value={password}
|
||||
onChange={(event) => setPassword(event.target.value)}
|
||||
placeholder="请输入密码"
|
||||
className="h-10 font-mono"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className="mt-3 flex items-start gap-2 rounded-md border border-cyber-neon-pink/40 bg-cyber-neon-pink/10 px-3 py-2">
|
||||
<ShieldAlert className="w-3.5 h-3.5 text-cyber-neon-pink mt-0.5 flex-shrink-0" />
|
||||
<span className="text-[11px] font-mono text-cyber-neon-pink">{error}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
variant="glow"
|
||||
disabled={!password || busy}
|
||||
className="w-full mt-4 font-mono"
|
||||
>
|
||||
{busy ? <Loader2 className="w-4 h-4 animate-spin" /> : '登 录'}
|
||||
</Button>
|
||||
|
||||
<p className="mt-4 text-[10px] font-mono text-cyber-text-muted leading-relaxed">
|
||||
首次启动的密码打印在服务端启动日志里。
|
||||
忘记密码时,设置环境变量 <span className="text-cyber-neon-cyan">MC_PASSWORD</span> 后重启即可恢复,
|
||||
并在登录后于设置页修改。
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user