dsh-plugin-image-workbench 0.0.0-stage → 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.
Files changed (186) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +258 -0
  3. package/README.md +260 -2
  4. package/client.js +241 -0
  5. package/cordis.patch.yml +14 -0
  6. package/host.js +692 -0
  7. package/install.mjs +333 -0
  8. package/package.json +58 -4
  9. package/scripts/fetch-style-images.mjs +104 -0
  10. package/scripts/vendor-snapshot.py +154 -0
  11. package/server/access.py +26 -0
  12. package/server/app.py +1329 -0
  13. package/server/catalog.json +1 -0
  14. package/server/catalog.py +147 -0
  15. package/server/composer.py +391 -0
  16. package/server/drafts.py +158 -0
  17. package/server/history.py +575 -0
  18. package/server/imaging.py +172 -0
  19. package/server/pool.py +1335 -0
  20. package/server/pool_admin.py +921 -0
  21. package/server/pool_service.py +1073 -0
  22. package/server/requirements.txt +6 -0
  23. package/server/smoke_check.py +402 -0
  24. package/server/static/access.html +202 -0
  25. package/server/static/index.html +4725 -0
  26. package/vendor/chatgpt2api/README.md +13 -0
  27. package/vendor/chatgpt2api/SOURCE.json +11 -0
  28. package/vendor/chatgpt2api/runtime/uv.exe +0 -0
  29. package/vendor/chatgpt2api/source/.env.example +82 -0
  30. package/vendor/chatgpt2api/source/.python-version +1 -0
  31. package/vendor/chatgpt2api/source/LICENSE +21 -0
  32. package/vendor/chatgpt2api/source/README.md +391 -0
  33. package/vendor/chatgpt2api/source/VERSION +1 -0
  34. package/vendor/chatgpt2api/source/api/__init__.py +2 -0
  35. package/vendor/chatgpt2api/source/api/accounts.py +537 -0
  36. package/vendor/chatgpt2api/source/api/ai.py +217 -0
  37. package/vendor/chatgpt2api/source/api/app.py +62 -0
  38. package/vendor/chatgpt2api/source/api/errors.py +46 -0
  39. package/vendor/chatgpt2api/source/api/image_inputs.py +309 -0
  40. package/vendor/chatgpt2api/source/api/image_tasks.py +120 -0
  41. package/vendor/chatgpt2api/source/api/support.py +134 -0
  42. package/vendor/chatgpt2api/source/api/system.py +365 -0
  43. package/vendor/chatgpt2api/source/assets/atlascloud.svg +1 -0
  44. package/vendor/chatgpt2api/source/assets/ipwo.png +0 -0
  45. package/vendor/chatgpt2api/source/assets/kunrouai.svg +50 -0
  46. package/vendor/chatgpt2api/source/config.default.json +108 -0
  47. package/vendor/chatgpt2api/source/main.py +9 -0
  48. package/vendor/chatgpt2api/source/pyproject.toml +27 -0
  49. package/vendor/chatgpt2api/source/scripts/init_proxy_config.py +186 -0
  50. package/vendor/chatgpt2api/source/scripts/migrate_storage.py +163 -0
  51. package/vendor/chatgpt2api/source/scripts/privoxy-warp.conf +13 -0
  52. package/vendor/chatgpt2api/source/scripts/test_outlook_token_mailbox.py +385 -0
  53. package/vendor/chatgpt2api/source/scripts/test_storage.py +129 -0
  54. package/vendor/chatgpt2api/source/scripts/verify_oauth_refresh.py +92 -0
  55. package/vendor/chatgpt2api/source/services/__init__.py +0 -0
  56. package/vendor/chatgpt2api/source/services/account_service.py +1757 -0
  57. package/vendor/chatgpt2api/source/services/auth_service.py +253 -0
  58. package/vendor/chatgpt2api/source/services/backup_service.py +671 -0
  59. package/vendor/chatgpt2api/source/services/config.py +667 -0
  60. package/vendor/chatgpt2api/source/services/content_filter.py +242 -0
  61. package/vendor/chatgpt2api/source/services/cpa_service.py +315 -0
  62. package/vendor/chatgpt2api/source/services/editable_file_task_service.py +260 -0
  63. package/vendor/chatgpt2api/source/services/image_service.py +376 -0
  64. package/vendor/chatgpt2api/source/services/image_storage_service.py +405 -0
  65. package/vendor/chatgpt2api/source/services/image_tags_service.py +76 -0
  66. package/vendor/chatgpt2api/source/services/image_task_service.py +550 -0
  67. package/vendor/chatgpt2api/source/services/log_service.py +337 -0
  68. package/vendor/chatgpt2api/source/services/model_service.py +182 -0
  69. package/vendor/chatgpt2api/source/services/oauth_login_service.py +267 -0
  70. package/vendor/chatgpt2api/source/services/openai_backend_api.py +2763 -0
  71. package/vendor/chatgpt2api/source/services/openai_oauth.py +32 -0
  72. package/vendor/chatgpt2api/source/services/protocol/__init__.py +2 -0
  73. package/vendor/chatgpt2api/source/services/protocol/anthropic_v1_messages.py +307 -0
  74. package/vendor/chatgpt2api/source/services/protocol/chat_completion_cache.py +238 -0
  75. package/vendor/chatgpt2api/source/services/protocol/conversation.py +1644 -0
  76. package/vendor/chatgpt2api/source/services/protocol/error_response.py +124 -0
  77. package/vendor/chatgpt2api/source/services/protocol/openai_search.py +19 -0
  78. package/vendor/chatgpt2api/source/services/protocol/openai_v1_chat_complete.py +316 -0
  79. package/vendor/chatgpt2api/source/services/protocol/openai_v1_image_edit.py +86 -0
  80. package/vendor/chatgpt2api/source/services/protocol/openai_v1_image_generations.py +42 -0
  81. package/vendor/chatgpt2api/source/services/protocol/openai_v1_models.py +53 -0
  82. package/vendor/chatgpt2api/source/services/protocol/openai_v1_response.py +453 -0
  83. package/vendor/chatgpt2api/source/services/protocol/web_search_tool.py +160 -0
  84. package/vendor/chatgpt2api/source/services/proxy_service.py +648 -0
  85. package/vendor/chatgpt2api/source/services/storage/__init__.py +5 -0
  86. package/vendor/chatgpt2api/source/services/storage/base.py +38 -0
  87. package/vendor/chatgpt2api/source/services/storage/database_storage.py +194 -0
  88. package/vendor/chatgpt2api/source/services/storage/factory.py +104 -0
  89. package/vendor/chatgpt2api/source/services/storage/git_storage.py +183 -0
  90. package/vendor/chatgpt2api/source/services/storage/json_storage.py +95 -0
  91. package/vendor/chatgpt2api/source/services/sub2api_service.py +531 -0
  92. package/vendor/chatgpt2api/source/utils/__init__.py +0 -0
  93. package/vendor/chatgpt2api/source/utils/helper.py +469 -0
  94. package/vendor/chatgpt2api/source/utils/image_tokens.py +346 -0
  95. package/vendor/chatgpt2api/source/utils/log.py +110 -0
  96. package/vendor/chatgpt2api/source/utils/pkce.py +19 -0
  97. package/vendor/chatgpt2api/source/utils/pow.py +207 -0
  98. package/vendor/chatgpt2api/source/utils/sentinel.py +159 -0
  99. package/vendor/chatgpt2api/source/utils/turnstile.py +184 -0
  100. package/vendor/chatgpt2api/source/uv.lock +904 -0
  101. package/vendor/chatgpt2api/source/web/bun.lock +1501 -0
  102. package/vendor/chatgpt2api/source/web/components.json +24 -0
  103. package/vendor/chatgpt2api/source/web/eslint.config.mjs +17 -0
  104. package/vendor/chatgpt2api/source/web/next.config.ts +40 -0
  105. package/vendor/chatgpt2api/source/web/package.json +58 -0
  106. package/vendor/chatgpt2api/source/web/postcss.config.mjs +5 -0
  107. package/vendor/chatgpt2api/source/web/public/github.svg +1 -0
  108. package/vendor/chatgpt2api/source/web/public/next.svg +1 -0
  109. package/vendor/chatgpt2api/source/web/public/openai.svg +1 -0
  110. package/vendor/chatgpt2api/source/web/public/vercel.svg +1 -0
  111. package/vendor/chatgpt2api/source/web/src/app/accounts/components/account-import-dialog.tsx +925 -0
  112. package/vendor/chatgpt2api/source/web/src/app/accounts/page.tsx +1307 -0
  113. package/vendor/chatgpt2api/source/web/src/app/debug/components/chat-panel.tsx +224 -0
  114. package/vendor/chatgpt2api/source/web/src/app/debug/components/editable-file-panel.tsx +444 -0
  115. package/vendor/chatgpt2api/source/web/src/app/debug/components/ppt-panel.tsx +9 -0
  116. package/vendor/chatgpt2api/source/web/src/app/debug/components/psd-panel.tsx +9 -0
  117. package/vendor/chatgpt2api/source/web/src/app/debug/components/search-panel.tsx +172 -0
  118. package/vendor/chatgpt2api/source/web/src/app/debug/components/skill-panel.tsx +169 -0
  119. package/vendor/chatgpt2api/source/web/src/app/debug/components/types.ts +39 -0
  120. package/vendor/chatgpt2api/source/web/src/app/debug/page.tsx +59 -0
  121. package/vendor/chatgpt2api/source/web/src/app/favicon.ico +0 -0
  122. package/vendor/chatgpt2api/source/web/src/app/globals.css +231 -0
  123. package/vendor/chatgpt2api/source/web/src/app/image/components/image-composer.tsx +542 -0
  124. package/vendor/chatgpt2api/source/web/src/app/image/components/image-results.tsx +554 -0
  125. package/vendor/chatgpt2api/source/web/src/app/image/components/image-sidebar.tsx +176 -0
  126. package/vendor/chatgpt2api/source/web/src/app/image/page.tsx +1799 -0
  127. package/vendor/chatgpt2api/source/web/src/app/image-manager/page.tsx +732 -0
  128. package/vendor/chatgpt2api/source/web/src/app/layout.tsx +50 -0
  129. package/vendor/chatgpt2api/source/web/src/app/login/page.tsx +101 -0
  130. package/vendor/chatgpt2api/source/web/src/app/logs/page.tsx +356 -0
  131. package/vendor/chatgpt2api/source/web/src/app/page.tsx +30 -0
  132. package/vendor/chatgpt2api/source/web/src/app/settings/components/api-docs-card.tsx +341 -0
  133. package/vendor/chatgpt2api/source/web/src/app/settings/components/backup-settings-card.tsx +447 -0
  134. package/vendor/chatgpt2api/source/web/src/app/settings/components/base-url-card.tsx +71 -0
  135. package/vendor/chatgpt2api/source/web/src/app/settings/components/config-card.tsx +491 -0
  136. package/vendor/chatgpt2api/source/web/src/app/settings/components/cpa-pool-dialog.tsx +108 -0
  137. package/vendor/chatgpt2api/source/web/src/app/settings/components/cpa-pools-card.tsx +169 -0
  138. package/vendor/chatgpt2api/source/web/src/app/settings/components/import-browser-dialog.tsx +185 -0
  139. package/vendor/chatgpt2api/source/web/src/app/settings/components/proxy-runtime-card.tsx +379 -0
  140. package/vendor/chatgpt2api/source/web/src/app/settings/components/proxy-settings-card.tsx +127 -0
  141. package/vendor/chatgpt2api/source/web/src/app/settings/components/proxy-settings.tsx +200 -0
  142. package/vendor/chatgpt2api/source/web/src/app/settings/components/settings-header.tsx +12 -0
  143. package/vendor/chatgpt2api/source/web/src/app/settings/components/sub2api-connections.tsx +886 -0
  144. package/vendor/chatgpt2api/source/web/src/app/settings/components/third-party-apps-card.tsx +81 -0
  145. package/vendor/chatgpt2api/source/web/src/app/settings/components/user-keys-card.tsx +422 -0
  146. package/vendor/chatgpt2api/source/web/src/app/settings/page.tsx +135 -0
  147. package/vendor/chatgpt2api/source/web/src/app/settings/store.ts +1069 -0
  148. package/vendor/chatgpt2api/source/web/src/components/date-range-filter.tsx +49 -0
  149. package/vendor/chatgpt2api/source/web/src/components/header-actions.tsx +24 -0
  150. package/vendor/chatgpt2api/source/web/src/components/image-lightbox.tsx +434 -0
  151. package/vendor/chatgpt2api/source/web/src/components/image-thumbnail.tsx +46 -0
  152. package/vendor/chatgpt2api/source/web/src/components/theme-script.tsx +18 -0
  153. package/vendor/chatgpt2api/source/web/src/components/theme-toggle.tsx +14 -0
  154. package/vendor/chatgpt2api/source/web/src/components/top-nav.tsx +263 -0
  155. package/vendor/chatgpt2api/source/web/src/components/ui/animated-theme-toggler.tsx +256 -0
  156. package/vendor/chatgpt2api/source/web/src/components/ui/badge.tsx +41 -0
  157. package/vendor/chatgpt2api/source/web/src/components/ui/button.tsx +59 -0
  158. package/vendor/chatgpt2api/source/web/src/components/ui/calendar.tsx +46 -0
  159. package/vendor/chatgpt2api/source/web/src/components/ui/card.tsx +61 -0
  160. package/vendor/chatgpt2api/source/web/src/components/ui/checkbox.tsx +27 -0
  161. package/vendor/chatgpt2api/source/web/src/components/ui/dia-text-reveal.tsx +267 -0
  162. package/vendor/chatgpt2api/source/web/src/components/ui/dialog.tsx +132 -0
  163. package/vendor/chatgpt2api/source/web/src/components/ui/field.tsx +13 -0
  164. package/vendor/chatgpt2api/source/web/src/components/ui/input.tsx +19 -0
  165. package/vendor/chatgpt2api/source/web/src/components/ui/label.tsx +24 -0
  166. package/vendor/chatgpt2api/source/web/src/components/ui/morphing-text.tsx +149 -0
  167. package/vendor/chatgpt2api/source/web/src/components/ui/popover.tsx +38 -0
  168. package/vendor/chatgpt2api/source/web/src/components/ui/select.tsx +175 -0
  169. package/vendor/chatgpt2api/source/web/src/components/ui/sheet.tsx +143 -0
  170. package/vendor/chatgpt2api/source/web/src/components/ui/table.tsx +29 -0
  171. package/vendor/chatgpt2api/source/web/src/components/ui/tabs.tsx +91 -0
  172. package/vendor/chatgpt2api/source/web/src/components/ui/text-3d-flip.tsx +269 -0
  173. package/vendor/chatgpt2api/source/web/src/components/ui/textarea.tsx +18 -0
  174. package/vendor/chatgpt2api/source/web/src/components/version-release-dialog.tsx +127 -0
  175. package/vendor/chatgpt2api/source/web/src/constants/common-env.ts +6 -0
  176. package/vendor/chatgpt2api/source/web/src/hooks/use-version-check.ts +85 -0
  177. package/vendor/chatgpt2api/source/web/src/lib/api.ts +926 -0
  178. package/vendor/chatgpt2api/source/web/src/lib/auth-session.ts +26 -0
  179. package/vendor/chatgpt2api/source/web/src/lib/release.ts +25 -0
  180. package/vendor/chatgpt2api/source/web/src/lib/request.ts +93 -0
  181. package/vendor/chatgpt2api/source/web/src/lib/use-auth-guard.ts +89 -0
  182. package/vendor/chatgpt2api/source/web/src/lib/utils.ts +6 -0
  183. package/vendor/chatgpt2api/source/web/src/store/auth.ts +112 -0
  184. package/vendor/chatgpt2api/source/web/src/store/editable-file-history.ts +33 -0
  185. package/vendor/chatgpt2api/source/web/src/store/image-conversations.ts +318 -0
  186. package/vendor/chatgpt2api/source/web/tsconfig.json +42 -0
@@ -0,0 +1,50 @@
1
+ import type { Metadata, Viewport } from "next";
2
+ import { Toaster } from "sonner";
3
+ import "./globals.css";
4
+ import { ThemeScript } from "@/components/theme-script";
5
+ import { TopNav } from "@/components/top-nav";
6
+
7
+ export const metadata: Metadata = {
8
+ title: "ChatGPT 号池管理",
9
+ description: "ChatGPT account pool management dashboard",
10
+ };
11
+
12
+ export const viewport: Viewport = {
13
+ width: "device-width",
14
+ initialScale: 1,
15
+ maximumScale: 1,
16
+ userScalable: false,
17
+ themeColor: [
18
+ { media: "(prefers-color-scheme: light)", color: "#f0ebe3" },
19
+ { media: "(prefers-color-scheme: dark)", color: "#12110f" },
20
+ ],
21
+ };
22
+
23
+ export default function RootLayout({
24
+ children,
25
+ }: Readonly<{
26
+ children: React.ReactNode;
27
+ }>) {
28
+ return (
29
+ <html lang="zh-CN" suppressHydrationWarning>
30
+ <head>
31
+ <ThemeScript />
32
+ </head>
33
+ <body
34
+ className="antialiased"
35
+ style={{
36
+ fontFamily:
37
+ '"SF Pro Display","SF Pro Text","PingFang SC","Microsoft YaHei","Helvetica Neue",sans-serif',
38
+ }}
39
+ >
40
+ <Toaster position="top-center" richColors offset={48} />
41
+ <main className="min-h-screen overflow-x-hidden bg-[radial-gradient(circle_at_top_left,_rgba(255,255,255,0.92),_rgba(245,239,231,0.96)_42%,_rgba(240,235,227,0.99)_100%)] px-4 pt-0 pb-2 text-stone-900 transition-colors duration-300 dark:bg-[radial-gradient(circle_at_top_left,_rgba(55,48,43,0.72),_rgba(28,25,23,0.98)_40%,_rgba(12,10,9,1)_100%)] dark:text-stone-100 sm:px-6 sm:pt-2 lg:px-8">
42
+ <div className="mx-auto box-border flex min-h-screen max-w-[1440px] flex-col gap-2 pt-[env(safe-area-inset-top)] sm:gap-5 sm:pt-0">
43
+ <TopNav />
44
+ {children}
45
+ </div>
46
+ </main>
47
+ </body>
48
+ </html>
49
+ );
50
+ }
@@ -0,0 +1,101 @@
1
+ "use client";
2
+
3
+ import { useRouter } from "next/navigation";
4
+ import { useState } from "react";
5
+ import { LoaderCircle, LockKeyhole } from "lucide-react";
6
+ import { toast } from "sonner";
7
+
8
+ import { Button } from "@/components/ui/button";
9
+ import { Card, CardContent } from "@/components/ui/card";
10
+ import { Input } from "@/components/ui/input";
11
+ import { HeaderActions } from "@/components/header-actions";
12
+ import { login } from "@/lib/api";
13
+ import { useRedirectIfAuthenticated } from "@/lib/use-auth-guard";
14
+ import { getDefaultRouteForRole, setStoredAuthSession } from "@/store/auth";
15
+
16
+ export default function LoginPage() {
17
+ const router = useRouter();
18
+ const [authKey, setAuthKey] = useState("");
19
+ const [isSubmitting, setIsSubmitting] = useState(false);
20
+ const { isCheckingAuth } = useRedirectIfAuthenticated();
21
+
22
+ const handleLogin = async () => {
23
+ const normalizedAuthKey = authKey.trim();
24
+ if (!normalizedAuthKey) {
25
+ toast.error("请输入 密钥");
26
+ return;
27
+ }
28
+
29
+ setIsSubmitting(true);
30
+ try {
31
+ const data = await login(normalizedAuthKey);
32
+ await setStoredAuthSession({
33
+ key: normalizedAuthKey,
34
+ role: data.role,
35
+ subjectId: data.subject_id,
36
+ name: data.name,
37
+ });
38
+ router.replace(getDefaultRouteForRole(data.role));
39
+ } catch (error) {
40
+ const message = error instanceof Error ? error.message : "登录失败";
41
+ toast.error(message);
42
+ } finally {
43
+ setIsSubmitting(false);
44
+ }
45
+ };
46
+
47
+ if (isCheckingAuth) {
48
+ return (
49
+ <div className="grid min-h-[calc(100vh-1rem)] w-full place-items-center px-4 py-6">
50
+ <LoaderCircle className="size-5 animate-spin text-stone-400" />
51
+ </div>
52
+ );
53
+ }
54
+
55
+ return (
56
+ <div className="grid min-h-[calc(100vh-1rem)] w-full place-items-center px-4 py-6">
57
+ <HeaderActions className="fixed top-4 right-4 z-10" />
58
+ <Card className="w-full max-w-[505px] rounded-[30px] border-white/80 bg-white/95 shadow-[0_28px_90px_rgba(28,25,23,0.10)]">
59
+ <CardContent className="space-y-7 p-6 sm:p-8">
60
+ <div className="space-y-4 text-center">
61
+ <div className="mx-auto inline-flex size-14 items-center justify-center rounded-[18px] bg-stone-950 text-white shadow-sm">
62
+ <LockKeyhole className="size-5" />
63
+ </div>
64
+ <div className="space-y-2">
65
+ <h1 className="text-3xl font-semibold tracking-tight text-stone-950">欢迎回来</h1>
66
+ <p className="text-sm leading-6 text-stone-500">输入密钥后继续使用账号管理和图片生成功能。</p>
67
+ </div>
68
+ </div>
69
+
70
+ <div className="space-y-3">
71
+ <label htmlFor="auth-key" className="block text-sm font-medium text-stone-700">
72
+ 密钥
73
+ </label>
74
+ <Input
75
+ id="auth-key"
76
+ type="password"
77
+ value={authKey}
78
+ onChange={(event) => setAuthKey(event.target.value)}
79
+ onKeyDown={(event) => {
80
+ if (event.key === "Enter") {
81
+ void handleLogin();
82
+ }
83
+ }}
84
+ placeholder="请输入密钥"
85
+ className="h-13 rounded-2xl border-stone-200 bg-white px-4"
86
+ />
87
+ </div>
88
+
89
+ <Button
90
+ className="h-13 w-full rounded-2xl bg-stone-950 text-white hover:bg-stone-800"
91
+ onClick={() => void handleLogin()}
92
+ disabled={isSubmitting}
93
+ >
94
+ {isSubmitting ? <LoaderCircle className="size-4 animate-spin" /> : null}
95
+ 登录
96
+ </Button>
97
+ </CardContent>
98
+ </Card>
99
+ </div>
100
+ );
101
+ }
@@ -0,0 +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
+ }
@@ -0,0 +1,30 @@
1
+ "use client";
2
+
3
+ import { useEffect } from "react";
4
+ import { useRouter } from "next/navigation";
5
+
6
+ import { getValidatedAuthSession } from "@/lib/auth-session";
7
+ import { getDefaultRouteForRole } from "@/store/auth";
8
+
9
+ export default function HomePage() {
10
+ const router = useRouter();
11
+
12
+ useEffect(() => {
13
+ let active = true;
14
+
15
+ const redirect = async () => {
16
+ const session = await getValidatedAuthSession();
17
+ if (!active) {
18
+ return;
19
+ }
20
+ router.replace(session ? getDefaultRouteForRole(session.role) : "/login");
21
+ };
22
+
23
+ void redirect();
24
+ return () => {
25
+ active = false;
26
+ };
27
+ }, [router]);
28
+
29
+ return null;
30
+ }