feat(webui): standardize content loading states
Use consistent delayed placeholders across data-backed console surfaces. Avoid flashing loading UI for fast local responses while keeping slower transitions stable. Keep failures visible and prevent gated content from opening on incomplete checks.
This commit is contained in:
22 files changed
+2493
-1527
No files matched your search
@@ -6,7 +6,8 @@
|
||||
// URL); the store reconciles on the next load. Invalid entries are flagged
|
||||
// client-side and simply dropped by the server on save.
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { AlertTriangle, KeyRound, Loader2, Music, Plus, RefreshCw, Trash2 } from 'lucide-react';
|
||||
import { AlertTriangle, KeyRound, Music, Plus, RefreshCw, Trash2 } from 'lucide-react';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
@@ -42,7 +43,8 @@ export function GlobalConfigPanel() {
|
||||
setLoadFailed(false);
|
||||
try {
|
||||
setConfig(await api.globalConfig.get());
|
||||
} catch {
|
||||
} catch (error) {
|
||||
console.error('load global config failed', error);
|
||||
setLoadFailed(true);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -103,23 +105,26 @@ export function GlobalConfigPanel() {
|
||||
}, 500);
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
if (loading || !config) {
|
||||
return (
|
||||
<div className="flex items-center gap-2 rounded-lg border bg-card/40 p-6 text-sm text-muted-foreground">
|
||||
<Loader2 className="size-4 animate-spin" /> 加载中…
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (loadFailed || !config) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-16 text-muted-foreground">
|
||||
<AlertTriangle className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">加载全局配置失败</p>
|
||||
<Button variant="outline" size="sm" onClick={() => void load()}>
|
||||
<RefreshCw className="size-3.5" /> 重试
|
||||
</Button>
|
||||
</div>
|
||||
<SkeletonSwap
|
||||
ready={!loading}
|
||||
lines={6}
|
||||
lineHeight={26}
|
||||
reserve={156}
|
||||
label="全局配置"
|
||||
className={!loading ? 'skeleton-swap-fluid min-h-[156px]' : ''}
|
||||
>
|
||||
{!loading && (loadFailed || !config) ? (
|
||||
<div className="flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-16 text-muted-foreground">
|
||||
<AlertTriangle className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">加载全局配置失败</p>
|
||||
<Button variant="outline" size="sm" onClick={() => void load()}>
|
||||
<RefreshCw className="size-3.5" /> 重试
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -128,101 +133,110 @@ export function GlobalConfigPanel() {
|
||||
commit({ ...config, rkey: { fallbackServers: next } }, false);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* rkey fallback servers */}
|
||||
<div className="flex flex-col gap-4 rounded-xl border bg-card/40 p-4">
|
||||
<div className="flex items-start gap-2 text-xs leading-relaxed text-muted-foreground">
|
||||
<KeyRound className="mt-0.5 size-3.5 shrink-0" />
|
||||
<p>
|
||||
<SkeletonSwap
|
||||
ready
|
||||
lines={6}
|
||||
lineHeight={26}
|
||||
reserve={156}
|
||||
label="全局配置"
|
||||
className="skeleton-swap-fluid min-h-[156px]"
|
||||
>
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* rkey fallback servers */}
|
||||
<div className="flex flex-col gap-4 rounded-xl border bg-card/40 p-4">
|
||||
<div className="flex items-start gap-2 text-xs leading-relaxed text-muted-foreground">
|
||||
<KeyRound className="mt-0.5 size-3.5 shrink-0" />
|
||||
<p>
|
||||
图片 / 文件下载链接需要服务器签发的 <code className="font-mono">rkey</code>。SnowLuma 默认走内核获取;
|
||||
当内核在你的环境下持续取不到时,会按顺序向这里配置的 HTTP 端点回退。
|
||||
<strong className="font-medium text-foreground/80">默认留空=关闭</strong>,不配置就不会联系任何第三方。
|
||||
<strong className="font-medium text-foreground/80">默认留空=关闭</strong>,不配置就不会联系任何第三方。
|
||||
建议填你自建的端点。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-2 border-t pt-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label>rkey 回退服务器</Label>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setServers([...servers, ''])}
|
||||
>
|
||||
<Plus className="size-3.5" /> 添加
|
||||
</Button>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{servers.length === 0 ? (
|
||||
<p className="rounded-lg border border-dashed px-3 py-4 text-center text-xs text-muted-foreground">
|
||||
<div className="flex flex-col gap-2 border-t pt-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label>rkey 回退服务器</Label>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setServers([...servers, ''])}
|
||||
>
|
||||
<Plus className="size-3.5" /> 添加
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{servers.length === 0 ? (
|
||||
<p className="rounded-lg border border-dashed px-3 py-4 text-center text-xs text-muted-foreground">
|
||||
未配置回退服务器(rkey 回退已关闭)
|
||||
</p>
|
||||
) : (
|
||||
<div className="flex flex-col gap-2">
|
||||
{servers.map((url, i) => {
|
||||
const invalid = url.trim().length > 0 && !isHttpUrl(url.trim());
|
||||
return (
|
||||
<div key={i} className="flex items-center gap-2">
|
||||
<Input
|
||||
type="url"
|
||||
inputMode="url"
|
||||
spellCheck={false}
|
||||
placeholder="https://your-rkey-server.example/rkeys"
|
||||
value={url}
|
||||
aria-invalid={invalid}
|
||||
className={cn('font-mono text-xs', invalid && 'border-destructive focus-visible:ring-destructive')}
|
||||
onChange={(e) => setServers(servers.map((s, idx) => (idx === i ? e.target.value : s)))}
|
||||
/>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
aria-label="删除"
|
||||
className="shrink-0 text-muted-foreground hover:text-destructive"
|
||||
onClick={() => setServers(servers.filter((_, idx) => idx !== i))}
|
||||
>
|
||||
<Trash2 className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
<p className="text-xs leading-relaxed text-muted-foreground">
|
||||
</p>
|
||||
) : (
|
||||
<div className="flex flex-col gap-2">
|
||||
{servers.map((url, i) => {
|
||||
const invalid = url.trim().length > 0 && !isHttpUrl(url.trim());
|
||||
return (
|
||||
<div key={i} className="flex items-center gap-2">
|
||||
<Input
|
||||
type="url"
|
||||
inputMode="url"
|
||||
spellCheck={false}
|
||||
placeholder="https://your-rkey-server.example/rkeys"
|
||||
value={url}
|
||||
aria-invalid={invalid}
|
||||
className={cn('font-mono text-xs', invalid && 'border-destructive focus-visible:ring-destructive')}
|
||||
onChange={(e) => setServers(servers.map((s, idx) => (idx === i ? e.target.value : s)))}
|
||||
/>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
aria-label="删除"
|
||||
className="shrink-0 text-muted-foreground hover:text-destructive"
|
||||
onClick={() => setServers(servers.filter((_, idx) => idx !== i))}
|
||||
>
|
||||
<Trash2 className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
<p className="text-xs leading-relaxed text-muted-foreground">
|
||||
端点需返回 <code className="font-mono">{'{ group_rkey, private_rkey, expired_time }'}</code>
|
||||
(兼容 NapCat rkey 服务格式)。非 http(s) 链接会被忽略。
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* music sign URL */}
|
||||
<div className="flex flex-col gap-4 rounded-xl border bg-card/40 p-4">
|
||||
<div className="flex items-start gap-2 text-xs leading-relaxed text-muted-foreground">
|
||||
<Music className="mt-0.5 size-3.5 shrink-0" />
|
||||
<p>音乐分享卡片的签名服务,对所有账号统一生效。留空则使用内置默认服务。</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5 border-t pt-3">
|
||||
<Label>音乐签名服务 URL</Label>
|
||||
<Input
|
||||
type="url"
|
||||
inputMode="url"
|
||||
spellCheck={false}
|
||||
placeholder={MUSIC_SIGN_DEFAULT}
|
||||
value={config.musicSignUrl}
|
||||
aria-invalid={config.musicSignUrl.trim().length > 0 && !isHttpUrl(config.musicSignUrl.trim())}
|
||||
className={cn(
|
||||
'font-mono text-xs',
|
||||
config.musicSignUrl.trim().length > 0 && !isHttpUrl(config.musicSignUrl.trim())
|
||||
&& 'border-destructive focus-visible:ring-destructive',
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
onChange={(e) => commit({ ...config, musicSignUrl: e.target.value })}
|
||||
/>
|
||||
<p className="text-xs leading-relaxed text-muted-foreground">
|
||||
内置默认:<code className="font-mono">{MUSIC_SIGN_DEFAULT}</code>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{msg && <p className={cn('text-xs', msg.kind === 'ok' ? 'text-success' : 'text-destructive')}>{msg.text}</p>}
|
||||
</div>
|
||||
{/* music sign URL */}
|
||||
<div className="flex flex-col gap-4 rounded-xl border bg-card/40 p-4">
|
||||
<div className="flex items-start gap-2 text-xs leading-relaxed text-muted-foreground">
|
||||
<Music className="mt-0.5 size-3.5 shrink-0" />
|
||||
<p>音乐分享卡片的签名服务,对所有账号统一生效。留空则使用内置默认服务。</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5 border-t pt-3">
|
||||
<Label>音乐签名服务 URL</Label>
|
||||
<Input
|
||||
type="url"
|
||||
inputMode="url"
|
||||
spellCheck={false}
|
||||
placeholder={MUSIC_SIGN_DEFAULT}
|
||||
value={config.musicSignUrl}
|
||||
aria-invalid={config.musicSignUrl.trim().length > 0 && !isHttpUrl(config.musicSignUrl.trim())}
|
||||
className={cn(
|
||||
'font-mono text-xs',
|
||||
config.musicSignUrl.trim().length > 0 && !isHttpUrl(config.musicSignUrl.trim())
|
||||
&& 'border-destructive focus-visible:ring-destructive',
|
||||
)}
|
||||
onChange={(e) => commit({ ...config, musicSignUrl: e.target.value })}
|
||||
/>
|
||||
<p className="text-xs leading-relaxed text-muted-foreground">
|
||||
内置默认:<code className="font-mono">{MUSIC_SIGN_DEFAULT}</code>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{msg && <p className={cn('text-xs', msg.kind === 'ok' ? 'text-success' : 'text-destructive')}>{msg.text}</p>}
|
||||
</div>
|
||||
</SkeletonSwap>
|
||||
);
|
||||
}
|
||||
@@ -2,11 +2,12 @@
|
||||
// info-only cards (name / url / template + an inline enable toggle); creating
|
||||
// and editing always go through a dialog. All changes auto-save (debounced),
|
||||
// like the per-account config page — no explicit save button.
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { motion } from 'motion/react';
|
||||
import { Bell, Loader2, Pencil, Plus, Send, Trash2 } from 'lucide-react';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { ToggleSwitch } from '@/components/ui/toggle-switch';
|
||||
@@ -48,23 +49,22 @@ export function NotificationsPanel() {
|
||||
const saveTimer = useRef<number | null>(null);
|
||||
const saveGen = useRef(0);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
void (async () => {
|
||||
try {
|
||||
const cfg = await api.notifications.getConfig();
|
||||
if (!cancelled) setConfig(cfg);
|
||||
} catch {
|
||||
if (!cancelled) setMsg({ kind: 'err', text: '加载通知配置失败' });
|
||||
} finally {
|
||||
if (!cancelled) setLoading(false);
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
setConfig(await api.notifications.getConfig());
|
||||
} catch (error) {
|
||||
console.error('load notifications config failed', error);
|
||||
setMsg({ kind: 'err', text: '加载通知配置失败' });
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [api, setMsg]);
|
||||
|
||||
useEffect(() => {
|
||||
void load();
|
||||
}, [load]);
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
if (saveTimer.current) clearTimeout(saveTimer.current);
|
||||
@@ -111,9 +111,23 @@ export function NotificationsPanel() {
|
||||
|
||||
if (loading || !config) {
|
||||
return (
|
||||
<div className="flex items-center gap-2 rounded-lg border bg-card/40 p-6 text-sm text-muted-foreground">
|
||||
<Loader2 className="size-4 animate-spin" /> 加载中…
|
||||
</div>
|
||||
<SkeletonSwap
|
||||
ready={!loading}
|
||||
lines={6}
|
||||
lineHeight={26}
|
||||
reserve={156}
|
||||
label="通知配置"
|
||||
className={!loading ? 'skeleton-swap-fluid min-h-[156px]' : ''}
|
||||
>
|
||||
{!loading && !config ? (
|
||||
<div role="alert" className="flex items-center justify-between gap-3 rounded-lg border border-destructive/30 bg-destructive/10 p-4 text-sm text-destructive">
|
||||
<span>{msg?.text ?? '加载通知配置失败'}</span>
|
||||
<Button variant="outline" size="sm" onClick={() => void load()}>
|
||||
重试
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -172,89 +186,98 @@ export function NotificationsPanel() {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* Global settings */}
|
||||
<div className="flex flex-col gap-4 rounded-xl border bg-card/40 p-4">
|
||||
<div className="flex items-start gap-2 text-xs leading-relaxed text-muted-foreground">
|
||||
<Bell className="mt-0.5 size-3.5 shrink-0" />
|
||||
<p>
|
||||
<SkeletonSwap
|
||||
ready
|
||||
lines={6}
|
||||
lineHeight={26}
|
||||
reserve={156}
|
||||
label="通知配置"
|
||||
className="skeleton-swap-fluid min-h-[156px]"
|
||||
>
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* Global settings */}
|
||||
<div className="flex flex-col gap-4 rounded-xl border bg-card/40 p-4">
|
||||
<div className="flex items-start gap-2 text-xs leading-relaxed text-muted-foreground">
|
||||
<Bell className="mt-0.5 size-3.5 shrink-0" />
|
||||
<p>
|
||||
账号上线 / 下线时向启用的渠道 POST 一条通知(机械转发,仅去抖防刷屏)。渠道在此全局定义,每个账号在其「配置」页勾选启用哪些。
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5 border-t pt-3">
|
||||
<Label>去抖窗口(秒)</Label>
|
||||
<Input
|
||||
type="number"
|
||||
min={0}
|
||||
max={3600}
|
||||
className="w-32 tabular-nums"
|
||||
value={config.debounceSeconds}
|
||||
onChange={(e) => {
|
||||
const n = Math.trunc(Number(e.target.value));
|
||||
commit({ ...config, debounceSeconds: Number.isFinite(n) ? Math.min(3600, Math.max(0, n)) : 0 });
|
||||
}}
|
||||
/>
|
||||
<p className="text-xs leading-relaxed text-muted-foreground">
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5 border-t pt-3">
|
||||
<Label>去抖窗口(秒)</Label>
|
||||
<Input
|
||||
type="number"
|
||||
min={0}
|
||||
max={3600}
|
||||
className="w-32 tabular-nums"
|
||||
value={config.debounceSeconds}
|
||||
onChange={(e) => {
|
||||
const n = Math.trunc(Number(e.target.value));
|
||||
commit({ ...config, debounceSeconds: Number.isFinite(n) ? Math.min(3600, Math.max(0, n)) : 0 });
|
||||
}}
|
||||
/>
|
||||
<p className="text-xs leading-relaxed text-muted-foreground">
|
||||
下线后在该秒数内自愈则不发;超时才发「下线」,恢复时再发「上线」。<code className="font-mono">0</code> = 立即发、不去抖。
|
||||
</p>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Channels */}
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-semibold tracking-tight">通知渠道</h3>
|
||||
{channels.length > 0 && (
|
||||
<Button variant="outline" size="sm" onClick={openCreate}>
|
||||
<Plus className="size-3.5" /> 新增渠道
|
||||
</Button>
|
||||
{/* Channels */}
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-semibold tracking-tight">通知渠道</h3>
|
||||
{channels.length > 0 && (
|
||||
<Button variant="outline" size="sm" onClick={openCreate}>
|
||||
<Plus className="size-3.5" /> 新增渠道
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{channels.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-16 text-muted-foreground">
|
||||
<Bell className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">还没有通知渠道</p>
|
||||
<Button variant="outline" size="sm" onClick={openCreate}>
|
||||
<Plus className="size-3.5" /> 创建第一个
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-2">
|
||||
{channels.map((ch, i) => (
|
||||
<ChannelCard
|
||||
key={ch.id}
|
||||
channel={ch}
|
||||
testing={testing === ch.id}
|
||||
onToggle={(v) => setChannels(
|
||||
channels.map((c, idx) => (idx === i ? { ...c, enabled: v } : c)),
|
||||
{ title: '正在更新通知渠道', successTitle: '通知渠道已更新' },
|
||||
)}
|
||||
onTest={() => void test(ch.id)}
|
||||
onEdit={() => openEdit(i)}
|
||||
onDelete={() => setChannels(
|
||||
channels.filter((_, idx) => idx !== i),
|
||||
{ title: '正在删除通知渠道', successTitle: '通知渠道已删除' },
|
||||
)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{channels.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed py-16 text-muted-foreground">
|
||||
<Bell className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">还没有通知渠道</p>
|
||||
<Button variant="outline" size="sm" onClick={openCreate}>
|
||||
<Plus className="size-3.5" /> 创建第一个
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-2">
|
||||
{channels.map((ch, i) => (
|
||||
<ChannelCard
|
||||
key={ch.id}
|
||||
channel={ch}
|
||||
testing={testing === ch.id}
|
||||
onToggle={(v) => setChannels(
|
||||
channels.map((c, idx) => (idx === i ? { ...c, enabled: v } : c)),
|
||||
{ title: '正在更新通知渠道', successTitle: '通知渠道已更新' },
|
||||
)}
|
||||
onTest={() => void test(ch.id)}
|
||||
onEdit={() => openEdit(i)}
|
||||
onDelete={() => setChannels(
|
||||
channels.filter((_, idx) => idx !== i),
|
||||
{ title: '正在删除通知渠道', successTitle: '通知渠道已删除' },
|
||||
)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
{msg && <p className={cn('text-xs', msg.kind === 'ok' ? 'text-success' : 'text-destructive')}>{msg.text}</p>}
|
||||
|
||||
{dialog.open && (
|
||||
<NotificationChannelDialog
|
||||
open={dialog.open}
|
||||
onOpenChange={(open) => !open && setDialog((d) => ({ ...d, open: false }))}
|
||||
isEdit={dialog.index != null}
|
||||
initial={dialog.seed}
|
||||
otherIds={otherIds(dialog.index)}
|
||||
onSubmit={submitChannel}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{msg && <p className={cn('text-xs', msg.kind === 'ok' ? 'text-success' : 'text-destructive')}>{msg.text}</p>}
|
||||
|
||||
{dialog.open && (
|
||||
<NotificationChannelDialog
|
||||
open={dialog.open}
|
||||
onOpenChange={(open) => !open && setDialog((d) => ({ ...d, open: false }))}
|
||||
isEdit={dialog.index != null}
|
||||
initial={dialog.seed}
|
||||
otherIds={otherIds(dialog.index)}
|
||||
onSubmit={submitChannel}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</SkeletonSwap>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import { Label } from '@/components/ui/label';
|
||||
import { Progress } from '@/components/ui/progress';
|
||||
import { ToggleSwitch } from '@/components/ui/toggle-switch';
|
||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { useActionFeedback } from '@/contexts/ActionFeedbackContext';
|
||||
import { useFlashMessage } from '@/hooks/use-flash-message';
|
||||
import { useApi } from '@/lib/api';
|
||||
@@ -107,12 +108,16 @@ export function StoragePanel() {
|
||||
};
|
||||
|
||||
const load = async (showSpinner = false): Promise<boolean> => {
|
||||
if (showSpinner) setRefreshing(true);
|
||||
if (showSpinner) {
|
||||
if (data === null) setLoading(true);
|
||||
else setRefreshing(true);
|
||||
}
|
||||
try {
|
||||
const overview = await api.storage.get();
|
||||
applyOverview(overview);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('load storage overview failed', error);
|
||||
setMsg({
|
||||
kind: 'err',
|
||||
text: error instanceof Error ? error.message : '加载存储信息失败',
|
||||
@@ -222,26 +227,28 @@ export function StoragePanel() {
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
if (loading || !data) {
|
||||
return (
|
||||
<div className="flex items-center gap-2 px-1 py-8 text-sm text-muted-foreground">
|
||||
<Loader2 className="size-4 animate-spin" />
|
||||
加载存储信息…
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<Card>
|
||||
<CardContent className="flex flex-col items-start gap-3 pt-5">
|
||||
<p className="text-sm text-muted-foreground">存储信息暂时不可用。</p>
|
||||
<Button variant="outline" onClick={() => void load(true)}>
|
||||
<RefreshCw className="size-4" />
|
||||
重试
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<SkeletonSwap
|
||||
ready={!loading}
|
||||
lines={7}
|
||||
lineHeight={26}
|
||||
reserve={182}
|
||||
label="存储信息"
|
||||
className={!loading ? 'skeleton-swap-fluid min-h-[182px]' : ''}
|
||||
>
|
||||
{!loading && !data ? (
|
||||
<Card>
|
||||
<CardContent className="flex flex-col items-start gap-3 pt-5">
|
||||
<p className="text-sm text-muted-foreground">存储信息暂时不可用。</p>
|
||||
<Button variant="outline" onClick={() => void load(true)}>
|
||||
<RefreshCw className="size-4" />
|
||||
重试
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -259,310 +266,319 @@ export function StoragePanel() {
|
||||
) as Record<AccountStorageCategory, number>;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
{msg && (
|
||||
<div
|
||||
role="status"
|
||||
className={cn(
|
||||
'rounded-lg px-3 py-2 text-xs',
|
||||
msg.kind === 'ok'
|
||||
? 'bg-emerald-500/10 text-emerald-700 dark:text-emerald-300'
|
||||
: 'bg-red-500/10 text-red-700 dark:text-red-300',
|
||||
)}
|
||||
>
|
||||
{msg.text}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Card>
|
||||
<CardHeader className="gap-3 sm:flex-row sm:items-start sm:justify-between">
|
||||
<div className="min-w-0">
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<HardDrive className="size-4" />
|
||||
存储概览
|
||||
</CardTitle>
|
||||
<CardDescription className="mt-1">
|
||||
只统计 SnowLuma 管理的日志、账号数据库和文件传输临时数据。
|
||||
</CardDescription>
|
||||
</div>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => void load(true)}
|
||||
disabled={refreshing || saving || operation !== null}
|
||||
className="shrink-0"
|
||||
>
|
||||
<RefreshCw className={cn('size-4', refreshing && 'animate-spin')} />
|
||||
刷新
|
||||
</Button>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-5">
|
||||
<div className="grid grid-cols-2 gap-2 sm:grid-cols-4">
|
||||
<Metric label="受管数据总量" value={formatBytes(snapshot.totals.managedBytes)} />
|
||||
<Metric label="日志" value={formatBytes(snapshot.totals.logsBytes)} />
|
||||
<Metric label="账号数据库" value={formatBytes(snapshot.totals.accountDataBytes)} />
|
||||
<Metric label="传输临时数据" value={formatBytes(snapshot.totals.temporaryBytes)} />
|
||||
</div>
|
||||
|
||||
<div className="rounded-lg bg-muted/35 p-3">
|
||||
<div className="mb-2 flex flex-wrap items-center justify-between gap-2">
|
||||
<div>
|
||||
<p className="text-sm font-medium">日志容量</p>
|
||||
<p className="mt-0.5 text-xs tabular-nums text-muted-foreground">
|
||||
{formatBytes(snapshot.logs.totalBytes)} / {formatBytes(snapshot.logs.maxTotalBytes)}
|
||||
</p>
|
||||
</div>
|
||||
<Badge variant={toneBadgeVariant(logPresentation.tone)}>
|
||||
{logPresentation.label}
|
||||
</Badge>
|
||||
</div>
|
||||
<Progress
|
||||
value={logPresentation.percent}
|
||||
aria-label="日志容量使用率"
|
||||
indicatorClassName={toneProgressClass(logPresentation.tone)}
|
||||
/>
|
||||
<div className="mt-2 flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted-foreground">
|
||||
<span>{snapshot.logs.fileCount} 个文件</span>
|
||||
<span>{snapshot.logs.activeFileCount} 个活动文件</span>
|
||||
<span>丢弃 {snapshot.logs.droppedLines} 行磁盘日志</span>
|
||||
</div>
|
||||
{snapshot.logs.lastError && (
|
||||
<div className="mt-3 flex items-start gap-2 rounded-md bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
||||
<AlertTriangle className="mt-0.5 size-3.5 shrink-0" />
|
||||
<span className="break-words">{snapshot.logs.lastError}</span>
|
||||
</div>
|
||||
<SkeletonSwap
|
||||
ready
|
||||
lines={7}
|
||||
lineHeight={26}
|
||||
reserve={182}
|
||||
label="存储信息"
|
||||
className="skeleton-swap-fluid min-h-[182px]"
|
||||
>
|
||||
<div className="flex flex-col gap-5">
|
||||
{msg && (
|
||||
<div
|
||||
role="status"
|
||||
className={cn(
|
||||
'rounded-lg px-3 py-2 text-xs',
|
||||
msg.kind === 'ok'
|
||||
? 'bg-emerald-500/10 text-emerald-700 dark:text-emerald-300'
|
||||
: 'bg-red-500/10 text-red-700 dark:text-red-300',
|
||||
)}
|
||||
>
|
||||
{msg.text}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{data.lastCleanup && <LastCleanupSummary cleanup={data.lastCleanup} />}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<FileClock className="size-4" />
|
||||
日志策略
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
总量上限始终生效;保留天数设为 0 时仅按总量淘汰。保存后立即应用。
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="storage-log-max" className="flex flex-wrap items-center gap-1">
|
||||
日志总量上限(MB)
|
||||
<EnvironmentBadge locked={isLocked('logMaxTotalMb')} />
|
||||
</Label>
|
||||
<Input
|
||||
id="storage-log-max"
|
||||
type="number"
|
||||
min={1}
|
||||
step={1}
|
||||
inputMode="numeric"
|
||||
value={maxTotalMb}
|
||||
onChange={(event) => setMaxTotalMb(event.target.value)}
|
||||
disabled={isLocked('logMaxTotalMb') || saving || operation !== null}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="storage-log-days" className="flex flex-wrap items-center gap-1">
|
||||
保留天数
|
||||
<EnvironmentBadge locked={isLocked('logRetainDays')} />
|
||||
</Label>
|
||||
<Input
|
||||
id="storage-log-days"
|
||||
type="number"
|
||||
min={0}
|
||||
step={1}
|
||||
inputMode="numeric"
|
||||
value={retainDays}
|
||||
onChange={(event) => setRetainDays(event.target.value)}
|
||||
disabled={isLocked('logRetainDays') || saving || operation !== null}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex min-h-11 items-center justify-between gap-4 rounded-lg bg-muted/35 px-3 py-2">
|
||||
<Card>
|
||||
<CardHeader className="gap-3 sm:flex-row sm:items-start sm:justify-between">
|
||||
<div className="min-w-0">
|
||||
<p className="flex flex-wrap items-center gap-1 text-sm font-medium">
|
||||
按账号额外写入日志
|
||||
<EnvironmentBadge locked={isLocked('logPerUin')} />
|
||||
</p>
|
||||
<p className="mt-0.5 text-xs leading-relaxed text-muted-foreground">
|
||||
开启后,同一条带账号上下文的日志还会写入账号子目录,占用会增加。
|
||||
</p>
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<HardDrive className="size-4" />
|
||||
存储概览
|
||||
</CardTitle>
|
||||
<CardDescription className="mt-1">
|
||||
只统计 SnowLuma 管理的日志、账号数据库和文件传输临时数据。
|
||||
</CardDescription>
|
||||
</div>
|
||||
<ToggleSwitch
|
||||
value={perUin}
|
||||
onChange={setPerUin}
|
||||
ariaLabel="按账号额外写入日志"
|
||||
disabled={isLocked('logPerUin') || saving || operation !== null}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Button
|
||||
onClick={() => void saveSettings()}
|
||||
disabled={
|
||||
saving
|
||||
|| operation !== null
|
||||
|| data.settings.envOverrides.length === 3
|
||||
}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => void load(true)}
|
||||
disabled={refreshing || saving || operation !== null}
|
||||
className="shrink-0"
|
||||
>
|
||||
{saving ? <Loader2 className="size-4 animate-spin" /> : <Save className="size-4" />}
|
||||
保存并应用
|
||||
<RefreshCw className={cn('size-4', refreshing && 'animate-spin')} />
|
||||
刷新
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<Trash2 className="size-4" />
|
||||
全局数据清理
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
日志清理会轮转活动文件;临时数据清理会自动跳过正在进行的上传和下载。
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="divide-y divide-border/60 p-0">
|
||||
<CleanupRow
|
||||
icon={FileClock}
|
||||
title="日志"
|
||||
description={`${snapshot.logs.fileCount} 个文件 · ${formatBytes(snapshot.logs.totalBytes)}`}
|
||||
busy={operation === 'logs'}
|
||||
disabled={saving || operation !== null}
|
||||
onClick={() => setPendingCleanup({
|
||||
request: { scope: 'logs' },
|
||||
title: '清理全部日志?',
|
||||
description: 'SnowLuma 会先轮转活动日志,再删除旧日志,只保留新建的空文件。',
|
||||
})}
|
||||
/>
|
||||
<CleanupRow
|
||||
icon={Activity}
|
||||
title="文件传输临时数据"
|
||||
description={`${snapshot.temporary.fileCount} 个文件 · ${formatBytes(snapshot.temporary.totalBytes)} · ${snapshot.temporary.activeItemCount} 个活动传输`}
|
||||
busy={operation === 'temporary'}
|
||||
disabled={saving || operation !== null}
|
||||
onClick={() => setPendingCleanup({
|
||||
request: { scope: 'temporary' },
|
||||
title: '清理非活动临时数据?',
|
||||
description: '正在上传或下载的项目会保留,其余 SnowLuma 文件传输临时数据将被删除。',
|
||||
})}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<Database className="size-4" />
|
||||
账号数据
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
仅清理选中的数据库分类。账号必须离线,配置、凭据和聊天内容导出不在此页面提供。
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-3">
|
||||
{snapshot.accounts.length === 0 ? (
|
||||
<div className="rounded-lg bg-muted/35 px-4 py-6 text-center text-sm text-muted-foreground">
|
||||
尚未发现账号数据库。
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-5">
|
||||
<div className="grid grid-cols-2 gap-2 sm:grid-cols-4">
|
||||
<Metric label="受管数据总量" value={formatBytes(snapshot.totals.managedBytes)} />
|
||||
<Metric label="日志" value={formatBytes(snapshot.totals.logsBytes)} />
|
||||
<Metric label="账号数据库" value={formatBytes(snapshot.totals.accountDataBytes)} />
|
||||
<Metric label="传输临时数据" value={formatBytes(snapshot.totals.temporaryBytes)} />
|
||||
</div>
|
||||
) : (
|
||||
snapshot.accounts.map((account) => (
|
||||
<AccountStorageCard
|
||||
key={account.uin}
|
||||
account={account}
|
||||
operation={operation}
|
||||
saving={saving}
|
||||
onRequest={(category) => {
|
||||
const info = CATEGORY_INFO[category];
|
||||
setPendingCleanup({
|
||||
request: { scope: 'account', category, uin: account.uin },
|
||||
title: `清理 ${account.nickname || account.uin} 的${info.label}?`,
|
||||
description: `将删除账号 ${account.uin} 的${info.label}数据库及其边车文件,其他分类和配置不受影响。`,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
))
|
||||
)}
|
||||
|
||||
{snapshot.accounts.length > 0 && (
|
||||
<div className="rounded-lg bg-muted/35 p-3">
|
||||
<div className="mb-3 flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div className="mb-2 flex flex-wrap items-center justify-between gap-2">
|
||||
<div>
|
||||
<p className="flex items-center gap-2 text-sm font-medium">
|
||||
<Users className="size-4" />
|
||||
全部账号
|
||||
</p>
|
||||
<p className="mt-0.5 text-xs text-muted-foreground">
|
||||
{onlineCount > 0
|
||||
? `${onlineCount} 个账号仍在线,全部账号清理暂不可用`
|
||||
: '选择一个分类,并在弹窗中输入确认短语'}
|
||||
<p className="text-sm font-medium">日志容量</p>
|
||||
<p className="mt-0.5 text-xs tabular-nums text-muted-foreground">
|
||||
{formatBytes(snapshot.logs.totalBytes)} / {formatBytes(snapshot.logs.maxTotalBytes)}
|
||||
</p>
|
||||
</div>
|
||||
<Badge variant={toneBadgeVariant(logPresentation.tone)}>
|
||||
{logPresentation.label}
|
||||
</Badge>
|
||||
</div>
|
||||
<div className="grid gap-2 sm:grid-cols-3">
|
||||
{CATEGORIES.map((category) => (
|
||||
<Button
|
||||
key={category}
|
||||
variant="outline"
|
||||
onClick={() => setAllAccountsCategory(category)}
|
||||
disabled={
|
||||
operation !== null
|
||||
<Progress
|
||||
value={logPresentation.percent}
|
||||
aria-label="日志容量使用率"
|
||||
indicatorClassName={toneProgressClass(logPresentation.tone)}
|
||||
/>
|
||||
<div className="mt-2 flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted-foreground">
|
||||
<span>{snapshot.logs.fileCount} 个文件</span>
|
||||
<span>{snapshot.logs.activeFileCount} 个活动文件</span>
|
||||
<span>丢弃 {snapshot.logs.droppedLines} 行磁盘日志</span>
|
||||
</div>
|
||||
{snapshot.logs.lastError && (
|
||||
<div className="mt-3 flex items-start gap-2 rounded-md bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
||||
<AlertTriangle className="mt-0.5 size-3.5 shrink-0" />
|
||||
<span className="break-words">{snapshot.logs.lastError}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{data.lastCleanup && <LastCleanupSummary cleanup={data.lastCleanup} />}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<FileClock className="size-4" />
|
||||
日志策略
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
总量上限始终生效;保留天数设为 0 时仅按总量淘汰。保存后立即应用。
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="storage-log-max" className="flex flex-wrap items-center gap-1">
|
||||
日志总量上限(MB)
|
||||
<EnvironmentBadge locked={isLocked('logMaxTotalMb')} />
|
||||
</Label>
|
||||
<Input
|
||||
id="storage-log-max"
|
||||
type="number"
|
||||
min={1}
|
||||
step={1}
|
||||
inputMode="numeric"
|
||||
value={maxTotalMb}
|
||||
onChange={(event) => setMaxTotalMb(event.target.value)}
|
||||
disabled={isLocked('logMaxTotalMb') || saving || operation !== null}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="storage-log-days" className="flex flex-wrap items-center gap-1">
|
||||
保留天数
|
||||
<EnvironmentBadge locked={isLocked('logRetainDays')} />
|
||||
</Label>
|
||||
<Input
|
||||
id="storage-log-days"
|
||||
type="number"
|
||||
min={0}
|
||||
step={1}
|
||||
inputMode="numeric"
|
||||
value={retainDays}
|
||||
onChange={(event) => setRetainDays(event.target.value)}
|
||||
disabled={isLocked('logRetainDays') || saving || operation !== null}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex min-h-11 items-center justify-between gap-4 rounded-lg bg-muted/35 px-3 py-2">
|
||||
<div className="min-w-0">
|
||||
<p className="flex flex-wrap items-center gap-1 text-sm font-medium">
|
||||
按账号额外写入日志
|
||||
<EnvironmentBadge locked={isLocked('logPerUin')} />
|
||||
</p>
|
||||
<p className="mt-0.5 text-xs leading-relaxed text-muted-foreground">
|
||||
开启后,同一条带账号上下文的日志还会写入账号子目录,占用会增加。
|
||||
</p>
|
||||
</div>
|
||||
<ToggleSwitch
|
||||
value={perUin}
|
||||
onChange={setPerUin}
|
||||
ariaLabel="按账号额外写入日志"
|
||||
disabled={isLocked('logPerUin') || saving || operation !== null}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Button
|
||||
onClick={() => void saveSettings()}
|
||||
disabled={
|
||||
saving
|
||||
|| operation !== null
|
||||
|| data.settings.envOverrides.length === 3
|
||||
}
|
||||
>
|
||||
{saving ? <Loader2 className="size-4 animate-spin" /> : <Save className="size-4" />}
|
||||
保存并应用
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<Trash2 className="size-4" />
|
||||
全局数据清理
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
日志清理会轮转活动文件;临时数据清理会自动跳过正在进行的上传和下载。
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="divide-y divide-border/60 p-0">
|
||||
<CleanupRow
|
||||
icon={FileClock}
|
||||
title="日志"
|
||||
description={`${snapshot.logs.fileCount} 个文件 · ${formatBytes(snapshot.logs.totalBytes)}`}
|
||||
busy={operation === 'logs'}
|
||||
disabled={saving || operation !== null}
|
||||
onClick={() => setPendingCleanup({
|
||||
request: { scope: 'logs' },
|
||||
title: '清理全部日志?',
|
||||
description: 'SnowLuma 会先轮转活动日志,再删除旧日志,只保留新建的空文件。',
|
||||
})}
|
||||
/>
|
||||
<CleanupRow
|
||||
icon={Activity}
|
||||
title="文件传输临时数据"
|
||||
description={`${snapshot.temporary.fileCount} 个文件 · ${formatBytes(snapshot.temporary.totalBytes)} · ${snapshot.temporary.activeItemCount} 个活动传输`}
|
||||
busy={operation === 'temporary'}
|
||||
disabled={saving || operation !== null}
|
||||
onClick={() => setPendingCleanup({
|
||||
request: { scope: 'temporary' },
|
||||
title: '清理非活动临时数据?',
|
||||
description: '正在上传或下载的项目会保留,其余 SnowLuma 文件传输临时数据将被删除。',
|
||||
})}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<Database className="size-4" />
|
||||
账号数据
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
仅清理选中的数据库分类。账号必须离线,配置、凭据和聊天内容导出不在此页面提供。
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-3">
|
||||
{snapshot.accounts.length === 0 ? (
|
||||
<div className="rounded-lg bg-muted/35 px-4 py-6 text-center text-sm text-muted-foreground">
|
||||
尚未发现账号数据库。
|
||||
</div>
|
||||
) : (
|
||||
snapshot.accounts.map((account) => (
|
||||
<AccountStorageCard
|
||||
key={account.uin}
|
||||
account={account}
|
||||
operation={operation}
|
||||
saving={saving}
|
||||
onRequest={(category) => {
|
||||
const info = CATEGORY_INFO[category];
|
||||
setPendingCleanup({
|
||||
request: { scope: 'account', category, uin: account.uin },
|
||||
title: `清理 ${account.nickname || account.uin} 的${info.label}?`,
|
||||
description: `将删除账号 ${account.uin} 的${info.label}数据库及其边车文件,其他分类和配置不受影响。`,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
))
|
||||
)}
|
||||
|
||||
{snapshot.accounts.length > 0 && (
|
||||
<div className="rounded-lg bg-muted/35 p-3">
|
||||
<div className="mb-3 flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div>
|
||||
<p className="flex items-center gap-2 text-sm font-medium">
|
||||
<Users className="size-4" />
|
||||
全部账号
|
||||
</p>
|
||||
<p className="mt-0.5 text-xs text-muted-foreground">
|
||||
{onlineCount > 0
|
||||
? `${onlineCount} 个账号仍在线,全部账号清理暂不可用`
|
||||
: '选择一个分类,并在弹窗中输入确认短语'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid gap-2 sm:grid-cols-3">
|
||||
{CATEGORIES.map((category) => (
|
||||
<Button
|
||||
key={category}
|
||||
variant="outline"
|
||||
onClick={() => setAllAccountsCategory(category)}
|
||||
disabled={
|
||||
operation !== null
|
||||
|| saving
|
||||
|| onlineCount > 0
|
||||
|| allCategoryBytes[category] === 0
|
||||
}
|
||||
className="justify-between"
|
||||
>
|
||||
<span>清理全部{CATEGORY_INFO[category].label}</span>
|
||||
<span className="text-xs tabular-nums text-muted-foreground">
|
||||
{formatBytes(allCategoryBytes[category])}
|
||||
</span>
|
||||
</Button>
|
||||
))}
|
||||
}
|
||||
className="justify-between"
|
||||
>
|
||||
<span>清理全部{CATEGORY_INFO[category].label}</span>
|
||||
<span className="text-xs tabular-nums text-muted-foreground">
|
||||
{formatBytes(allCategoryBytes[category])}
|
||||
</span>
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<ConfirmDialog
|
||||
open={pendingCleanup !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open && operation === null) setPendingCleanup(null);
|
||||
}}
|
||||
title={pendingCleanup?.title ?? ''}
|
||||
description={pendingCleanup?.description}
|
||||
confirmText="确认清理"
|
||||
destructive
|
||||
onConfirm={async () => {
|
||||
if (!pendingCleanup) return;
|
||||
await runCleanup(pendingCleanup.request);
|
||||
setPendingCleanup(null);
|
||||
}}
|
||||
/>
|
||||
<ConfirmDialog
|
||||
open={pendingCleanup !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open && operation === null) setPendingCleanup(null);
|
||||
}}
|
||||
title={pendingCleanup?.title ?? ''}
|
||||
description={pendingCleanup?.description}
|
||||
confirmText="确认清理"
|
||||
destructive
|
||||
onConfirm={async () => {
|
||||
if (!pendingCleanup) return;
|
||||
await runCleanup(pendingCleanup.request);
|
||||
setPendingCleanup(null);
|
||||
}}
|
||||
/>
|
||||
|
||||
<AllAccountsCleanupDialog
|
||||
category={allAccountsCategory}
|
||||
busy={operation?.startsWith('allAccounts:') ?? false}
|
||||
onOpenChange={(open) => {
|
||||
if (!open && operation === null) setAllAccountsCategory(null);
|
||||
}}
|
||||
onConfirm={async (category) => {
|
||||
await runCleanup({
|
||||
scope: 'allAccounts',
|
||||
category,
|
||||
confirmation: ALL_ACCOUNTS_CONFIRMATION,
|
||||
});
|
||||
setAllAccountsCategory(null);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<AllAccountsCleanupDialog
|
||||
category={allAccountsCategory}
|
||||
busy={operation?.startsWith('allAccounts:') ?? false}
|
||||
onOpenChange={(open) => {
|
||||
if (!open && operation === null) setAllAccountsCategory(null);
|
||||
}}
|
||||
onConfirm={async (category) => {
|
||||
await runCleanup({
|
||||
scope: 'allAccounts',
|
||||
category,
|
||||
confirmation: ALL_ACCOUNTS_CONFIRMATION,
|
||||
});
|
||||
setAllAccountsCategory(null);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</SkeletonSwap>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import { motion } from 'motion/react';
|
||||
import { AlertTriangle, Database, Download, Loader2, Lock, Pencil, Save, ShieldCheck, Trash2, Upload } from 'lucide-react';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
@@ -57,7 +58,8 @@ export function SystemPanel() {
|
||||
setTrustProxy(res.settings.trustProxy);
|
||||
setTlsEnabled(res.settings.tlsEnabled);
|
||||
return true;
|
||||
} catch {
|
||||
} catch (error) {
|
||||
console.error('load system settings failed', error);
|
||||
setMsg({ kind: 'err', text: '加载系统设置失败' });
|
||||
return false;
|
||||
} finally {
|
||||
@@ -211,8 +213,33 @@ export function SystemPanel() {
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return <div className="flex items-center gap-2 px-1 py-8 text-sm text-muted-foreground"><Loader2 className="h-4 w-4 animate-spin" /> 加载中…</div>;
|
||||
if (loading || !data) {
|
||||
return (
|
||||
<SkeletonSwap
|
||||
ready={!loading}
|
||||
lines={7}
|
||||
lineHeight={26}
|
||||
reserve={182}
|
||||
label="系统设置"
|
||||
className={!loading ? 'skeleton-swap-fluid min-h-[182px]' : ''}
|
||||
>
|
||||
{!loading && !data ? (
|
||||
<div role="alert" className="flex items-center justify-between gap-3 rounded-lg border border-destructive/30 bg-destructive/10 p-4 text-sm text-destructive">
|
||||
<span>{msg?.text ?? '加载系统设置失败'}</span>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
setLoading(true);
|
||||
void load();
|
||||
}}
|
||||
>
|
||||
重试
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
);
|
||||
}
|
||||
|
||||
const EnvBadge = ({ field }: { field: string }) =>
|
||||
@@ -221,190 +248,199 @@ export function SystemPanel() {
|
||||
: null;
|
||||
|
||||
return (
|
||||
<motion.div initial={{ opacity: 0, y: 8 }} animate={{ opacity: 1, y: 0 }} className="flex flex-col gap-5">
|
||||
{/* restart-to-apply notice */}
|
||||
<div className="flex items-start gap-2 rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-700 dark:text-amber-300">
|
||||
<AlertTriangle className="mt-0.5 h-3.5 w-3.5 shrink-0" />
|
||||
<span>监听相关设置(端口 / 绑定地址 / HTTPS)属服务级配置,保存后需<strong>重启 SnowLuma</strong> 才生效;本机无自动重启。</span>
|
||||
</div>
|
||||
<SkeletonSwap
|
||||
ready
|
||||
lines={7}
|
||||
lineHeight={26}
|
||||
reserve={182}
|
||||
label="系统设置"
|
||||
className="skeleton-swap-fluid min-h-[182px]"
|
||||
>
|
||||
<motion.div initial={{ opacity: 0, y: 8 }} animate={{ opacity: 1, y: 0 }} className="flex flex-col gap-5">
|
||||
{/* restart-to-apply notice */}
|
||||
<div className="flex items-start gap-2 rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-700 dark:text-amber-300">
|
||||
<AlertTriangle className="mt-0.5 h-3.5 w-3.5 shrink-0" />
|
||||
<span>监听相关设置(端口 / 绑定地址 / HTTPS)属服务级配置,保存后需<strong>重启 SnowLuma</strong> 才生效;本机无自动重启。</span>
|
||||
</div>
|
||||
|
||||
{msg && (
|
||||
<div className={cn('rounded-lg px-3 py-2 text-xs', msg.kind === 'ok'
|
||||
? 'bg-emerald-500/10 text-emerald-700 dark:text-emerald-300'
|
||||
: 'bg-red-500/10 text-red-700 dark:text-red-300')}>{msg.text}</div>
|
||||
)}
|
||||
{msg && (
|
||||
<div className={cn('rounded-lg px-3 py-2 text-xs', msg.kind === 'ok'
|
||||
? 'bg-emerald-500/10 text-emerald-700 dark:text-emerald-300'
|
||||
: 'bg-red-500/10 text-red-700 dark:text-red-300')}>{msg.text}</div>
|
||||
)}
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-sm">服务监听</CardTitle>
|
||||
<CardDescription>WebUI 当前监听端口:{data?.listeningPort}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label className="flex items-center">端口<EnvBadge field="webuiPort" /></Label>
|
||||
<Input value={port} onChange={(e) => setPort(e.target.value)} inputMode="numeric" placeholder="5099" />
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label className="flex items-center">绑定地址<EnvBadge field="webuiHost" /></Label>
|
||||
<Select value={host} onChange={(e) => setHost(e.target.value)}>
|
||||
<option value="0.0.0.0">0.0.0.0(所有网卡)</option>
|
||||
<option value="127.0.0.1">127.0.0.1(仅本机)</option>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label className="flex items-center">信任代理 (trust-proxy)<EnvBadge field="trustProxy" /></Label>
|
||||
<Input value={trustProxy} onChange={(e) => setTrustProxy(e.target.value)} placeholder="留空=只信任 socket 对端;1=信任反代头" />
|
||||
<p className="text-xs text-muted-foreground">仅在 WebUI 位于受信任反向代理之后时才设为 1 / loopback / IP 列表。</p>
|
||||
</div>
|
||||
<div>
|
||||
<Button onClick={saveSettings} disabled={saving} className="gap-1.5">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />} 保存
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-sm">服务监听</CardTitle>
|
||||
<CardDescription>WebUI 当前监听端口:{data?.listeningPort}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label className="flex items-center">端口<EnvBadge field="webuiPort" /></Label>
|
||||
<Input value={port} onChange={(e) => setPort(e.target.value)} inputMode="numeric" placeholder="5099" />
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label className="flex items-center">绑定地址<EnvBadge field="webuiHost" /></Label>
|
||||
<Select value={host} onChange={(e) => setHost(e.target.value)}>
|
||||
<option value="0.0.0.0">0.0.0.0(所有网卡)</option>
|
||||
<option value="127.0.0.1">127.0.0.1(仅本机)</option>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label className="flex items-center">信任代理 (trust-proxy)<EnvBadge field="trustProxy" /></Label>
|
||||
<Input value={trustProxy} onChange={(e) => setTrustProxy(e.target.value)} placeholder="留空=只信任 socket 对端;1=信任反代头" />
|
||||
<p className="text-xs text-muted-foreground">仅在 WebUI 位于受信任反向代理之后时才设为 1 / loopback / IP 列表。</p>
|
||||
</div>
|
||||
<div>
|
||||
<Button onClick={saveSettings} disabled={saving} className="gap-1.5">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />} 保存
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<ShieldCheck className="h-4 w-4" /> HTTPS / TLS
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
{data?.hasCert ? '已安装证书。' : '尚未安装证书。'} 启用 TLS 需先安装有效的证书与私钥(PEM)。
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label>启用 HTTPS</Label>
|
||||
<ToggleSwitch value={tlsEnabled} onChange={setTlsEnabled} ariaLabel="启用 HTTPS" />
|
||||
</div>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm">
|
||||
<ShieldCheck className="h-4 w-4" /> HTTPS / TLS
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
{data?.hasCert ? '已安装证书。' : '尚未安装证书。'} 启用 TLS 需先安装有效的证书与私钥(PEM)。
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label>启用 HTTPS</Label>
|
||||
<ToggleSwitch value={tlsEnabled} onChange={setTlsEnabled} ariaLabel="启用 HTTPS" />
|
||||
</div>
|
||||
|
||||
{data?.hasCert && !editingCert ? (
|
||||
{data?.hasCert && !editingCert ? (
|
||||
// Cert already installed — don't re-render the sensitive PEM. Show a
|
||||
// summary + actions; private key is never sent back to the client.
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex items-center gap-2 rounded-lg border border-border bg-muted/30 px-3 py-2 text-xs text-muted-foreground">
|
||||
<ShieldCheck className="h-4 w-4 text-emerald-500" />
|
||||
<span>证书与私钥已安装(出于安全不回显,未改变)。</span>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button variant="outline" onClick={() => setEditingCert(true)} className="gap-1.5">
|
||||
<Pencil className="h-4 w-4" /> 更改证书
|
||||
</Button>
|
||||
<Button variant="outline" onClick={() => setConfirmDeleteCert(true)} disabled={saving} className="gap-1.5">
|
||||
<Trash2 className="h-4 w-4" /> 删除证书
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label>证书 (cert.pem)</Label>
|
||||
<Textarea className="min-h-28 font-mono text-xs" value={certPem} onChange={(e) => setCertPem(e.target.value)} placeholder="-----BEGIN CERTIFICATE-----" />
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label>私钥 (key.pem)</Label>
|
||||
<Textarea className="min-h-28 font-mono text-xs" value={keyPem} onChange={(e) => setKeyPem(e.target.value)} placeholder="-----BEGIN PRIVATE KEY-----" />
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button onClick={uploadCert} disabled={saving} className="gap-1.5">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />} 保存证书
|
||||
</Button>
|
||||
{data?.hasCert && editingCert && (
|
||||
<Button variant="outline" onClick={() => { setEditingCert(false); setCertPem(''); setKeyPem(''); }} className="gap-1.5">
|
||||
取消
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex items-center gap-2 rounded-lg border border-border bg-muted/30 px-3 py-2 text-xs text-muted-foreground">
|
||||
<ShieldCheck className="h-4 w-4 text-emerald-500" />
|
||||
<span>证书与私钥已安装(出于安全不回显,未改变)。</span>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button variant="outline" onClick={() => setEditingCert(true)} className="gap-1.5">
|
||||
<Pencil className="h-4 w-4" /> 更改证书
|
||||
</Button>
|
||||
)}
|
||||
<Button variant="outline" onClick={() => setConfirmDeleteCert(true)} disabled={saving} className="gap-1.5">
|
||||
<Trash2 className="h-4 w-4" /> 删除证书
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
) : (
|
||||
<>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label>证书 (cert.pem)</Label>
|
||||
<Textarea className="min-h-28 font-mono text-xs" value={certPem} onChange={(e) => setCertPem(e.target.value)} placeholder="-----BEGIN CERTIFICATE-----" />
|
||||
</div>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label>私钥 (key.pem)</Label>
|
||||
<Textarea className="min-h-28 font-mono text-xs" value={keyPem} onChange={(e) => setKeyPem(e.target.value)} placeholder="-----BEGIN PRIVATE KEY-----" />
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button onClick={uploadCert} disabled={saving} className="gap-1.5">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />} 保存证书
|
||||
</Button>
|
||||
{data?.hasCert && editingCert && (
|
||||
<Button variant="outline" onClick={() => { setEditingCert(false); setCertPem(''); setKeyPem(''); }} className="gap-1.5">
|
||||
取消
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
私钥仅写入服务器 config/key.pem(0600 权限),不会回显。证书无效时保存会被拒绝;若启用了 TLS 但证书加载失败,启动时会自动回退到 HTTP。
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm"><Database className="h-4 w-4" /> 配置备份 / 恢复</CardTitle>
|
||||
<CardDescription>备份外观、通知、系统设置和证书等配置;敏感开关还会包含 OneBot 配置。不含消息数据库。</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label>导出时包含敏感配置</Label>
|
||||
<ToggleSwitch value={exportCreds} onChange={setExportCreds} ariaLabel="导出包含敏感配置" />
|
||||
</div>
|
||||
{exportCreds && (
|
||||
<p className="text-sm leading-relaxed text-red-600 dark:text-red-400">⚠ 将额外包含 WebUI 登录状态、TLS 私钥,以及带访问令牌的 OneBot 配置,请妥善保管。</p>
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
<div>
|
||||
<Button onClick={exportBackup} disabled={saving} className="gap-1.5">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Download className="h-4 w-4" />} 导出备份
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-sm"><Database className="h-4 w-4" /> 配置备份 / 恢复</CardTitle>
|
||||
<CardDescription>备份外观、通知、系统设置和证书等配置;敏感开关还会包含 OneBot 配置。不含消息数据库。</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label>导出时包含敏感配置</Label>
|
||||
<ToggleSwitch value={exportCreds} onChange={setExportCreds} ariaLabel="导出包含敏感配置" />
|
||||
</div>
|
||||
{exportCreds && (
|
||||
<p className="text-sm leading-relaxed text-red-600 dark:text-red-400">⚠ 将额外包含 WebUI 登录状态、TLS 私钥,以及带访问令牌的 OneBot 配置,请妥善保管。</p>
|
||||
)}
|
||||
<div>
|
||||
<Button onClick={exportBackup} disabled={saving} className="gap-1.5">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Download className="h-4 w-4" />} 导出备份
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="h-px bg-border" />
|
||||
<div className="h-px bg-border" />
|
||||
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label>恢复时一并恢复敏感配置</Label>
|
||||
<ToggleSwitch value={restoreCreds} onChange={setRestoreCreds} ariaLabel="恢复包含敏感配置" />
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label>恢复时一并恢复敏感配置</Label>
|
||||
<ToggleSwitch value={restoreCreds} onChange={setRestoreCreds} ariaLabel="恢复包含敏感配置" />
|
||||
</div>
|
||||
{restoreCreds && (
|
||||
<p className="text-sm leading-relaxed text-red-600 dark:text-red-400">⚠ 将覆盖当前 WebUI 登录状态、TLS 私钥与 OneBot 配置(含访问令牌);若备份口令未知可能登不进。</p>
|
||||
)}
|
||||
<input
|
||||
ref={fileRef}
|
||||
type="file"
|
||||
accept="application/json,.json"
|
||||
className="hidden"
|
||||
onChange={(e) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (file) setPendingBackup(file);
|
||||
e.target.value = '';
|
||||
}}
|
||||
/>
|
||||
<div>
|
||||
<Button variant="outline" onClick={() => fileRef.current?.click()} disabled={saving} className="gap-1.5">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Upload className="h-4 w-4" />} 选择备份文件并恢复
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-xs leading-relaxed text-muted-foreground">恢复前会校验本次要恢复的配置;写入过程中出错会自动回滚,成功后临时快照会删除。恢复后需重启生效。</p>
|
||||
</div>
|
||||
{restoreCreds && (
|
||||
<p className="text-sm leading-relaxed text-red-600 dark:text-red-400">⚠ 将覆盖当前 WebUI 登录状态、TLS 私钥与 OneBot 配置(含访问令牌);若备份口令未知可能登不进。</p>
|
||||
)}
|
||||
<input
|
||||
ref={fileRef}
|
||||
type="file"
|
||||
accept="application/json,.json"
|
||||
className="hidden"
|
||||
onChange={(e) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (file) setPendingBackup(file);
|
||||
e.target.value = '';
|
||||
}}
|
||||
/>
|
||||
<div>
|
||||
<Button variant="outline" onClick={() => fileRef.current?.click()} disabled={saving} className="gap-1.5">
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Upload className="h-4 w-4" />} 选择备份文件并恢复
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-xs leading-relaxed text-muted-foreground">恢复前会校验本次要恢复的配置;写入过程中出错会自动回滚,成功后临时快照会删除。恢复后需重启生效。</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<ConfirmDialog
|
||||
open={confirmDeleteCert}
|
||||
onOpenChange={setConfirmDeleteCert}
|
||||
title="删除 TLS 证书?"
|
||||
description="将移除服务器上的证书与私钥。若 HTTPS 仍处于启用状态,下次启动将无法继续使用当前证书。"
|
||||
confirmText="删除证书"
|
||||
destructive
|
||||
onConfirm={deleteCert}
|
||||
/>
|
||||
<ConfirmDialog
|
||||
open={confirmDeleteCert}
|
||||
onOpenChange={setConfirmDeleteCert}
|
||||
title="删除 TLS 证书?"
|
||||
description="将移除服务器上的证书与私钥。若 HTTPS 仍处于启用状态,下次启动将无法继续使用当前证书。"
|
||||
confirmText="删除证书"
|
||||
destructive
|
||||
onConfirm={deleteCert}
|
||||
/>
|
||||
|
||||
<ConfirmDialog
|
||||
open={pendingBackup !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setPendingBackup(null);
|
||||
}}
|
||||
title="恢复配置备份?"
|
||||
description={
|
||||
pendingBackup
|
||||
? `将从 ${pendingBackup.name} 覆盖当前系统配置${restoreCreds ? ',包括敏感配置、TLS 私钥与 OneBot 配置' : ''}。成功后需要重启 SnowLuma。`
|
||||
: ''
|
||||
}
|
||||
confirmText="确认恢复"
|
||||
destructive
|
||||
onConfirm={async () => {
|
||||
if (!pendingBackup) return;
|
||||
await importBackup(pendingBackup);
|
||||
setPendingBackup(null);
|
||||
}}
|
||||
/>
|
||||
</motion.div>
|
||||
<ConfirmDialog
|
||||
open={pendingBackup !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setPendingBackup(null);
|
||||
}}
|
||||
title="恢复配置备份?"
|
||||
description={
|
||||
pendingBackup
|
||||
? `将从 ${pendingBackup.name} 覆盖当前系统配置${restoreCreds ? ',包括敏感配置、TLS 私钥与 OneBot 配置' : ''}。成功后需要重启 SnowLuma。`
|
||||
: ''
|
||||
}
|
||||
confirmText="确认恢复"
|
||||
destructive
|
||||
onConfirm={async () => {
|
||||
if (!pendingBackup) return;
|
||||
await importBackup(pendingBackup);
|
||||
setPendingBackup(null);
|
||||
}}
|
||||
/>
|
||||
</motion.div>
|
||||
</SkeletonSwap>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user