dsh-plugin-image-workbench 1.1.5 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.en.md +5 -3
- package/README.md +7 -3
- package/client.js +241 -241
- package/cordis.patch.yml +14 -14
- package/host.js +51 -0
- package/install.mjs +333 -387
- package/package.json +3 -2
- package/scripts/fetch-style-images.mjs +104 -0
- package/scripts/vendor-snapshot.py +154 -154
- package/server/access.py +26 -26
- package/server/app.py +1329 -1329
- package/server/catalog.py +147 -147
- package/server/composer.py +391 -391
- package/server/drafts.py +158 -158
- package/server/history.py +575 -575
- package/server/imaging.py +172 -172
- package/server/pool.py +1335 -1335
- package/server/pool_admin.py +921 -921
- package/server/pool_service.py +1073 -1073
- package/server/requirements.txt +6 -6
- package/server/smoke_check.py +402 -402
- package/server/static/access.html +202 -202
- package/vendor/chatgpt2api/source/.env.example +82 -82
- package/vendor/chatgpt2api/source/.python-version +1 -1
- package/vendor/chatgpt2api/source/LICENSE +21 -21
- package/vendor/chatgpt2api/source/README.md +391 -391
- package/vendor/chatgpt2api/source/VERSION +1 -1
- package/vendor/chatgpt2api/source/api/__init__.py +2 -2
- package/vendor/chatgpt2api/source/api/accounts.py +537 -537
- package/vendor/chatgpt2api/source/api/ai.py +217 -217
- package/vendor/chatgpt2api/source/api/app.py +62 -62
- package/vendor/chatgpt2api/source/api/errors.py +46 -46
- package/vendor/chatgpt2api/source/api/image_inputs.py +309 -309
- package/vendor/chatgpt2api/source/api/image_tasks.py +120 -120
- package/vendor/chatgpt2api/source/api/support.py +134 -134
- package/vendor/chatgpt2api/source/api/system.py +365 -365
- package/vendor/chatgpt2api/source/assets/kunrouai.svg +50 -50
- package/vendor/chatgpt2api/source/config.default.json +108 -108
- package/vendor/chatgpt2api/source/main.py +9 -9
- package/vendor/chatgpt2api/source/pyproject.toml +27 -27
- package/vendor/chatgpt2api/source/scripts/init_proxy_config.py +186 -186
- package/vendor/chatgpt2api/source/scripts/migrate_storage.py +163 -163
- package/vendor/chatgpt2api/source/scripts/privoxy-warp.conf +13 -13
- package/vendor/chatgpt2api/source/scripts/test_outlook_token_mailbox.py +385 -385
- package/vendor/chatgpt2api/source/scripts/test_storage.py +129 -129
- package/vendor/chatgpt2api/source/scripts/verify_oauth_refresh.py +92 -92
- package/vendor/chatgpt2api/source/services/account_service.py +1757 -1757
- package/vendor/chatgpt2api/source/services/auth_service.py +253 -253
- package/vendor/chatgpt2api/source/services/backup_service.py +671 -671
- package/vendor/chatgpt2api/source/services/config.py +667 -667
- package/vendor/chatgpt2api/source/services/content_filter.py +242 -242
- package/vendor/chatgpt2api/source/services/cpa_service.py +315 -315
- package/vendor/chatgpt2api/source/services/editable_file_task_service.py +260 -260
- package/vendor/chatgpt2api/source/services/image_service.py +376 -376
- package/vendor/chatgpt2api/source/services/image_storage_service.py +405 -405
- package/vendor/chatgpt2api/source/services/image_tags_service.py +76 -76
- package/vendor/chatgpt2api/source/services/image_task_service.py +550 -550
- package/vendor/chatgpt2api/source/services/log_service.py +337 -337
- package/vendor/chatgpt2api/source/services/model_service.py +182 -182
- package/vendor/chatgpt2api/source/services/oauth_login_service.py +267 -267
- package/vendor/chatgpt2api/source/services/openai_backend_api.py +2763 -2763
- package/vendor/chatgpt2api/source/services/openai_oauth.py +32 -32
- package/vendor/chatgpt2api/source/services/protocol/__init__.py +2 -2
- package/vendor/chatgpt2api/source/services/protocol/anthropic_v1_messages.py +307 -307
- package/vendor/chatgpt2api/source/services/protocol/chat_completion_cache.py +238 -238
- package/vendor/chatgpt2api/source/services/protocol/conversation.py +1644 -1644
- package/vendor/chatgpt2api/source/services/protocol/error_response.py +124 -124
- package/vendor/chatgpt2api/source/services/protocol/openai_search.py +19 -19
- package/vendor/chatgpt2api/source/services/protocol/openai_v1_chat_complete.py +316 -316
- package/vendor/chatgpt2api/source/services/protocol/openai_v1_image_edit.py +86 -86
- package/vendor/chatgpt2api/source/services/protocol/openai_v1_image_generations.py +42 -42
- package/vendor/chatgpt2api/source/services/protocol/openai_v1_models.py +53 -53
- package/vendor/chatgpt2api/source/services/protocol/openai_v1_response.py +453 -453
- package/vendor/chatgpt2api/source/services/protocol/web_search_tool.py +160 -160
- package/vendor/chatgpt2api/source/services/proxy_service.py +648 -648
- package/vendor/chatgpt2api/source/services/storage/__init__.py +5 -5
- package/vendor/chatgpt2api/source/services/storage/base.py +38 -38
- package/vendor/chatgpt2api/source/services/storage/database_storage.py +194 -194
- package/vendor/chatgpt2api/source/services/storage/factory.py +104 -104
- package/vendor/chatgpt2api/source/services/storage/git_storage.py +183 -183
- package/vendor/chatgpt2api/source/services/storage/json_storage.py +95 -95
- package/vendor/chatgpt2api/source/services/sub2api_service.py +531 -531
- package/vendor/chatgpt2api/source/utils/helper.py +469 -469
- package/vendor/chatgpt2api/source/utils/image_tokens.py +346 -346
- package/vendor/chatgpt2api/source/utils/log.py +110 -110
- package/vendor/chatgpt2api/source/utils/pkce.py +19 -19
- package/vendor/chatgpt2api/source/utils/pow.py +207 -207
- package/vendor/chatgpt2api/source/utils/sentinel.py +159 -159
- package/vendor/chatgpt2api/source/utils/turnstile.py +184 -184
- package/vendor/chatgpt2api/source/uv.lock +904 -904
- package/vendor/chatgpt2api/source/web/bun.lock +1501 -1501
- package/vendor/chatgpt2api/source/web/components.json +24 -24
- package/vendor/chatgpt2api/source/web/eslint.config.mjs +17 -17
- package/vendor/chatgpt2api/source/web/next.config.ts +40 -40
- package/vendor/chatgpt2api/source/web/package.json +58 -58
- package/vendor/chatgpt2api/source/web/postcss.config.mjs +5 -5
- package/vendor/chatgpt2api/source/web/src/app/accounts/components/account-import-dialog.tsx +925 -925
- package/vendor/chatgpt2api/source/web/src/app/accounts/page.tsx +1307 -1307
- package/vendor/chatgpt2api/source/web/src/app/debug/components/chat-panel.tsx +224 -224
- package/vendor/chatgpt2api/source/web/src/app/debug/components/editable-file-panel.tsx +444 -444
- package/vendor/chatgpt2api/source/web/src/app/debug/components/ppt-panel.tsx +9 -9
- package/vendor/chatgpt2api/source/web/src/app/debug/components/psd-panel.tsx +9 -9
- package/vendor/chatgpt2api/source/web/src/app/debug/components/search-panel.tsx +172 -172
- package/vendor/chatgpt2api/source/web/src/app/debug/components/skill-panel.tsx +169 -169
- package/vendor/chatgpt2api/source/web/src/app/debug/components/types.ts +39 -39
- package/vendor/chatgpt2api/source/web/src/app/debug/page.tsx +59 -59
- package/vendor/chatgpt2api/source/web/src/app/globals.css +230 -230
- package/vendor/chatgpt2api/source/web/src/app/image/components/image-composer.tsx +542 -542
- package/vendor/chatgpt2api/source/web/src/app/image/components/image-results.tsx +554 -554
- package/vendor/chatgpt2api/source/web/src/app/image/components/image-sidebar.tsx +176 -176
- package/vendor/chatgpt2api/source/web/src/app/image/page.tsx +1799 -1799
- package/vendor/chatgpt2api/source/web/src/app/image-manager/page.tsx +732 -732
- package/vendor/chatgpt2api/source/web/src/app/layout.tsx +50 -50
- package/vendor/chatgpt2api/source/web/src/app/login/page.tsx +101 -101
- package/vendor/chatgpt2api/source/web/src/app/logs/page.tsx +356 -356
- package/vendor/chatgpt2api/source/web/src/app/page.tsx +30 -30
- package/vendor/chatgpt2api/source/web/src/app/settings/components/api-docs-card.tsx +341 -341
- package/vendor/chatgpt2api/source/web/src/app/settings/components/backup-settings-card.tsx +447 -447
- package/vendor/chatgpt2api/source/web/src/app/settings/components/base-url-card.tsx +71 -71
- package/vendor/chatgpt2api/source/web/src/app/settings/components/config-card.tsx +491 -491
- package/vendor/chatgpt2api/source/web/src/app/settings/components/cpa-pool-dialog.tsx +108 -108
- package/vendor/chatgpt2api/source/web/src/app/settings/components/cpa-pools-card.tsx +169 -169
- package/vendor/chatgpt2api/source/web/src/app/settings/components/import-browser-dialog.tsx +185 -185
- package/vendor/chatgpt2api/source/web/src/app/settings/components/proxy-runtime-card.tsx +379 -379
- package/vendor/chatgpt2api/source/web/src/app/settings/components/proxy-settings-card.tsx +127 -127
- package/vendor/chatgpt2api/source/web/src/app/settings/components/proxy-settings.tsx +200 -200
- package/vendor/chatgpt2api/source/web/src/app/settings/components/settings-header.tsx +12 -12
- package/vendor/chatgpt2api/source/web/src/app/settings/components/sub2api-connections.tsx +886 -886
- package/vendor/chatgpt2api/source/web/src/app/settings/components/third-party-apps-card.tsx +81 -81
- package/vendor/chatgpt2api/source/web/src/app/settings/components/user-keys-card.tsx +422 -422
- package/vendor/chatgpt2api/source/web/src/app/settings/page.tsx +135 -135
- package/vendor/chatgpt2api/source/web/src/app/settings/store.ts +1069 -1069
- package/vendor/chatgpt2api/source/web/src/components/date-range-filter.tsx +49 -49
- package/vendor/chatgpt2api/source/web/src/components/header-actions.tsx +24 -24
- package/vendor/chatgpt2api/source/web/src/components/image-lightbox.tsx +434 -434
- package/vendor/chatgpt2api/source/web/src/components/image-thumbnail.tsx +46 -46
- package/vendor/chatgpt2api/source/web/src/components/theme-script.tsx +18 -18
- package/vendor/chatgpt2api/source/web/src/components/theme-toggle.tsx +14 -14
- package/vendor/chatgpt2api/source/web/src/components/top-nav.tsx +263 -263
- package/vendor/chatgpt2api/source/web/src/components/ui/animated-theme-toggler.tsx +256 -256
- package/vendor/chatgpt2api/source/web/src/components/ui/badge.tsx +41 -41
- package/vendor/chatgpt2api/source/web/src/components/ui/button.tsx +59 -59
- package/vendor/chatgpt2api/source/web/src/components/ui/calendar.tsx +46 -46
- package/vendor/chatgpt2api/source/web/src/components/ui/card.tsx +61 -61
- package/vendor/chatgpt2api/source/web/src/components/ui/checkbox.tsx +27 -27
- package/vendor/chatgpt2api/source/web/src/components/ui/dia-text-reveal.tsx +267 -267
- package/vendor/chatgpt2api/source/web/src/components/ui/dialog.tsx +132 -132
- package/vendor/chatgpt2api/source/web/src/components/ui/field.tsx +13 -13
- package/vendor/chatgpt2api/source/web/src/components/ui/input.tsx +19 -19
- package/vendor/chatgpt2api/source/web/src/components/ui/label.tsx +24 -24
- package/vendor/chatgpt2api/source/web/src/components/ui/morphing-text.tsx +149 -149
- package/vendor/chatgpt2api/source/web/src/components/ui/popover.tsx +38 -38
- package/vendor/chatgpt2api/source/web/src/components/ui/select.tsx +175 -175
- package/vendor/chatgpt2api/source/web/src/components/ui/sheet.tsx +143 -143
- package/vendor/chatgpt2api/source/web/src/components/ui/table.tsx +29 -29
- package/vendor/chatgpt2api/source/web/src/components/ui/tabs.tsx +91 -91
- package/vendor/chatgpt2api/source/web/src/components/ui/text-3d-flip.tsx +269 -269
- package/vendor/chatgpt2api/source/web/src/components/ui/textarea.tsx +18 -18
- package/vendor/chatgpt2api/source/web/src/components/version-release-dialog.tsx +127 -127
- package/vendor/chatgpt2api/source/web/src/constants/common-env.ts +6 -6
- package/vendor/chatgpt2api/source/web/src/hooks/use-version-check.ts +85 -85
- package/vendor/chatgpt2api/source/web/src/lib/api.ts +926 -926
- package/vendor/chatgpt2api/source/web/src/lib/auth-session.ts +26 -26
- package/vendor/chatgpt2api/source/web/src/lib/release.ts +25 -25
- package/vendor/chatgpt2api/source/web/src/lib/request.ts +93 -93
- package/vendor/chatgpt2api/source/web/src/lib/use-auth-guard.ts +89 -89
- package/vendor/chatgpt2api/source/web/src/lib/utils.ts +6 -6
- package/vendor/chatgpt2api/source/web/src/store/auth.ts +112 -112
- package/vendor/chatgpt2api/source/web/src/store/editable-file-history.ts +33 -33
- package/vendor/chatgpt2api/source/web/src/store/image-conversations.ts +318 -318
- package/vendor/chatgpt2api/source/web/tsconfig.json +42 -42
|
@@ -1,356 +1,356 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import { useEffect, useMemo, useState } from "react";
|
|
4
|
-
import { ChevronLeft, ChevronRight, ImageIcon, LoaderCircle, RefreshCw, Search, Trash2 } from "lucide-react";
|
|
5
|
-
import { toast } from "sonner";
|
|
6
|
-
|
|
7
|
-
import { DateRangeFilter } from "@/components/date-range-filter";
|
|
8
|
-
import { ImageLightbox } from "@/components/image-lightbox";
|
|
9
|
-
import { ImageThumbnail, getImageThumbnailUrl } from "@/components/image-thumbnail";
|
|
10
|
-
import { Badge } from "@/components/ui/badge";
|
|
11
|
-
import { Button } from "@/components/ui/button";
|
|
12
|
-
import { Card, CardContent } from "@/components/ui/card";
|
|
13
|
-
import { Checkbox } from "@/components/ui/checkbox";
|
|
14
|
-
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
|
15
|
-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
|
16
|
-
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
|
17
|
-
import { deleteSystemLogs, fetchSystemLogs, type SystemLog } from "@/lib/api";
|
|
18
|
-
import { useAuthGuard } from "@/lib/use-auth-guard";
|
|
19
|
-
|
|
20
|
-
const LogType = {
|
|
21
|
-
Call: "call",
|
|
22
|
-
Account: "account",
|
|
23
|
-
} as const;
|
|
24
|
-
|
|
25
|
-
const typeLabels: Record<string, string> = {
|
|
26
|
-
[LogType.Call]: "调用日志",
|
|
27
|
-
[LogType.Account]: "账号管理日志",
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
function getDetailText(item: SystemLog, key: string) {
|
|
31
|
-
const value = item.detail?.[key];
|
|
32
|
-
return typeof value === "string" || typeof value === "number" ? String(value) : "-";
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function formatDuration(item: SystemLog) {
|
|
36
|
-
const value = item.detail?.duration_ms;
|
|
37
|
-
return typeof value === "number" ? `${(value / 1000).toFixed(2)} s` : "-";
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function getUrls(item: SystemLog | null) {
|
|
41
|
-
const urls = item?.detail?.urls;
|
|
42
|
-
return Array.isArray(urls) ? urls.filter((url): url is string => typeof url === "string") : [];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function getStatus(item: SystemLog) {
|
|
46
|
-
const status = item.detail?.status;
|
|
47
|
-
if (status === "success") return "成功";
|
|
48
|
-
if (status === "failed") return "失败";
|
|
49
|
-
return "-";
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function LogsContent() {
|
|
53
|
-
const [items, setItems] = useState<SystemLog[]>([]);
|
|
54
|
-
const [type, setType] = useState<string>(LogType.Call);
|
|
55
|
-
const [startDate, setStartDate] = useState("");
|
|
56
|
-
const [endDate, setEndDate] = useState("");
|
|
57
|
-
const [detailLog, setDetailLog] = useState<SystemLog | null>(null);
|
|
58
|
-
const [detailOpen, setDetailOpen] = useState(false);
|
|
59
|
-
const [lightboxIndex, setLightboxIndex] = useState(0);
|
|
60
|
-
const [lightboxOpen, setLightboxOpen] = useState(false);
|
|
61
|
-
const [page, setPage] = useState(1);
|
|
62
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
63
|
-
const [isDeleting, setIsDeleting] = useState(false);
|
|
64
|
-
const [selectedIds, setSelectedIds] = useState<string[]>([]);
|
|
65
|
-
const [deletingItems, setDeletingItems] = useState<SystemLog[]>([]);
|
|
66
|
-
const detailUrls = getUrls(detailLog);
|
|
67
|
-
const detailImages = detailUrls.map((url, index) => ({ id: `${index}`, src: url }));
|
|
68
|
-
const isCallLog = type === LogType.Call;
|
|
69
|
-
const pageSize = 10;
|
|
70
|
-
const pageCount = Math.max(1, Math.ceil(items.length / pageSize));
|
|
71
|
-
const safePage = Math.min(page, pageCount);
|
|
72
|
-
const currentRows = items.slice((safePage - 1) * pageSize, safePage * pageSize);
|
|
73
|
-
const selectedSet = useMemo(() => new Set(selectedIds), [selectedIds]);
|
|
74
|
-
const currentPageSelected = currentRows.length > 0 && currentRows.every((item) => selectedSet.has(item.id));
|
|
75
|
-
const allSelected = items.length > 0 && items.every((item) => selectedSet.has(item.id));
|
|
76
|
-
|
|
77
|
-
const loadLogs = async () => {
|
|
78
|
-
setIsLoading(true);
|
|
79
|
-
try {
|
|
80
|
-
const data = await fetchSystemLogs({ type, start_date: startDate, end_date: endDate });
|
|
81
|
-
setItems(data.items);
|
|
82
|
-
setSelectedIds((current) => current.filter((id) => data.items.some((item) => item.id === id)));
|
|
83
|
-
setPage(1);
|
|
84
|
-
} catch (error) {
|
|
85
|
-
toast.error(error instanceof Error ? error.message : "加载日志失败");
|
|
86
|
-
} finally {
|
|
87
|
-
setIsLoading(false);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const clearFilters = () => {
|
|
92
|
-
setStartDate("");
|
|
93
|
-
setEndDate("");
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const openDetail = (item: SystemLog) => {
|
|
97
|
-
setDetailLog(item);
|
|
98
|
-
setDetailOpen(true);
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const openLogImage = (item: SystemLog, index: number) => {
|
|
102
|
-
setDetailLog(item);
|
|
103
|
-
setLightboxIndex(index);
|
|
104
|
-
setLightboxOpen(true);
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const toggleIds = (ids: string[], checked: boolean) => {
|
|
108
|
-
setSelectedIds((current) => checked ? Array.from(new Set([...current, ...ids])) : current.filter((id) => !ids.includes(id)));
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const confirmDelete = async () => {
|
|
112
|
-
const ids = deletingItems.map((item) => item.id);
|
|
113
|
-
if (ids.length === 0) return;
|
|
114
|
-
setIsDeleting(true);
|
|
115
|
-
try {
|
|
116
|
-
const data = await deleteSystemLogs(ids);
|
|
117
|
-
toast.success(`已删除 ${data.removed} 条日志`);
|
|
118
|
-
setDeletingItems([]);
|
|
119
|
-
setSelectedIds((current) => current.filter((id) => !ids.includes(id)));
|
|
120
|
-
if (detailLog && ids.includes(detailLog.id)) {
|
|
121
|
-
setDetailOpen(false);
|
|
122
|
-
setDetailLog(null);
|
|
123
|
-
}
|
|
124
|
-
await loadLogs();
|
|
125
|
-
} catch (error) {
|
|
126
|
-
toast.error(error instanceof Error ? error.message : "删除日志失败");
|
|
127
|
-
} finally {
|
|
128
|
-
setIsDeleting(false);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
useEffect(() => {
|
|
133
|
-
void loadLogs();
|
|
134
|
-
}, [type, startDate, endDate]);
|
|
135
|
-
|
|
136
|
-
return (
|
|
137
|
-
<section className="space-y-5">
|
|
138
|
-
<div className="flex flex-col gap-4 lg:flex-row lg:items-end lg:justify-between">
|
|
139
|
-
<div className="space-y-1">
|
|
140
|
-
<div className="text-xs font-semibold tracking-[0.18em] text-stone-500 uppercase">Logs</div>
|
|
141
|
-
<h1 className="text-2xl font-semibold tracking-tight">日志管理</h1>
|
|
142
|
-
</div>
|
|
143
|
-
<div className="flex flex-wrap gap-2">
|
|
144
|
-
<Select value={type} onValueChange={setType}>
|
|
145
|
-
<SelectTrigger className="h-10 w-[150px] rounded-xl border-stone-200 bg-white"><SelectValue /></SelectTrigger>
|
|
146
|
-
<SelectContent>
|
|
147
|
-
<SelectItem value={LogType.Call}>调用日志</SelectItem>
|
|
148
|
-
<SelectItem value={LogType.Account}>账号管理日志</SelectItem>
|
|
149
|
-
</SelectContent>
|
|
150
|
-
</Select>
|
|
151
|
-
<DateRangeFilter startDate={startDate} endDate={endDate} onChange={(start, end) => { setStartDate(start); setEndDate(end); }} />
|
|
152
|
-
<Button variant="outline" onClick={clearFilters} className="h-10 rounded-xl border-stone-200 bg-white px-4 text-stone-700">
|
|
153
|
-
清除筛选条件
|
|
154
|
-
</Button>
|
|
155
|
-
<Button onClick={() => void loadLogs()} disabled={isLoading} className="h-10 rounded-xl bg-stone-950 px-4 text-white hover:bg-stone-800">
|
|
156
|
-
{isLoading ? <LoaderCircle className="size-4 animate-spin" /> : <Search className="size-4" />}
|
|
157
|
-
查询
|
|
158
|
-
</Button>
|
|
159
|
-
</div>
|
|
160
|
-
</div>
|
|
161
|
-
|
|
162
|
-
<Card className="overflow-hidden rounded-2xl border-white/80 bg-white/90 shadow-sm">
|
|
163
|
-
<CardContent className="p-0">
|
|
164
|
-
<div className="flex flex-wrap items-center justify-between gap-3 border-b border-stone-100 px-5 py-4">
|
|
165
|
-
<div className="flex flex-wrap items-center gap-3 text-sm text-stone-600">
|
|
166
|
-
<span>共 {items.length} 条</span>
|
|
167
|
-
<label className="flex items-center gap-2">
|
|
168
|
-
<Checkbox checked={currentPageSelected} onCheckedChange={(checked) => toggleIds(currentRows.map((item) => item.id), Boolean(checked))} />
|
|
169
|
-
本页全选
|
|
170
|
-
</label>
|
|
171
|
-
<label className="flex items-center gap-2">
|
|
172
|
-
<Checkbox checked={allSelected} onCheckedChange={(checked) => toggleIds(items.map((item) => item.id), Boolean(checked))} />
|
|
173
|
-
全选结果
|
|
174
|
-
</label>
|
|
175
|
-
{selectedIds.length > 0 ? <span>已选 {selectedIds.length} 条</span> : null}
|
|
176
|
-
</div>
|
|
177
|
-
<div className="flex items-center gap-2">
|
|
178
|
-
<Button variant="ghost" className="h-8 rounded-lg px-3 text-stone-500" onClick={() => void loadLogs()} disabled={isLoading}>
|
|
179
|
-
<RefreshCw className={`size-4 ${isLoading ? "animate-spin" : ""}`} />
|
|
180
|
-
刷新
|
|
181
|
-
</Button>
|
|
182
|
-
<button type="button" className="text-sm text-stone-500 hover:text-stone-900 disabled:text-stone-300" onClick={() => setSelectedIds([])} disabled={selectedIds.length === 0 || isDeleting}>
|
|
183
|
-
取消选择
|
|
184
|
-
</button>
|
|
185
|
-
<Button variant="outline" className="h-8 rounded-lg border-rose-200 bg-white px-3 text-rose-600 hover:bg-rose-50" onClick={() => setDeletingItems(items.filter((item) => selectedSet.has(item.id)))} disabled={selectedIds.length === 0 || isDeleting}>
|
|
186
|
-
<Trash2 className="size-4" />
|
|
187
|
-
删除所选
|
|
188
|
-
</Button>
|
|
189
|
-
</div>
|
|
190
|
-
</div>
|
|
191
|
-
<div className="overflow-x-auto">
|
|
192
|
-
<Table className="min-w-[900px]">
|
|
193
|
-
<TableHeader>
|
|
194
|
-
<TableRow>
|
|
195
|
-
<TableHead className="w-12"></TableHead>
|
|
196
|
-
<TableHead>时间</TableHead>
|
|
197
|
-
<TableHead>类型</TableHead>
|
|
198
|
-
{isCallLog ? <TableHead>令牌名称</TableHead> : null}
|
|
199
|
-
{isCallLog ? <TableHead>调用耗时</TableHead> : null}
|
|
200
|
-
{isCallLog ? <TableHead>状态</TableHead> : null}
|
|
201
|
-
{isCallLog ? <TableHead className="w-36">图片</TableHead> : null}
|
|
202
|
-
<TableHead>简述</TableHead>
|
|
203
|
-
<TableHead className="w-40">操作</TableHead>
|
|
204
|
-
</TableRow>
|
|
205
|
-
</TableHeader>
|
|
206
|
-
<TableBody>
|
|
207
|
-
{currentRows.map((item) => {
|
|
208
|
-
const urls = getUrls(item);
|
|
209
|
-
return (
|
|
210
|
-
<TableRow key={item.id} className="text-stone-600">
|
|
211
|
-
<TableCell>
|
|
212
|
-
<Checkbox checked={selectedSet.has(item.id)} onCheckedChange={(checked) => toggleIds([item.id], Boolean(checked))} />
|
|
213
|
-
</TableCell>
|
|
214
|
-
<TableCell className="whitespace-nowrap">{item.time}</TableCell>
|
|
215
|
-
<TableCell><Badge variant="secondary" className="rounded-md">{typeLabels[item.type] || item.type}</Badge></TableCell>
|
|
216
|
-
{isCallLog ? <TableCell>{getDetailText(item, "key_name")}</TableCell> : null}
|
|
217
|
-
{isCallLog ? <TableCell>{formatDuration(item)}</TableCell> : null}
|
|
218
|
-
{isCallLog ? (
|
|
219
|
-
<TableCell>
|
|
220
|
-
<Badge variant={item.detail?.status === "failed" ? "danger" : "success"} className="rounded-md">
|
|
221
|
-
{getStatus(item)}
|
|
222
|
-
</Badge>
|
|
223
|
-
</TableCell>
|
|
224
|
-
) : null}
|
|
225
|
-
{isCallLog ? (
|
|
226
|
-
<TableCell>
|
|
227
|
-
{urls.length ? (
|
|
228
|
-
<div className="flex items-center gap-1.5">
|
|
229
|
-
{urls.slice(0, 3).map((url, imageIndex) => (
|
|
230
|
-
<button
|
|
231
|
-
key={`${url}-${imageIndex}`}
|
|
232
|
-
type="button"
|
|
233
|
-
className="relative size-9 overflow-hidden rounded-lg border border-stone-200 bg-stone-100"
|
|
234
|
-
onClick={() => openLogImage(item, imageIndex)}
|
|
235
|
-
title="预览图片"
|
|
236
|
-
>
|
|
237
|
-
<ImageThumbnail src={url} thumbnailSrc={getImageThumbnailUrl(url)} className="h-full w-full" />
|
|
238
|
-
</button>
|
|
239
|
-
))}
|
|
240
|
-
{urls.length > 3 ? <span className="text-xs text-stone-400">+{urls.length - 3}</span> : null}
|
|
241
|
-
</div>
|
|
242
|
-
) : (
|
|
243
|
-
<span className="inline-flex items-center gap-1 text-xs text-stone-400">
|
|
244
|
-
<ImageIcon className="size-3.5" />
|
|
245
|
-
-
|
|
246
|
-
</span>
|
|
247
|
-
)}
|
|
248
|
-
</TableCell>
|
|
249
|
-
) : null}
|
|
250
|
-
<TableCell className="max-w-[420px] truncate text-stone-500">{item.summary || "-"}</TableCell>
|
|
251
|
-
<TableCell>
|
|
252
|
-
<div className="flex items-center gap-1">
|
|
253
|
-
<Button variant="ghost" className="h-8 rounded-lg px-3 text-stone-600" onClick={() => openDetail(item)}>
|
|
254
|
-
查看详情
|
|
255
|
-
</Button>
|
|
256
|
-
<Button variant="ghost" className="h-8 rounded-lg px-3 text-rose-600 hover:bg-rose-50 hover:text-rose-700" onClick={() => setDeletingItems([item])}>
|
|
257
|
-
删除
|
|
258
|
-
</Button>
|
|
259
|
-
</div>
|
|
260
|
-
</TableCell>
|
|
261
|
-
</TableRow>
|
|
262
|
-
);
|
|
263
|
-
})}
|
|
264
|
-
</TableBody>
|
|
265
|
-
</Table>
|
|
266
|
-
</div>
|
|
267
|
-
<div className="flex items-center justify-end gap-2 border-t border-stone-100 px-4 py-3 text-sm text-stone-500">
|
|
268
|
-
<span>第 {safePage} / {pageCount} 页,共 {items.length} 条</span>
|
|
269
|
-
<Button variant="outline" size="icon" className="size-9 rounded-lg border-stone-200 bg-white" disabled={safePage <= 1} onClick={() => setPage((value) => Math.max(1, value - 1))}>
|
|
270
|
-
<ChevronLeft className="size-4" />
|
|
271
|
-
</Button>
|
|
272
|
-
<Button variant="outline" size="icon" className="size-9 rounded-lg border-stone-200 bg-white" disabled={safePage >= pageCount} onClick={() => setPage((value) => Math.min(pageCount, value + 1))}>
|
|
273
|
-
<ChevronRight className="size-4" />
|
|
274
|
-
</Button>
|
|
275
|
-
</div>
|
|
276
|
-
{!isLoading && items.length === 0 ? <div className="px-6 py-14 text-center text-sm text-stone-500">没有找到日志</div> : null}
|
|
277
|
-
</CardContent>
|
|
278
|
-
</Card>
|
|
279
|
-
<Dialog open={detailOpen} onOpenChange={setDetailOpen}>
|
|
280
|
-
<DialogContent className="flex h-[min(88vh,860px)] w-[min(92vw,920px)] flex-col overflow-hidden rounded-2xl p-0">
|
|
281
|
-
<DialogHeader className="shrink-0 border-b border-stone-100 px-6 py-5">
|
|
282
|
-
<DialogTitle>日志详情</DialogTitle>
|
|
283
|
-
</DialogHeader>
|
|
284
|
-
<div className="flex-1 overflow-y-auto px-6 py-5">
|
|
285
|
-
<div className="space-y-4">
|
|
286
|
-
<div className="grid gap-3 rounded-xl border border-stone-200 bg-white p-4 text-sm text-stone-600 md:grid-cols-2">
|
|
287
|
-
{Object.entries(detailLog?.detail || {})
|
|
288
|
-
.filter(([key, value]) => key !== "urls" && typeof value !== "object")
|
|
289
|
-
.map(([key, value]) => (
|
|
290
|
-
<div key={key} className="flex items-start justify-between gap-4">
|
|
291
|
-
<span className="text-stone-400">{key}</span>
|
|
292
|
-
<span className="text-right font-medium break-all text-stone-700">{String(value)}</span>
|
|
293
|
-
</div>
|
|
294
|
-
))}
|
|
295
|
-
</div>
|
|
296
|
-
{detailUrls.length ? (
|
|
297
|
-
<div className="grid gap-3 sm:grid-cols-2 md:grid-cols-3">
|
|
298
|
-
{detailUrls.map((url, index) => (
|
|
299
|
-
<button
|
|
300
|
-
key={url}
|
|
301
|
-
type="button"
|
|
302
|
-
className="aspect-square overflow-hidden rounded-xl border border-stone-200 bg-stone-100"
|
|
303
|
-
onClick={() => {
|
|
304
|
-
setLightboxIndex(index);
|
|
305
|
-
setLightboxOpen(true);
|
|
306
|
-
}}
|
|
307
|
-
>
|
|
308
|
-
<img src={url} alt="" className="h-full w-full object-cover" />
|
|
309
|
-
</button>
|
|
310
|
-
))}
|
|
311
|
-
</div>
|
|
312
|
-
) : null}
|
|
313
|
-
<pre className="max-h-[72vh] overflow-auto rounded-xl border border-stone-200 bg-stone-50 p-4 text-xs leading-6 text-stone-700">
|
|
314
|
-
{JSON.stringify(detailLog?.detail || {}, null, 2)}
|
|
315
|
-
</pre>
|
|
316
|
-
</div>
|
|
317
|
-
</div>
|
|
318
|
-
</DialogContent>
|
|
319
|
-
</Dialog>
|
|
320
|
-
<ImageLightbox
|
|
321
|
-
images={detailImages}
|
|
322
|
-
currentIndex={lightboxIndex}
|
|
323
|
-
open={lightboxOpen}
|
|
324
|
-
onOpenChange={setLightboxOpen}
|
|
325
|
-
onIndexChange={setLightboxIndex}
|
|
326
|
-
/>
|
|
327
|
-
<Dialog open={deletingItems.length > 0} onOpenChange={(open) => (!open ? setDeletingItems([]) : null)}>
|
|
328
|
-
<DialogContent showCloseButton={false} className="rounded-2xl p-6">
|
|
329
|
-
<DialogHeader className="gap-2">
|
|
330
|
-
<DialogTitle>{deletingItems.length === 1 ? "删除日志" : "删除所选日志"}</DialogTitle>
|
|
331
|
-
<DialogDescription className="text-sm leading-6">
|
|
332
|
-
确认删除 {deletingItems.length} 条日志吗?删除后无法恢复。
|
|
333
|
-
</DialogDescription>
|
|
334
|
-
</DialogHeader>
|
|
335
|
-
<DialogFooter>
|
|
336
|
-
<Button variant="outline" className="rounded-xl" onClick={() => setDeletingItems([])} disabled={isDeleting}>
|
|
337
|
-
取消
|
|
338
|
-
</Button>
|
|
339
|
-
<Button className="rounded-xl bg-rose-600 text-white hover:bg-rose-700" onClick={() => void confirmDelete()} disabled={isDeleting || deletingItems.length === 0}>
|
|
340
|
-
{isDeleting ? <LoaderCircle className="size-4 animate-spin" /> : null}
|
|
341
|
-
确认删除
|
|
342
|
-
</Button>
|
|
343
|
-
</DialogFooter>
|
|
344
|
-
</DialogContent>
|
|
345
|
-
</Dialog>
|
|
346
|
-
</section>
|
|
347
|
-
);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
export default function LogsPage() {
|
|
351
|
-
const { isCheckingAuth, session } = useAuthGuard(["admin"]);
|
|
352
|
-
if (isCheckingAuth || !session || session.role !== "admin") {
|
|
353
|
-
return <div className="flex min-h-[40vh] items-center justify-center"><LoaderCircle className="size-5 animate-spin text-stone-400" /></div>;
|
|
354
|
-
}
|
|
355
|
-
return <LogsContent />;
|
|
356
|
-
}
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useMemo, useState } from "react";
|
|
4
|
+
import { ChevronLeft, ChevronRight, ImageIcon, LoaderCircle, RefreshCw, Search, Trash2 } from "lucide-react";
|
|
5
|
+
import { toast } from "sonner";
|
|
6
|
+
|
|
7
|
+
import { DateRangeFilter } from "@/components/date-range-filter";
|
|
8
|
+
import { ImageLightbox } from "@/components/image-lightbox";
|
|
9
|
+
import { ImageThumbnail, getImageThumbnailUrl } from "@/components/image-thumbnail";
|
|
10
|
+
import { Badge } from "@/components/ui/badge";
|
|
11
|
+
import { Button } from "@/components/ui/button";
|
|
12
|
+
import { Card, CardContent } from "@/components/ui/card";
|
|
13
|
+
import { Checkbox } from "@/components/ui/checkbox";
|
|
14
|
+
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
|
15
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
|
16
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
|
17
|
+
import { deleteSystemLogs, fetchSystemLogs, type SystemLog } from "@/lib/api";
|
|
18
|
+
import { useAuthGuard } from "@/lib/use-auth-guard";
|
|
19
|
+
|
|
20
|
+
const LogType = {
|
|
21
|
+
Call: "call",
|
|
22
|
+
Account: "account",
|
|
23
|
+
} as const;
|
|
24
|
+
|
|
25
|
+
const typeLabels: Record<string, string> = {
|
|
26
|
+
[LogType.Call]: "调用日志",
|
|
27
|
+
[LogType.Account]: "账号管理日志",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function getDetailText(item: SystemLog, key: string) {
|
|
31
|
+
const value = item.detail?.[key];
|
|
32
|
+
return typeof value === "string" || typeof value === "number" ? String(value) : "-";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function formatDuration(item: SystemLog) {
|
|
36
|
+
const value = item.detail?.duration_ms;
|
|
37
|
+
return typeof value === "number" ? `${(value / 1000).toFixed(2)} s` : "-";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getUrls(item: SystemLog | null) {
|
|
41
|
+
const urls = item?.detail?.urls;
|
|
42
|
+
return Array.isArray(urls) ? urls.filter((url): url is string => typeof url === "string") : [];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getStatus(item: SystemLog) {
|
|
46
|
+
const status = item.detail?.status;
|
|
47
|
+
if (status === "success") return "成功";
|
|
48
|
+
if (status === "failed") return "失败";
|
|
49
|
+
return "-";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function LogsContent() {
|
|
53
|
+
const [items, setItems] = useState<SystemLog[]>([]);
|
|
54
|
+
const [type, setType] = useState<string>(LogType.Call);
|
|
55
|
+
const [startDate, setStartDate] = useState("");
|
|
56
|
+
const [endDate, setEndDate] = useState("");
|
|
57
|
+
const [detailLog, setDetailLog] = useState<SystemLog | null>(null);
|
|
58
|
+
const [detailOpen, setDetailOpen] = useState(false);
|
|
59
|
+
const [lightboxIndex, setLightboxIndex] = useState(0);
|
|
60
|
+
const [lightboxOpen, setLightboxOpen] = useState(false);
|
|
61
|
+
const [page, setPage] = useState(1);
|
|
62
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
63
|
+
const [isDeleting, setIsDeleting] = useState(false);
|
|
64
|
+
const [selectedIds, setSelectedIds] = useState<string[]>([]);
|
|
65
|
+
const [deletingItems, setDeletingItems] = useState<SystemLog[]>([]);
|
|
66
|
+
const detailUrls = getUrls(detailLog);
|
|
67
|
+
const detailImages = detailUrls.map((url, index) => ({ id: `${index}`, src: url }));
|
|
68
|
+
const isCallLog = type === LogType.Call;
|
|
69
|
+
const pageSize = 10;
|
|
70
|
+
const pageCount = Math.max(1, Math.ceil(items.length / pageSize));
|
|
71
|
+
const safePage = Math.min(page, pageCount);
|
|
72
|
+
const currentRows = items.slice((safePage - 1) * pageSize, safePage * pageSize);
|
|
73
|
+
const selectedSet = useMemo(() => new Set(selectedIds), [selectedIds]);
|
|
74
|
+
const currentPageSelected = currentRows.length > 0 && currentRows.every((item) => selectedSet.has(item.id));
|
|
75
|
+
const allSelected = items.length > 0 && items.every((item) => selectedSet.has(item.id));
|
|
76
|
+
|
|
77
|
+
const loadLogs = async () => {
|
|
78
|
+
setIsLoading(true);
|
|
79
|
+
try {
|
|
80
|
+
const data = await fetchSystemLogs({ type, start_date: startDate, end_date: endDate });
|
|
81
|
+
setItems(data.items);
|
|
82
|
+
setSelectedIds((current) => current.filter((id) => data.items.some((item) => item.id === id)));
|
|
83
|
+
setPage(1);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
toast.error(error instanceof Error ? error.message : "加载日志失败");
|
|
86
|
+
} finally {
|
|
87
|
+
setIsLoading(false);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const clearFilters = () => {
|
|
92
|
+
setStartDate("");
|
|
93
|
+
setEndDate("");
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const openDetail = (item: SystemLog) => {
|
|
97
|
+
setDetailLog(item);
|
|
98
|
+
setDetailOpen(true);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const openLogImage = (item: SystemLog, index: number) => {
|
|
102
|
+
setDetailLog(item);
|
|
103
|
+
setLightboxIndex(index);
|
|
104
|
+
setLightboxOpen(true);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const toggleIds = (ids: string[], checked: boolean) => {
|
|
108
|
+
setSelectedIds((current) => checked ? Array.from(new Set([...current, ...ids])) : current.filter((id) => !ids.includes(id)));
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const confirmDelete = async () => {
|
|
112
|
+
const ids = deletingItems.map((item) => item.id);
|
|
113
|
+
if (ids.length === 0) return;
|
|
114
|
+
setIsDeleting(true);
|
|
115
|
+
try {
|
|
116
|
+
const data = await deleteSystemLogs(ids);
|
|
117
|
+
toast.success(`已删除 ${data.removed} 条日志`);
|
|
118
|
+
setDeletingItems([]);
|
|
119
|
+
setSelectedIds((current) => current.filter((id) => !ids.includes(id)));
|
|
120
|
+
if (detailLog && ids.includes(detailLog.id)) {
|
|
121
|
+
setDetailOpen(false);
|
|
122
|
+
setDetailLog(null);
|
|
123
|
+
}
|
|
124
|
+
await loadLogs();
|
|
125
|
+
} catch (error) {
|
|
126
|
+
toast.error(error instanceof Error ? error.message : "删除日志失败");
|
|
127
|
+
} finally {
|
|
128
|
+
setIsDeleting(false);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
void loadLogs();
|
|
134
|
+
}, [type, startDate, endDate]);
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<section className="space-y-5">
|
|
138
|
+
<div className="flex flex-col gap-4 lg:flex-row lg:items-end lg:justify-between">
|
|
139
|
+
<div className="space-y-1">
|
|
140
|
+
<div className="text-xs font-semibold tracking-[0.18em] text-stone-500 uppercase">Logs</div>
|
|
141
|
+
<h1 className="text-2xl font-semibold tracking-tight">日志管理</h1>
|
|
142
|
+
</div>
|
|
143
|
+
<div className="flex flex-wrap gap-2">
|
|
144
|
+
<Select value={type} onValueChange={setType}>
|
|
145
|
+
<SelectTrigger className="h-10 w-[150px] rounded-xl border-stone-200 bg-white"><SelectValue /></SelectTrigger>
|
|
146
|
+
<SelectContent>
|
|
147
|
+
<SelectItem value={LogType.Call}>调用日志</SelectItem>
|
|
148
|
+
<SelectItem value={LogType.Account}>账号管理日志</SelectItem>
|
|
149
|
+
</SelectContent>
|
|
150
|
+
</Select>
|
|
151
|
+
<DateRangeFilter startDate={startDate} endDate={endDate} onChange={(start, end) => { setStartDate(start); setEndDate(end); }} />
|
|
152
|
+
<Button variant="outline" onClick={clearFilters} className="h-10 rounded-xl border-stone-200 bg-white px-4 text-stone-700">
|
|
153
|
+
清除筛选条件
|
|
154
|
+
</Button>
|
|
155
|
+
<Button onClick={() => void loadLogs()} disabled={isLoading} className="h-10 rounded-xl bg-stone-950 px-4 text-white hover:bg-stone-800">
|
|
156
|
+
{isLoading ? <LoaderCircle className="size-4 animate-spin" /> : <Search className="size-4" />}
|
|
157
|
+
查询
|
|
158
|
+
</Button>
|
|
159
|
+
</div>
|
|
160
|
+
</div>
|
|
161
|
+
|
|
162
|
+
<Card className="overflow-hidden rounded-2xl border-white/80 bg-white/90 shadow-sm">
|
|
163
|
+
<CardContent className="p-0">
|
|
164
|
+
<div className="flex flex-wrap items-center justify-between gap-3 border-b border-stone-100 px-5 py-4">
|
|
165
|
+
<div className="flex flex-wrap items-center gap-3 text-sm text-stone-600">
|
|
166
|
+
<span>共 {items.length} 条</span>
|
|
167
|
+
<label className="flex items-center gap-2">
|
|
168
|
+
<Checkbox checked={currentPageSelected} onCheckedChange={(checked) => toggleIds(currentRows.map((item) => item.id), Boolean(checked))} />
|
|
169
|
+
本页全选
|
|
170
|
+
</label>
|
|
171
|
+
<label className="flex items-center gap-2">
|
|
172
|
+
<Checkbox checked={allSelected} onCheckedChange={(checked) => toggleIds(items.map((item) => item.id), Boolean(checked))} />
|
|
173
|
+
全选结果
|
|
174
|
+
</label>
|
|
175
|
+
{selectedIds.length > 0 ? <span>已选 {selectedIds.length} 条</span> : null}
|
|
176
|
+
</div>
|
|
177
|
+
<div className="flex items-center gap-2">
|
|
178
|
+
<Button variant="ghost" className="h-8 rounded-lg px-3 text-stone-500" onClick={() => void loadLogs()} disabled={isLoading}>
|
|
179
|
+
<RefreshCw className={`size-4 ${isLoading ? "animate-spin" : ""}`} />
|
|
180
|
+
刷新
|
|
181
|
+
</Button>
|
|
182
|
+
<button type="button" className="text-sm text-stone-500 hover:text-stone-900 disabled:text-stone-300" onClick={() => setSelectedIds([])} disabled={selectedIds.length === 0 || isDeleting}>
|
|
183
|
+
取消选择
|
|
184
|
+
</button>
|
|
185
|
+
<Button variant="outline" className="h-8 rounded-lg border-rose-200 bg-white px-3 text-rose-600 hover:bg-rose-50" onClick={() => setDeletingItems(items.filter((item) => selectedSet.has(item.id)))} disabled={selectedIds.length === 0 || isDeleting}>
|
|
186
|
+
<Trash2 className="size-4" />
|
|
187
|
+
删除所选
|
|
188
|
+
</Button>
|
|
189
|
+
</div>
|
|
190
|
+
</div>
|
|
191
|
+
<div className="overflow-x-auto">
|
|
192
|
+
<Table className="min-w-[900px]">
|
|
193
|
+
<TableHeader>
|
|
194
|
+
<TableRow>
|
|
195
|
+
<TableHead className="w-12"></TableHead>
|
|
196
|
+
<TableHead>时间</TableHead>
|
|
197
|
+
<TableHead>类型</TableHead>
|
|
198
|
+
{isCallLog ? <TableHead>令牌名称</TableHead> : null}
|
|
199
|
+
{isCallLog ? <TableHead>调用耗时</TableHead> : null}
|
|
200
|
+
{isCallLog ? <TableHead>状态</TableHead> : null}
|
|
201
|
+
{isCallLog ? <TableHead className="w-36">图片</TableHead> : null}
|
|
202
|
+
<TableHead>简述</TableHead>
|
|
203
|
+
<TableHead className="w-40">操作</TableHead>
|
|
204
|
+
</TableRow>
|
|
205
|
+
</TableHeader>
|
|
206
|
+
<TableBody>
|
|
207
|
+
{currentRows.map((item) => {
|
|
208
|
+
const urls = getUrls(item);
|
|
209
|
+
return (
|
|
210
|
+
<TableRow key={item.id} className="text-stone-600">
|
|
211
|
+
<TableCell>
|
|
212
|
+
<Checkbox checked={selectedSet.has(item.id)} onCheckedChange={(checked) => toggleIds([item.id], Boolean(checked))} />
|
|
213
|
+
</TableCell>
|
|
214
|
+
<TableCell className="whitespace-nowrap">{item.time}</TableCell>
|
|
215
|
+
<TableCell><Badge variant="secondary" className="rounded-md">{typeLabels[item.type] || item.type}</Badge></TableCell>
|
|
216
|
+
{isCallLog ? <TableCell>{getDetailText(item, "key_name")}</TableCell> : null}
|
|
217
|
+
{isCallLog ? <TableCell>{formatDuration(item)}</TableCell> : null}
|
|
218
|
+
{isCallLog ? (
|
|
219
|
+
<TableCell>
|
|
220
|
+
<Badge variant={item.detail?.status === "failed" ? "danger" : "success"} className="rounded-md">
|
|
221
|
+
{getStatus(item)}
|
|
222
|
+
</Badge>
|
|
223
|
+
</TableCell>
|
|
224
|
+
) : null}
|
|
225
|
+
{isCallLog ? (
|
|
226
|
+
<TableCell>
|
|
227
|
+
{urls.length ? (
|
|
228
|
+
<div className="flex items-center gap-1.5">
|
|
229
|
+
{urls.slice(0, 3).map((url, imageIndex) => (
|
|
230
|
+
<button
|
|
231
|
+
key={`${url}-${imageIndex}`}
|
|
232
|
+
type="button"
|
|
233
|
+
className="relative size-9 overflow-hidden rounded-lg border border-stone-200 bg-stone-100"
|
|
234
|
+
onClick={() => openLogImage(item, imageIndex)}
|
|
235
|
+
title="预览图片"
|
|
236
|
+
>
|
|
237
|
+
<ImageThumbnail src={url} thumbnailSrc={getImageThumbnailUrl(url)} className="h-full w-full" />
|
|
238
|
+
</button>
|
|
239
|
+
))}
|
|
240
|
+
{urls.length > 3 ? <span className="text-xs text-stone-400">+{urls.length - 3}</span> : null}
|
|
241
|
+
</div>
|
|
242
|
+
) : (
|
|
243
|
+
<span className="inline-flex items-center gap-1 text-xs text-stone-400">
|
|
244
|
+
<ImageIcon className="size-3.5" />
|
|
245
|
+
-
|
|
246
|
+
</span>
|
|
247
|
+
)}
|
|
248
|
+
</TableCell>
|
|
249
|
+
) : null}
|
|
250
|
+
<TableCell className="max-w-[420px] truncate text-stone-500">{item.summary || "-"}</TableCell>
|
|
251
|
+
<TableCell>
|
|
252
|
+
<div className="flex items-center gap-1">
|
|
253
|
+
<Button variant="ghost" className="h-8 rounded-lg px-3 text-stone-600" onClick={() => openDetail(item)}>
|
|
254
|
+
查看详情
|
|
255
|
+
</Button>
|
|
256
|
+
<Button variant="ghost" className="h-8 rounded-lg px-3 text-rose-600 hover:bg-rose-50 hover:text-rose-700" onClick={() => setDeletingItems([item])}>
|
|
257
|
+
删除
|
|
258
|
+
</Button>
|
|
259
|
+
</div>
|
|
260
|
+
</TableCell>
|
|
261
|
+
</TableRow>
|
|
262
|
+
);
|
|
263
|
+
})}
|
|
264
|
+
</TableBody>
|
|
265
|
+
</Table>
|
|
266
|
+
</div>
|
|
267
|
+
<div className="flex items-center justify-end gap-2 border-t border-stone-100 px-4 py-3 text-sm text-stone-500">
|
|
268
|
+
<span>第 {safePage} / {pageCount} 页,共 {items.length} 条</span>
|
|
269
|
+
<Button variant="outline" size="icon" className="size-9 rounded-lg border-stone-200 bg-white" disabled={safePage <= 1} onClick={() => setPage((value) => Math.max(1, value - 1))}>
|
|
270
|
+
<ChevronLeft className="size-4" />
|
|
271
|
+
</Button>
|
|
272
|
+
<Button variant="outline" size="icon" className="size-9 rounded-lg border-stone-200 bg-white" disabled={safePage >= pageCount} onClick={() => setPage((value) => Math.min(pageCount, value + 1))}>
|
|
273
|
+
<ChevronRight className="size-4" />
|
|
274
|
+
</Button>
|
|
275
|
+
</div>
|
|
276
|
+
{!isLoading && items.length === 0 ? <div className="px-6 py-14 text-center text-sm text-stone-500">没有找到日志</div> : null}
|
|
277
|
+
</CardContent>
|
|
278
|
+
</Card>
|
|
279
|
+
<Dialog open={detailOpen} onOpenChange={setDetailOpen}>
|
|
280
|
+
<DialogContent className="flex h-[min(88vh,860px)] w-[min(92vw,920px)] flex-col overflow-hidden rounded-2xl p-0">
|
|
281
|
+
<DialogHeader className="shrink-0 border-b border-stone-100 px-6 py-5">
|
|
282
|
+
<DialogTitle>日志详情</DialogTitle>
|
|
283
|
+
</DialogHeader>
|
|
284
|
+
<div className="flex-1 overflow-y-auto px-6 py-5">
|
|
285
|
+
<div className="space-y-4">
|
|
286
|
+
<div className="grid gap-3 rounded-xl border border-stone-200 bg-white p-4 text-sm text-stone-600 md:grid-cols-2">
|
|
287
|
+
{Object.entries(detailLog?.detail || {})
|
|
288
|
+
.filter(([key, value]) => key !== "urls" && typeof value !== "object")
|
|
289
|
+
.map(([key, value]) => (
|
|
290
|
+
<div key={key} className="flex items-start justify-between gap-4">
|
|
291
|
+
<span className="text-stone-400">{key}</span>
|
|
292
|
+
<span className="text-right font-medium break-all text-stone-700">{String(value)}</span>
|
|
293
|
+
</div>
|
|
294
|
+
))}
|
|
295
|
+
</div>
|
|
296
|
+
{detailUrls.length ? (
|
|
297
|
+
<div className="grid gap-3 sm:grid-cols-2 md:grid-cols-3">
|
|
298
|
+
{detailUrls.map((url, index) => (
|
|
299
|
+
<button
|
|
300
|
+
key={url}
|
|
301
|
+
type="button"
|
|
302
|
+
className="aspect-square overflow-hidden rounded-xl border border-stone-200 bg-stone-100"
|
|
303
|
+
onClick={() => {
|
|
304
|
+
setLightboxIndex(index);
|
|
305
|
+
setLightboxOpen(true);
|
|
306
|
+
}}
|
|
307
|
+
>
|
|
308
|
+
<img src={url} alt="" className="h-full w-full object-cover" />
|
|
309
|
+
</button>
|
|
310
|
+
))}
|
|
311
|
+
</div>
|
|
312
|
+
) : null}
|
|
313
|
+
<pre className="max-h-[72vh] overflow-auto rounded-xl border border-stone-200 bg-stone-50 p-4 text-xs leading-6 text-stone-700">
|
|
314
|
+
{JSON.stringify(detailLog?.detail || {}, null, 2)}
|
|
315
|
+
</pre>
|
|
316
|
+
</div>
|
|
317
|
+
</div>
|
|
318
|
+
</DialogContent>
|
|
319
|
+
</Dialog>
|
|
320
|
+
<ImageLightbox
|
|
321
|
+
images={detailImages}
|
|
322
|
+
currentIndex={lightboxIndex}
|
|
323
|
+
open={lightboxOpen}
|
|
324
|
+
onOpenChange={setLightboxOpen}
|
|
325
|
+
onIndexChange={setLightboxIndex}
|
|
326
|
+
/>
|
|
327
|
+
<Dialog open={deletingItems.length > 0} onOpenChange={(open) => (!open ? setDeletingItems([]) : null)}>
|
|
328
|
+
<DialogContent showCloseButton={false} className="rounded-2xl p-6">
|
|
329
|
+
<DialogHeader className="gap-2">
|
|
330
|
+
<DialogTitle>{deletingItems.length === 1 ? "删除日志" : "删除所选日志"}</DialogTitle>
|
|
331
|
+
<DialogDescription className="text-sm leading-6">
|
|
332
|
+
确认删除 {deletingItems.length} 条日志吗?删除后无法恢复。
|
|
333
|
+
</DialogDescription>
|
|
334
|
+
</DialogHeader>
|
|
335
|
+
<DialogFooter>
|
|
336
|
+
<Button variant="outline" className="rounded-xl" onClick={() => setDeletingItems([])} disabled={isDeleting}>
|
|
337
|
+
取消
|
|
338
|
+
</Button>
|
|
339
|
+
<Button className="rounded-xl bg-rose-600 text-white hover:bg-rose-700" onClick={() => void confirmDelete()} disabled={isDeleting || deletingItems.length === 0}>
|
|
340
|
+
{isDeleting ? <LoaderCircle className="size-4 animate-spin" /> : null}
|
|
341
|
+
确认删除
|
|
342
|
+
</Button>
|
|
343
|
+
</DialogFooter>
|
|
344
|
+
</DialogContent>
|
|
345
|
+
</Dialog>
|
|
346
|
+
</section>
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export default function LogsPage() {
|
|
351
|
+
const { isCheckingAuth, session } = useAuthGuard(["admin"]);
|
|
352
|
+
if (isCheckingAuth || !session || session.role !== "admin") {
|
|
353
|
+
return <div className="flex min-h-[40vh] items-center justify-center"><LoaderCircle className="size-5 animate-spin text-stone-400" /></div>;
|
|
354
|
+
}
|
|
355
|
+
return <LogsContent />;
|
|
356
|
+
}
|