tuxevil-rotator 3.10.0 → 4.0.0
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/CHANGELOG.md +52 -0
- package/README.md +22 -12
- package/package.json +8 -4
- package/src/admin-auth.ts +233 -3
- package/src/dashboard-app.ts +257 -0
- package/src/dashboard-live.ts +654 -0
- package/src/dashboard-types.ts +192 -0
- package/src/dashboard.ts +165 -732
- package/src/db-store.ts +43 -0
- package/src/exposure.ts +21 -1
- package/src/providers/opencode-zen/catalog.ts +2 -0
- package/src/providers/opencode-zen/forward.ts +18 -15
- package/src/providers/opencode-zen/login.ts +2 -1
- package/src/providers/opencode-zen/quota.ts +2 -1
- package/src/proxy.ts +71 -25
- package/src/rotator.ts +30 -30
- package/src/settings-repository.ts +7 -0
- package/src/types.ts +2 -0
- package/src/web/app.tsx +765 -0
- package/src/web/components/charts.tsx +338 -0
- package/src/web/components/command.tsx +279 -0
- package/src/web/components/icons.tsx +357 -0
- package/src/web/components/overlays.tsx +432 -0
- package/src/web/components/ui.tsx +421 -0
- package/src/web/lib/accounts.ts +109 -0
- package/src/web/lib/attention.ts +219 -0
- package/src/web/lib/colors.ts +103 -0
- package/src/web/lib/format.ts +113 -0
- package/src/web/lib/mask.ts +92 -0
- package/src/web/lib/pools.ts +199 -0
- package/src/web/lib/status.ts +242 -0
- package/src/web/lib/usage.ts +296 -0
- package/src/web/main.tsx +16 -0
- package/src/web/nav.ts +28 -0
- package/src/web/pages/AccountDetail.tsx +346 -0
- package/src/web/pages/Accounts.tsx +581 -0
- package/src/web/pages/Keys.tsx +431 -0
- package/src/web/pages/Overview.tsx +600 -0
- package/src/web/pages/Requests.tsx +644 -0
- package/src/web/pages/Settings.tsx +546 -0
- package/src/web/pages/Usage.tsx +346 -0
- package/src/web/pages/shared.ts +36 -0
- package/src/web/state/actions.ts +211 -0
- package/src/web/state/api.ts +273 -0
- package/src/web/state/prefs.ts +19 -0
- package/src/web/state/router.ts +92 -0
- package/src/web/state/store.ts +266 -0
- package/src/web/styles/app.css +5043 -0
- package/src/web/tsconfig.json +14 -0
- package/src/static/dashboard-keys.js +0 -535
- package/src/static/dashboard-logs.js +0 -800
- package/src/static/dashboard.css +0 -2741
- package/src/static/dashboard.js +0 -3334
package/src/web/app.tsx
ADDED
|
@@ -0,0 +1,765 @@
|
|
|
1
|
+
import type { ComponentChildren, JSX } from "preact";
|
|
2
|
+
import { useEffect, useMemo, useState } from "preact/hooks";
|
|
3
|
+
import { buildAttention, actionableCount, SEVERITY_ICON, SEVERITY_TONE, type AttentionItem } from "./lib/attention.js";
|
|
4
|
+
import { formatRelative } from "./lib/format.js";
|
|
5
|
+
import { needsAttention } from "./lib/status.js";
|
|
6
|
+
import {
|
|
7
|
+
accounts,
|
|
8
|
+
authRequired,
|
|
9
|
+
authState,
|
|
10
|
+
connection,
|
|
11
|
+
masked,
|
|
12
|
+
masker,
|
|
13
|
+
now,
|
|
14
|
+
overview,
|
|
15
|
+
paletteOpen,
|
|
16
|
+
railExpanded,
|
|
17
|
+
signIn,
|
|
18
|
+
signOut,
|
|
19
|
+
theme,
|
|
20
|
+
} from "./state/store.js";
|
|
21
|
+
import { api } from "./state/api.js";
|
|
22
|
+
import { toast } from "./state/actions.js";
|
|
23
|
+
import { readPref, writePref } from "./state/prefs.js";
|
|
24
|
+
import { accountPath, BASE, navigate, query, route } from "./state/router.js";
|
|
25
|
+
import { NAV, PAGE_TITLES, type NavItem } from "./nav.js";
|
|
26
|
+
import { Icon, LogoMark } from "./components/icons.js";
|
|
27
|
+
import { ConfirmHost, Drawer, Menu, Popover, ToastHost } from "./components/overlays.js";
|
|
28
|
+
import { CommandPalette, MOD_KEY } from "./components/command.js";
|
|
29
|
+
import { AsyncButton, Button, Link, Spinner } from "./components/ui.js";
|
|
30
|
+
import { OverviewPage } from "./pages/Overview.js";
|
|
31
|
+
import { AccountsPage } from "./pages/Accounts.js";
|
|
32
|
+
import { AccountDetail } from "./pages/AccountDetail.js";
|
|
33
|
+
import { RequestsPage } from "./pages/Requests.js";
|
|
34
|
+
import { UsagePage } from "./pages/Usage.js";
|
|
35
|
+
import { KeysPage } from "./pages/Keys.js";
|
|
36
|
+
import { SettingsPage } from "./pages/Settings.js";
|
|
37
|
+
import { openAddAccount } from "./pages/shared.js";
|
|
38
|
+
|
|
39
|
+
/** Below this width the rail becomes a slide-over sheet. */
|
|
40
|
+
const COMPACT_QUERY = "(max-width: 760px)";
|
|
41
|
+
const SUPPORT_URL = "https://ko-fi.com/tuxevil";
|
|
42
|
+
|
|
43
|
+
export function App(): JSX.Element {
|
|
44
|
+
const auth = authState.value;
|
|
45
|
+
if (auth === "checking") {
|
|
46
|
+
return (
|
|
47
|
+
<div class="boot">
|
|
48
|
+
<Spinner />
|
|
49
|
+
</div>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
if (auth === "signed-out") return <LoginScreen />;
|
|
53
|
+
return <Shell />;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function useDocumentTitle(): void {
|
|
57
|
+
const page = route.value.page;
|
|
58
|
+
const data = overview.value;
|
|
59
|
+
const issues = data ? data.accounts.filter(needsAttention).length : 0;
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
const title = page === "not-found" ? "Not found" : PAGE_TITLES[page];
|
|
62
|
+
document.title = `${issues > 0 ? `(${issues}) ` : ""}${title} · Tuxevil Rotator`;
|
|
63
|
+
}, [page, issues]);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function useMediaQuery(query: string): boolean {
|
|
67
|
+
const [matches, setMatches] = useState(() => window.matchMedia(query).matches);
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
const list = window.matchMedia(query);
|
|
70
|
+
const onChange = () => setMatches(list.matches);
|
|
71
|
+
onChange();
|
|
72
|
+
list.addEventListener("change", onChange);
|
|
73
|
+
return () => list.removeEventListener("change", onChange);
|
|
74
|
+
}, [query]);
|
|
75
|
+
return matches;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function useAttention(): AttentionItem[] {
|
|
79
|
+
const data = overview.value;
|
|
80
|
+
const minute = Math.floor(now.value / 60_000);
|
|
81
|
+
return useMemo(() => (data ? buildAttention(data, Date.now(), masker.value.name) : []), [data, masker.value, minute]);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function Shell(): JSX.Element {
|
|
85
|
+
const current = route.value;
|
|
86
|
+
const [navOpen, setNavOpen] = useState(false);
|
|
87
|
+
const compact = useMediaQuery(COMPACT_QUERY);
|
|
88
|
+
useDocumentTitle();
|
|
89
|
+
|
|
90
|
+
useEffect(() => setNavOpen(false), [current.page, compact]);
|
|
91
|
+
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
const onKey = (event: KeyboardEvent) => {
|
|
94
|
+
if ((event.metaKey || event.ctrlKey) && !event.altKey && event.key.toLowerCase() === "k") {
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
paletteOpen.value = !paletteOpen.value;
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (event.key === "Escape") setNavOpen(false);
|
|
100
|
+
const target = event.target as HTMLElement | null;
|
|
101
|
+
if (target && (target.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(target.tagName))) return;
|
|
102
|
+
if (event.metaKey || event.ctrlKey || event.altKey) return;
|
|
103
|
+
if (event.key === "/") {
|
|
104
|
+
const search = document.querySelector<HTMLInputElement>("[data-page-search] input");
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
if (search) search.focus();
|
|
107
|
+
else paletteOpen.value = true;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
document.addEventListener("keydown", onKey);
|
|
111
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
112
|
+
}, []);
|
|
113
|
+
|
|
114
|
+
const toggleNav = () => {
|
|
115
|
+
if (compact) setNavOpen(!navOpen);
|
|
116
|
+
else railExpanded.value = !railExpanded.value;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
let page: JSX.Element;
|
|
120
|
+
switch (current.page) {
|
|
121
|
+
case "overview":
|
|
122
|
+
page = <OverviewPage />;
|
|
123
|
+
break;
|
|
124
|
+
case "accounts":
|
|
125
|
+
page = <AccountsPage />;
|
|
126
|
+
break;
|
|
127
|
+
case "requests":
|
|
128
|
+
page = <RequestsPage />;
|
|
129
|
+
break;
|
|
130
|
+
case "usage":
|
|
131
|
+
page = <UsagePage />;
|
|
132
|
+
break;
|
|
133
|
+
case "keys":
|
|
134
|
+
page = <KeysPage />;
|
|
135
|
+
break;
|
|
136
|
+
case "settings":
|
|
137
|
+
page = <SettingsPage />;
|
|
138
|
+
break;
|
|
139
|
+
default:
|
|
140
|
+
page = <NotFound />;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const drawerEmail = current.account;
|
|
144
|
+
const closeDrawer = () => {
|
|
145
|
+
const back = query.value.toString();
|
|
146
|
+
navigate(`${BASE}/accounts${back ? `?${back}` : ""}`, { replace: false });
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<div class={`app${railExpanded.value ? " rail-expanded" : ""}${navOpen ? " nav-open" : ""}`}>
|
|
151
|
+
<a class="skip-link" href="#main">
|
|
152
|
+
Skip to content
|
|
153
|
+
</a>
|
|
154
|
+
<TopBar navOpen={compact ? navOpen : railExpanded.value} onToggleNav={toggleNav} />
|
|
155
|
+
<Rail />
|
|
156
|
+
<div class="rail-scrim" aria-hidden="true" onClick={() => setNavOpen(false)} />
|
|
157
|
+
<main class="canvas" id="main" tabIndex={-1}>
|
|
158
|
+
<Banners />
|
|
159
|
+
{overview.value ? (
|
|
160
|
+
<div class="page" key={current.page}>
|
|
161
|
+
{page}
|
|
162
|
+
</div>
|
|
163
|
+
) : (
|
|
164
|
+
<div class="page page-loading">
|
|
165
|
+
<Spinner />
|
|
166
|
+
<span>{connection.value.error ? `Waiting for the rotator — ${connection.value.error}` : "Loading the rotator state…"}</span>
|
|
167
|
+
</div>
|
|
168
|
+
)}
|
|
169
|
+
</main>
|
|
170
|
+
<Drawer open={Boolean(drawerEmail) && Boolean(overview.value)} onClose={closeDrawer} label="Account details">
|
|
171
|
+
{drawerEmail && overview.value && <AccountDetail email={drawerEmail} onClose={closeDrawer} />}
|
|
172
|
+
</Drawer>
|
|
173
|
+
<CommandPalette />
|
|
174
|
+
<ConfirmHost />
|
|
175
|
+
<ToastHost />
|
|
176
|
+
</div>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ── Top bar ─────────────────────────────────────────────────────────────
|
|
181
|
+
|
|
182
|
+
/** `navOpen`: the rail is expanded (desktop) or the nav sheet is open (phone). */
|
|
183
|
+
function TopBar({ navOpen, onToggleNav }: { navOpen: boolean; onToggleNav: () => void }): JSX.Element {
|
|
184
|
+
return (
|
|
185
|
+
<header class="topbar">
|
|
186
|
+
<div class="topbar-start">
|
|
187
|
+
<Link href={BASE} class="brand-pill" aria-label="Tuxevil Rotator overview">
|
|
188
|
+
<LogoMark size={22} />
|
|
189
|
+
<span class="brand-name">Tuxevil Rotator</span>
|
|
190
|
+
<span class="brand-sep" aria-hidden="true" />
|
|
191
|
+
<LiveIndicator compact />
|
|
192
|
+
</Link>
|
|
193
|
+
<div class="pill-group" role="group" aria-label="Navigation">
|
|
194
|
+
<button
|
|
195
|
+
type="button"
|
|
196
|
+
class="pill-btn"
|
|
197
|
+
aria-label={navOpen ? "Collapse sidebar" : "Expand sidebar"}
|
|
198
|
+
aria-expanded={navOpen}
|
|
199
|
+
title={navOpen ? "Collapse sidebar" : "Expand sidebar"}
|
|
200
|
+
onClick={onToggleNav}
|
|
201
|
+
>
|
|
202
|
+
<Icon name="panelLeft" size={17} />
|
|
203
|
+
</button>
|
|
204
|
+
<button type="button" class="pill-btn" aria-label="Add account" title="Add account" onClick={openAddAccount}>
|
|
205
|
+
<Icon name="plus" size={17} />
|
|
206
|
+
</button>
|
|
207
|
+
</div>
|
|
208
|
+
</div>
|
|
209
|
+
<div class="topbar-end">
|
|
210
|
+
<button type="button" class="search-trigger" onClick={() => (paletteOpen.value = true)}>
|
|
211
|
+
<Icon name="search" size={16} />
|
|
212
|
+
<span class="search-trigger-text">Search or jump to…</span>
|
|
213
|
+
<span class="search-trigger-keys" aria-hidden="true">
|
|
214
|
+
<kbd>{MOD_KEY}</kbd>
|
|
215
|
+
<kbd>K</kbd>
|
|
216
|
+
</span>
|
|
217
|
+
</button>
|
|
218
|
+
<Inbox />
|
|
219
|
+
</div>
|
|
220
|
+
</header>
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function attentionEmail(item: AttentionItem): string | null {
|
|
225
|
+
for (const action of item.actions) if ("email" in action) return action.email;
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function Inbox(): JSX.Element {
|
|
230
|
+
const items = useAttention();
|
|
231
|
+
const count = actionableCount(items);
|
|
232
|
+
const urgent = items.filter((i) => i.severity !== "info");
|
|
233
|
+
const notes = items.length - urgent.length;
|
|
234
|
+
const shown = (urgent.length > 0 ? urgent : items).slice(0, 6);
|
|
235
|
+
|
|
236
|
+
const open = (item: AttentionItem) => {
|
|
237
|
+
const email = attentionEmail(item);
|
|
238
|
+
if (email) {
|
|
239
|
+
navigate(accountPath(email));
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
navigate(BASE);
|
|
243
|
+
requestAnimationFrame(() =>
|
|
244
|
+
document.getElementById("attention")?.scrollIntoView({ behavior: "smooth", block: "start" }),
|
|
245
|
+
);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
return (
|
|
249
|
+
<Popover
|
|
250
|
+
label={count > 0 ? `Needs you: ${count}` : "Needs you"}
|
|
251
|
+
triggerClass={`icon-pill${count > 0 ? " has-badge" : ""}`}
|
|
252
|
+
triggerTitle="Needs you"
|
|
253
|
+
class="inbox"
|
|
254
|
+
trigger={
|
|
255
|
+
<>
|
|
256
|
+
<Icon name="bell" size={17} />
|
|
257
|
+
{count > 0 && <span class="icon-pill-badge num">{count > 9 ? "9+" : count}</span>}
|
|
258
|
+
</>
|
|
259
|
+
}
|
|
260
|
+
>
|
|
261
|
+
{(close) => (
|
|
262
|
+
<>
|
|
263
|
+
<header class="inbox-head">
|
|
264
|
+
<strong>Needs you</strong>
|
|
265
|
+
<span class="muted">
|
|
266
|
+
{urgent.length > 0
|
|
267
|
+
? `${urgent.length} to look at${notes ? ` · ${notes} ${notes === 1 ? "note" : "notes"}` : ""}`
|
|
268
|
+
: notes > 0
|
|
269
|
+
? `${notes} ${notes === 1 ? "note" : "notes"}`
|
|
270
|
+
: "All clear"}
|
|
271
|
+
</span>
|
|
272
|
+
</header>
|
|
273
|
+
{shown.length === 0 ? (
|
|
274
|
+
<div class="inbox-empty">
|
|
275
|
+
<span class="inbox-empty-icon">
|
|
276
|
+
<Icon name="checkCircle" size={20} />
|
|
277
|
+
</span>
|
|
278
|
+
<strong>Nothing needs you</strong>
|
|
279
|
+
<span class="muted">Every account is routing normally.</span>
|
|
280
|
+
</div>
|
|
281
|
+
) : (
|
|
282
|
+
<ul class="inbox-list">
|
|
283
|
+
{shown.map((item) => (
|
|
284
|
+
<li key={item.id}>
|
|
285
|
+
<button
|
|
286
|
+
type="button"
|
|
287
|
+
class={`inbox-item tone-${SEVERITY_TONE[item.severity]}`}
|
|
288
|
+
onClick={() => {
|
|
289
|
+
close();
|
|
290
|
+
open(item);
|
|
291
|
+
}}
|
|
292
|
+
>
|
|
293
|
+
<span class="inbox-item-icon">
|
|
294
|
+
<Icon name={SEVERITY_ICON[item.severity]} size={16} />
|
|
295
|
+
</span>
|
|
296
|
+
<span class="inbox-item-text">
|
|
297
|
+
<strong>{item.title}</strong>
|
|
298
|
+
<span>{masker.value.text(item.detail)}</span>
|
|
299
|
+
</span>
|
|
300
|
+
<Icon name="chevronRight" size={14} class="inbox-item-chevron" />
|
|
301
|
+
</button>
|
|
302
|
+
</li>
|
|
303
|
+
))}
|
|
304
|
+
</ul>
|
|
305
|
+
)}
|
|
306
|
+
<footer class="inbox-foot">
|
|
307
|
+
<Link
|
|
308
|
+
href={BASE}
|
|
309
|
+
class="btn btn-ghost btn-sm"
|
|
310
|
+
onClick={() => {
|
|
311
|
+
close();
|
|
312
|
+
requestAnimationFrame(() => document.getElementById("attention")?.scrollIntoView({ block: "start" }));
|
|
313
|
+
}}
|
|
314
|
+
>
|
|
315
|
+
Open overview <Icon name="arrowUpRight" size={14} />
|
|
316
|
+
</Link>
|
|
317
|
+
</footer>
|
|
318
|
+
</>
|
|
319
|
+
)}
|
|
320
|
+
</Popover>
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// ── Rail ────────────────────────────────────────────────────────────────
|
|
325
|
+
|
|
326
|
+
function Rail(): JSX.Element {
|
|
327
|
+
const items = useAttention();
|
|
328
|
+
const attention = actionableCount(items);
|
|
329
|
+
const issues = accounts.value.filter(needsAttention).length;
|
|
330
|
+
const page = route.value.page;
|
|
331
|
+
const primary = NAV.filter((item) => item.id !== "settings");
|
|
332
|
+
const settings = NAV.find((item) => item.id === "settings")!;
|
|
333
|
+
const badgeFor = (item: NavItem) =>
|
|
334
|
+
item.id === "overview" && attention > 0
|
|
335
|
+
? { count: attention, title: "Items that need you" }
|
|
336
|
+
: item.id === "accounts" && issues > 0
|
|
337
|
+
? { count: issues, title: "Accounts that need attention" }
|
|
338
|
+
: null;
|
|
339
|
+
|
|
340
|
+
return (
|
|
341
|
+
<nav class="rail" aria-label="Dashboard">
|
|
342
|
+
<div class="rail-group">
|
|
343
|
+
{primary.map((item) => (
|
|
344
|
+
<RailLink key={item.id} item={item} active={page === item.id} badge={badgeFor(item)} />
|
|
345
|
+
))}
|
|
346
|
+
</div>
|
|
347
|
+
<div class="rail-foot">
|
|
348
|
+
<RailLink item={settings} active={page === "settings"} badge={null} />
|
|
349
|
+
<SupportNudge />
|
|
350
|
+
<ProfileMenu />
|
|
351
|
+
</div>
|
|
352
|
+
</nav>
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function RailLink({
|
|
357
|
+
item,
|
|
358
|
+
active,
|
|
359
|
+
badge,
|
|
360
|
+
}: {
|
|
361
|
+
item: NavItem;
|
|
362
|
+
active: boolean;
|
|
363
|
+
badge: { count: number; title: string } | null;
|
|
364
|
+
}): JSX.Element {
|
|
365
|
+
return (
|
|
366
|
+
<Link
|
|
367
|
+
href={item.href}
|
|
368
|
+
class={`rail-item${active ? " is-active" : ""}`}
|
|
369
|
+
aria-current={active ? "page" : undefined}
|
|
370
|
+
data-tooltip={item.label}
|
|
371
|
+
>
|
|
372
|
+
<span class="rail-icon">
|
|
373
|
+
<Icon name={item.icon} size={18} />
|
|
374
|
+
{badge && <span class="rail-dot" aria-hidden="true" />}
|
|
375
|
+
</span>
|
|
376
|
+
<span class="rail-label">{item.label}</span>
|
|
377
|
+
{badge && (
|
|
378
|
+
<span class="rail-count num" title={badge.title}>
|
|
379
|
+
{badge.count}
|
|
380
|
+
</span>
|
|
381
|
+
)}
|
|
382
|
+
</Link>
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function ProfileMenu(): JSX.Element {
|
|
387
|
+
const data = overview.value;
|
|
388
|
+
const value = theme.value;
|
|
389
|
+
return (
|
|
390
|
+
<Menu
|
|
391
|
+
label="Profile and preferences"
|
|
392
|
+
placement="right-end"
|
|
393
|
+
triggerClass="rail-profile"
|
|
394
|
+
trigger={
|
|
395
|
+
<>
|
|
396
|
+
<span class="avatar" aria-hidden="true">
|
|
397
|
+
<Icon name="user" size={16} />
|
|
398
|
+
</span>
|
|
399
|
+
<span class="rail-profile-text">
|
|
400
|
+
<strong>Administrator</strong>
|
|
401
|
+
<span>{data ? `v${data.version}` : "Tuxevil Rotator"}</span>
|
|
402
|
+
</span>
|
|
403
|
+
<Icon name="more" size={15} class="rail-profile-more" />
|
|
404
|
+
</>
|
|
405
|
+
}
|
|
406
|
+
header={
|
|
407
|
+
<div class="menu-profile">
|
|
408
|
+
<span class="avatar avatar-lg" aria-hidden="true">
|
|
409
|
+
<Icon name="user" size={18} />
|
|
410
|
+
</span>
|
|
411
|
+
<span class="menu-profile-text">
|
|
412
|
+
<strong>Administrator</strong>
|
|
413
|
+
<span>
|
|
414
|
+
Tuxevil Rotator{data ? ` v${data.version}` : ""}
|
|
415
|
+
{data ? ` · port ${data.proxyPort}` : ""}
|
|
416
|
+
</span>
|
|
417
|
+
</span>
|
|
418
|
+
</div>
|
|
419
|
+
}
|
|
420
|
+
items={[
|
|
421
|
+
{ heading: "Theme" },
|
|
422
|
+
{ label: "System", icon: "monitor", checked: value === "system", onSelect: () => (theme.value = "system") },
|
|
423
|
+
{ label: "Light", icon: "sun", checked: value === "light", onSelect: () => (theme.value = "light") },
|
|
424
|
+
{ label: "Dark", icon: "moon", checked: value === "dark", onSelect: () => (theme.value = "dark") },
|
|
425
|
+
"separator",
|
|
426
|
+
{
|
|
427
|
+
label: "Privacy mask",
|
|
428
|
+
icon: masked.value ? "eyeOff" : "eye",
|
|
429
|
+
kind: "checkbox",
|
|
430
|
+
checked: masked.value,
|
|
431
|
+
onSelect: () => (masked.value = !masked.value),
|
|
432
|
+
},
|
|
433
|
+
{ label: "Command palette", icon: "search", hint: `${MOD_KEY}K`, onSelect: () => (paletteOpen.value = true) },
|
|
434
|
+
{ label: "Support the project", icon: "heart", onSelect: () => window.open(SUPPORT_URL, "_blank", "noopener") },
|
|
435
|
+
...(authRequired.value
|
|
436
|
+
? (["separator", { label: "Sign out", icon: "logout", onSelect: () => void signOut() }] as const)
|
|
437
|
+
: []),
|
|
438
|
+
]}
|
|
439
|
+
/>
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
export function LiveIndicator({ compact }: { compact?: boolean }): JSX.Element {
|
|
444
|
+
const { state, lastUpdate, error } = connection.value;
|
|
445
|
+
const label = { live: "Live", polling: "Reconnecting", offline: "Offline", connecting: "Connecting" }[state];
|
|
446
|
+
const detail =
|
|
447
|
+
state === "offline"
|
|
448
|
+
? `Cannot reach the rotator${error ? `: ${error}` : ""}`
|
|
449
|
+
: state === "polling"
|
|
450
|
+
? "Live stream dropped; polling every 15s while it reconnects"
|
|
451
|
+
: state === "live"
|
|
452
|
+
? "Streaming live updates"
|
|
453
|
+
: "Connecting to the rotator";
|
|
454
|
+
return (
|
|
455
|
+
<span class={`live live-${state}${compact ? " live-compact" : ""}`} title={detail} role="status">
|
|
456
|
+
<span class="live-dot" aria-hidden="true" />
|
|
457
|
+
<span class="live-label">
|
|
458
|
+
{label}
|
|
459
|
+
{!compact && lastUpdate > 0 && state !== "live" && (
|
|
460
|
+
<span class="live-age"> · {formatRelative(lastUpdate, now.value)}</span>
|
|
461
|
+
)}
|
|
462
|
+
</span>
|
|
463
|
+
</span>
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const SUPPORT_SNOOZE_MS = 30 * 24 * 60 * 60 * 1000;
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Quiet, dismissible support ask; returns every 30 days unless turned off.
|
|
471
|
+
* A card in the expanded rail, a heart that opens the same note when collapsed.
|
|
472
|
+
*/
|
|
473
|
+
function SupportNudge(): JSX.Element | null {
|
|
474
|
+
const [visible, setVisible] = useState(() => {
|
|
475
|
+
if (readPref("hideDonationModal", "")) return false;
|
|
476
|
+
const snoozedAt = Number(readPref("donationPromptSnoozedAt", "0")) || 0;
|
|
477
|
+
return Date.now() - snoozedAt > SUPPORT_SNOOZE_MS;
|
|
478
|
+
});
|
|
479
|
+
if (!visible) return null;
|
|
480
|
+
const snooze = () => {
|
|
481
|
+
writePref("donationPromptSnoozedAt", String(Date.now()));
|
|
482
|
+
setVisible(false);
|
|
483
|
+
};
|
|
484
|
+
const body = (
|
|
485
|
+
<>
|
|
486
|
+
<span class="support-icon">
|
|
487
|
+
<Icon name="heart" size={14} />
|
|
488
|
+
</span>
|
|
489
|
+
<span class="support-text">
|
|
490
|
+
Saving money with the rotator?{" "}
|
|
491
|
+
<a href={SUPPORT_URL} target="_blank" rel="noopener noreferrer">
|
|
492
|
+
Support the project
|
|
493
|
+
</a>
|
|
494
|
+
</span>
|
|
495
|
+
</>
|
|
496
|
+
);
|
|
497
|
+
return (
|
|
498
|
+
<>
|
|
499
|
+
<div class="support-nudge">
|
|
500
|
+
{body}
|
|
501
|
+
<button type="button" class="support-dismiss" aria-label="Dismiss for 30 days" title="Dismiss for 30 days" onClick={snooze}>
|
|
502
|
+
<Icon name="x" size={12} />
|
|
503
|
+
</button>
|
|
504
|
+
</div>
|
|
505
|
+
<span class="support-mini">
|
|
506
|
+
<Popover
|
|
507
|
+
label="Support the project"
|
|
508
|
+
triggerClass="rail-item rail-heart"
|
|
509
|
+
triggerTitle="Support the project"
|
|
510
|
+
placement="right-end"
|
|
511
|
+
class="support-pop"
|
|
512
|
+
trigger={
|
|
513
|
+
<span class="rail-icon">
|
|
514
|
+
<Icon name="heart" size={18} />
|
|
515
|
+
</span>
|
|
516
|
+
}
|
|
517
|
+
>
|
|
518
|
+
{(close) => (
|
|
519
|
+
<>
|
|
520
|
+
<div class="support-pop-body">{body}</div>
|
|
521
|
+
<div class="support-pop-actions">
|
|
522
|
+
<Button
|
|
523
|
+
size="sm"
|
|
524
|
+
variant="ghost"
|
|
525
|
+
onClick={() => {
|
|
526
|
+
close();
|
|
527
|
+
snooze();
|
|
528
|
+
}}
|
|
529
|
+
>
|
|
530
|
+
Not now
|
|
531
|
+
</Button>
|
|
532
|
+
<a class="btn btn-primary btn-sm" href={SUPPORT_URL} target="_blank" rel="noopener noreferrer" data-autofocus>
|
|
533
|
+
<Icon name="heart" size={14} /> Support
|
|
534
|
+
</a>
|
|
535
|
+
</div>
|
|
536
|
+
</>
|
|
537
|
+
)}
|
|
538
|
+
</Popover>
|
|
539
|
+
</span>
|
|
540
|
+
</>
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// ── Banners ─────────────────────────────────────────────────────────────
|
|
545
|
+
|
|
546
|
+
function Banners(): JSX.Element | null {
|
|
547
|
+
const data = overview.value;
|
|
548
|
+
const [dismissed, setDismissed] = useState(() => readPref("updateDismissed", ""));
|
|
549
|
+
const [pendingRestart, setPendingRestart] = useState(() => readPref("updatePendingRestart", ""));
|
|
550
|
+
const [hiddenNotices, setHiddenNotices] = useState<string[]>([]);
|
|
551
|
+
if (!data) return null;
|
|
552
|
+
const update = data.updateInfo;
|
|
553
|
+
const banners: ComponentChildren[] = [];
|
|
554
|
+
|
|
555
|
+
if (connection.value.state === "offline" && connection.value.lastUpdate > 0) {
|
|
556
|
+
banners.push(
|
|
557
|
+
<div class="banner tone-bad" key="offline" role="alert">
|
|
558
|
+
<span class="banner-icon">
|
|
559
|
+
<Icon name="critical" size={16} />
|
|
560
|
+
</span>
|
|
561
|
+
<div class="banner-text">
|
|
562
|
+
<strong>Can't reach the rotator.</strong> Showing data from {formatRelative(connection.value.lastUpdate, now.value)}; retrying in the background.
|
|
563
|
+
</div>
|
|
564
|
+
</div>,
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
if (pendingRestart) {
|
|
569
|
+
banners.push(
|
|
570
|
+
<div class="banner tone-ok" key="restart">
|
|
571
|
+
<span class="banner-icon">
|
|
572
|
+
<Icon name="checkCircle" size={16} />
|
|
573
|
+
</span>
|
|
574
|
+
<div class="banner-text">
|
|
575
|
+
<strong>Updated to v{pendingRestart}.</strong> Restart the rotator process to run the new version.
|
|
576
|
+
</div>
|
|
577
|
+
<Button
|
|
578
|
+
size="sm"
|
|
579
|
+
variant="ghost"
|
|
580
|
+
onClick={() => {
|
|
581
|
+
writePref("updatePendingRestart", null);
|
|
582
|
+
setPendingRestart("");
|
|
583
|
+
}}
|
|
584
|
+
>
|
|
585
|
+
Dismiss
|
|
586
|
+
</Button>
|
|
587
|
+
</div>,
|
|
588
|
+
);
|
|
589
|
+
} else if (update?.updateAvailable && update.latestVersion && dismissed !== update.latestVersion) {
|
|
590
|
+
const latest = update.latestVersion;
|
|
591
|
+
banners.push(
|
|
592
|
+
<div class="banner tone-info" key="update">
|
|
593
|
+
<span class="banner-icon">
|
|
594
|
+
<Icon name="download" size={16} />
|
|
595
|
+
</span>
|
|
596
|
+
<div class="banner-text">
|
|
597
|
+
<strong>Version {latest} is available.</strong> You are running v{update.currentVersion}.
|
|
598
|
+
</div>
|
|
599
|
+
<div class="banner-actions">
|
|
600
|
+
<a class="btn btn-ghost btn-sm" href="https://github.com/tuxevil/tuxevil-rotator/releases" target="_blank" rel="noopener noreferrer">
|
|
601
|
+
Changelog
|
|
602
|
+
</a>
|
|
603
|
+
<Button
|
|
604
|
+
size="sm"
|
|
605
|
+
variant="ghost"
|
|
606
|
+
onClick={() => {
|
|
607
|
+
writePref("updateDismissed", latest);
|
|
608
|
+
setDismissed(latest);
|
|
609
|
+
}}
|
|
610
|
+
>
|
|
611
|
+
Dismiss
|
|
612
|
+
</Button>
|
|
613
|
+
<AsyncButton
|
|
614
|
+
size="sm"
|
|
615
|
+
variant="primary"
|
|
616
|
+
onClick={async () => {
|
|
617
|
+
try {
|
|
618
|
+
const result = await api.selfUpdate();
|
|
619
|
+
if (result.ok && result.to) {
|
|
620
|
+
writePref("updatePendingRestart", result.to);
|
|
621
|
+
setPendingRestart(result.to);
|
|
622
|
+
} else toast(`Update failed: ${result.message || "unknown error"}`, "error");
|
|
623
|
+
} catch (err) {
|
|
624
|
+
toast(`Update failed: ${err instanceof Error ? err.message : String(err)}`, "error");
|
|
625
|
+
}
|
|
626
|
+
}}
|
|
627
|
+
>
|
|
628
|
+
Update now
|
|
629
|
+
</AsyncButton>
|
|
630
|
+
</div>
|
|
631
|
+
</div>,
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
for (const notice of data.notifications) {
|
|
636
|
+
if (hiddenNotices.includes(notice.id) || readPref(`notif-dismissed-${notice.id}`, "")) continue;
|
|
637
|
+
const tone = notice.type === "critical" ? "bad" : notice.type === "warning" ? "warn" : "info";
|
|
638
|
+
let actionUrl: string | null;
|
|
639
|
+
try {
|
|
640
|
+
const parsed = notice.actionUrl ? new URL(notice.actionUrl, window.location.origin) : null;
|
|
641
|
+
actionUrl = parsed && (parsed.protocol === "https:" || parsed.protocol === "http:") ? parsed.href : null;
|
|
642
|
+
} catch {
|
|
643
|
+
actionUrl = null;
|
|
644
|
+
}
|
|
645
|
+
banners.push(
|
|
646
|
+
<div class={`banner tone-${tone}`} key={`n-${notice.id}`}>
|
|
647
|
+
<span class="banner-icon">
|
|
648
|
+
<Icon name={notice.type === "info" ? "info" : "warning"} size={16} />
|
|
649
|
+
</span>
|
|
650
|
+
<div class="banner-text">
|
|
651
|
+
<strong>{notice.title}</strong> {notice.message}
|
|
652
|
+
</div>
|
|
653
|
+
<div class="banner-actions">
|
|
654
|
+
{actionUrl && (
|
|
655
|
+
<a class="btn btn-ghost btn-sm" href={actionUrl} target="_blank" rel="noopener noreferrer">
|
|
656
|
+
{notice.actionLabel || "Learn more"}
|
|
657
|
+
</a>
|
|
658
|
+
)}
|
|
659
|
+
<Button
|
|
660
|
+
size="sm"
|
|
661
|
+
variant="ghost"
|
|
662
|
+
icon="x"
|
|
663
|
+
iconOnly
|
|
664
|
+
onClick={() => {
|
|
665
|
+
writePref(`notif-dismissed-${notice.id}`, "1");
|
|
666
|
+
setHiddenNotices([...hiddenNotices, notice.id]);
|
|
667
|
+
}}
|
|
668
|
+
>
|
|
669
|
+
Dismiss
|
|
670
|
+
</Button>
|
|
671
|
+
</div>
|
|
672
|
+
</div>,
|
|
673
|
+
);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
return banners.length > 0 ? <div class="banners">{banners}</div> : null;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
function NotFound(): JSX.Element {
|
|
680
|
+
return (
|
|
681
|
+
<div class="empty empty-page">
|
|
682
|
+
<span class="empty-icon">
|
|
683
|
+
<Icon name="search" size={20} />
|
|
684
|
+
</span>
|
|
685
|
+
<strong>This page does not exist.</strong>
|
|
686
|
+
<Link href={BASE} class="btn btn-secondary btn-md">
|
|
687
|
+
Go to the overview
|
|
688
|
+
</Link>
|
|
689
|
+
</div>
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
// ── Sign in ─────────────────────────────────────────────────────────────
|
|
694
|
+
|
|
695
|
+
function LoginScreen(): JSX.Element {
|
|
696
|
+
const [token, setToken] = useState("");
|
|
697
|
+
const [busy, setBusy] = useState(false);
|
|
698
|
+
const [error, setError] = useState<string | null>(() =>
|
|
699
|
+
new URLSearchParams(window.location.search).get("auth") === "invalid"
|
|
700
|
+
? "That sign-in link has an invalid or outdated token."
|
|
701
|
+
: null,
|
|
702
|
+
);
|
|
703
|
+
|
|
704
|
+
useEffect(() => {
|
|
705
|
+
const params = new URLSearchParams(window.location.search);
|
|
706
|
+
if (params.has("auth")) {
|
|
707
|
+
params.delete("auth");
|
|
708
|
+
const rest = params.toString();
|
|
709
|
+
window.history.replaceState(null, "", window.location.pathname + (rest ? `?${rest}` : ""));
|
|
710
|
+
}
|
|
711
|
+
}, []);
|
|
712
|
+
|
|
713
|
+
const submit = async (event: Event) => {
|
|
714
|
+
event.preventDefault();
|
|
715
|
+
if (!token.trim()) return;
|
|
716
|
+
setBusy(true);
|
|
717
|
+
setError(null);
|
|
718
|
+
try {
|
|
719
|
+
await signIn(token.trim());
|
|
720
|
+
} catch (err) {
|
|
721
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
722
|
+
} finally {
|
|
723
|
+
setBusy(false);
|
|
724
|
+
}
|
|
725
|
+
};
|
|
726
|
+
|
|
727
|
+
return (
|
|
728
|
+
<div class="login">
|
|
729
|
+
<div class="login-glow" aria-hidden="true" />
|
|
730
|
+
<form class="login-card" onSubmit={submit}>
|
|
731
|
+
<div class="login-brand">
|
|
732
|
+
<LogoMark size={40} />
|
|
733
|
+
</div>
|
|
734
|
+
<div class="login-titles">
|
|
735
|
+
<h1>Sign in to Tuxevil Rotator</h1>
|
|
736
|
+
<p class="login-help">
|
|
737
|
+
Paste the admin token (<code>TUXEVIL_ROTATOR_ADMIN_TOKEN</code>). Links ending in <code>?token=…</code> sign you in directly.
|
|
738
|
+
</p>
|
|
739
|
+
</div>
|
|
740
|
+
<label class="field">
|
|
741
|
+
<span class="field-label">Admin token</span>
|
|
742
|
+
<input
|
|
743
|
+
class="input input-lg"
|
|
744
|
+
type="password"
|
|
745
|
+
name="admin-token"
|
|
746
|
+
autocomplete="current-password"
|
|
747
|
+
value={token}
|
|
748
|
+
spellcheck={false}
|
|
749
|
+
autofocus
|
|
750
|
+
onInput={(event) => setToken((event.target as HTMLInputElement).value)}
|
|
751
|
+
/>
|
|
752
|
+
</label>
|
|
753
|
+
{error && (
|
|
754
|
+
<p class="form-error" role="alert">
|
|
755
|
+
{error}
|
|
756
|
+
</p>
|
|
757
|
+
)}
|
|
758
|
+
<Button type="submit" variant="primary" class="btn-block" loading={busy} disabled={!token.trim()}>
|
|
759
|
+
Sign in
|
|
760
|
+
</Button>
|
|
761
|
+
<p class="login-foot">The browser keeps a session cookie for 30 days; the token itself is not stored.</p>
|
|
762
|
+
</form>
|
|
763
|
+
</div>
|
|
764
|
+
);
|
|
765
|
+
}
|