@aronnaxlin/bgm-cli 1.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/LICENSE +660 -0
- package/README.en.md +122 -0
- package/README.md +127 -0
- package/README.zh-TW.md +122 -0
- package/package.json +41 -0
- package/src/cli.js +993 -0
- package/src/commands/blog.js +213 -0
- package/src/commands/calendar.js +32 -0
- package/src/commands/character.js +291 -0
- package/src/commands/collection.js +418 -0
- package/src/commands/episode.js +379 -0
- package/src/commands/group.js +488 -0
- package/src/commands/index.js +362 -0
- package/src/commands/notify.js +74 -0
- package/src/commands/person.js +297 -0
- package/src/commands/status.js +74 -0
- package/src/commands/subject.js +537 -0
- package/src/commands/timeline.js +288 -0
- package/src/commands/trending.js +58 -0
- package/src/commands/tui.js +1537 -0
- package/src/commands/user.js +83 -0
- package/src/core/client.js +2065 -0
- package/src/core/config.js +450 -0
- package/src/core/http.js +144 -0
- package/src/core/output.js +3888 -0
- package/src/core/proxy.js +47 -0
- package/src/core/reactions.js +62 -0
- package/src/core/turnstile.js +526 -0
- package/src/data/bangumi-emotes.json +311 -0
- package/src/utils/args.js +113 -0
- package/src/utils/auth-flow.js +373 -0
- package/src/utils/auth.js +90 -0
- package/src/utils/calendar.js +23 -0
- package/src/utils/collection-ops.js +333 -0
- package/src/utils/collection.js +240 -0
- package/src/utils/formatters.js +157 -0
- package/src/utils/helpers.js +283 -0
- package/src/utils/hot.js +182 -0
- package/src/utils/install.js +40 -0
- package/src/utils/prompts.js +87 -0
- package/src/utils/relay.js +74 -0
- package/src/utils/status.js +68 -0
- package/src/utils/tui-interactive.js +197 -0
- package/src/utils/tui-render.js +86 -0
- package/src/utils/turnstile-flow.js +154 -0
- package/src/utils/validators.js +412 -0
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth and Turnstile authorization flow utilities.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import http from "node:http";
|
|
6
|
+
import readline from "node:readline/promises";
|
|
7
|
+
import { getConfigFilePath, setConfigValues } from "../core/config.js";
|
|
8
|
+
import { BangumiApiError as ApiError } from "../core/http.js";
|
|
9
|
+
import { CommandError } from "../core/output.js";
|
|
10
|
+
import { escapeHtml, previewToken, sleep, toBoolean, tryOpenExternalUrl, writeProgress } from "./helpers.js";
|
|
11
|
+
import { askRequired } from "./prompts.js";
|
|
12
|
+
import {
|
|
13
|
+
buildHostedRelayCorsHeaders,
|
|
14
|
+
readHostedRelayJsonBody,
|
|
15
|
+
respondHostedRelayJson,
|
|
16
|
+
respondHostedRelayPreflight,
|
|
17
|
+
respondHtml,
|
|
18
|
+
} from "./relay.js";
|
|
19
|
+
import { extractPrivateSessionId, getPrivateLoginUrl } from "./auth.js";
|
|
20
|
+
|
|
21
|
+
export async function waitForAuthorizationCode({ redirectUri, expectedState, timeoutMs = 300000 }) {
|
|
22
|
+
const callbackUrl = new URL(redirectUri);
|
|
23
|
+
const hostname = callbackUrl.hostname;
|
|
24
|
+
const port = Number(callbackUrl.port || (callbackUrl.protocol === "https:" ? 443 : 80));
|
|
25
|
+
const pathName = callbackUrl.pathname || "/";
|
|
26
|
+
|
|
27
|
+
console.log(`Waiting for callback on ${hostname}:${port}${pathName}`);
|
|
28
|
+
|
|
29
|
+
const result = await new Promise((resolve, reject) => {
|
|
30
|
+
let settled = false;
|
|
31
|
+
const server = http.createServer((req, res) => {
|
|
32
|
+
try {
|
|
33
|
+
const requestUrl = new URL(req.url ?? "/", redirectUri);
|
|
34
|
+
if (requestUrl.pathname !== pathName) {
|
|
35
|
+
respondHtml(res, 404, "Not Found", "<h1>Not Found</h1>");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const error = requestUrl.searchParams.get("error");
|
|
40
|
+
const code = requestUrl.searchParams.get("code");
|
|
41
|
+
const state = requestUrl.searchParams.get("state");
|
|
42
|
+
|
|
43
|
+
if (error) {
|
|
44
|
+
respondHtml(
|
|
45
|
+
res,
|
|
46
|
+
400,
|
|
47
|
+
"Authorization failed",
|
|
48
|
+
`<h1>Authorization failed</h1><p>${escapeHtml(error)}</p>`,
|
|
49
|
+
);
|
|
50
|
+
finishReject(new CommandError(`Bangumi authorization failed: ${error}`));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!code) {
|
|
55
|
+
respondHtml(
|
|
56
|
+
res,
|
|
57
|
+
400,
|
|
58
|
+
"Missing code",
|
|
59
|
+
"<h1>Missing code</h1><p>No authorization code was returned.</p>",
|
|
60
|
+
);
|
|
61
|
+
finishReject(new CommandError("Authorization callback did not contain code."));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (expectedState && state !== expectedState) {
|
|
66
|
+
respondHtml(
|
|
67
|
+
res,
|
|
68
|
+
400,
|
|
69
|
+
"Invalid state",
|
|
70
|
+
"<h1>Invalid state</h1><p>State verification failed.</p>",
|
|
71
|
+
);
|
|
72
|
+
finishReject(new CommandError("Authorization callback state mismatch."));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
respondHtml(
|
|
77
|
+
res,
|
|
78
|
+
200,
|
|
79
|
+
"Authorization completed",
|
|
80
|
+
"<h1>Authorization completed</h1><p>You can now return to the terminal.</p>",
|
|
81
|
+
);
|
|
82
|
+
finishResolve(code);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
finishReject(error);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
server.once("error", (error) => {
|
|
89
|
+
finishReject(
|
|
90
|
+
new CommandError(
|
|
91
|
+
`Failed to listen on redirect URI ${redirectUri}: ${error.message}. Use manual callback mode instead.`,
|
|
92
|
+
),
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const timeout = setTimeout(() => {
|
|
97
|
+
finishReject(new CommandError("Timed out waiting for OAuth callback. Rerun `bgm --init` and choose manual callback mode if needed."));
|
|
98
|
+
}, timeoutMs);
|
|
99
|
+
|
|
100
|
+
function cleanup() {
|
|
101
|
+
clearTimeout(timeout);
|
|
102
|
+
server.close();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function finishResolve(value) {
|
|
106
|
+
if (settled) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
settled = true;
|
|
110
|
+
cleanup();
|
|
111
|
+
resolve(value);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function finishReject(error) {
|
|
115
|
+
if (settled) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
settled = true;
|
|
119
|
+
cleanup();
|
|
120
|
+
reject(error);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
server.listen(port, hostname);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export async function waitForHostedOAuthAuthorization(backend, session) {
|
|
130
|
+
const startedAt = Date.now();
|
|
131
|
+
const pollIntervalMs = session.poll_interval_ms ?? 2000;
|
|
132
|
+
const expiresAt = session.expires_at ? new Date(session.expires_at).getTime() : Date.now() + 300000;
|
|
133
|
+
|
|
134
|
+
while (Date.now() <= expiresAt) {
|
|
135
|
+
let status;
|
|
136
|
+
try {
|
|
137
|
+
status = await backend.getSession(session.session_id);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
if (error instanceof ApiError && error.status === 404 && error.details?.status === "expired") {
|
|
140
|
+
throw new CommandError("OAuth session expired before authorization completed.");
|
|
141
|
+
}
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (status.status === "authorized") {
|
|
146
|
+
return backend.claimSession(session.session_id);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (status.status === "failed") {
|
|
150
|
+
throw new CommandError(`OAuth authorization failed: ${status.error ?? "unknown_error"}`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (status.status === "expired") {
|
|
154
|
+
throw new CommandError("OAuth session expired before authorization completed.");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (Date.now() - startedAt < 1000 || (Date.now() - startedAt) % 10000 < pollIntervalMs) {
|
|
158
|
+
console.log(`Waiting for authorization... session ${session.session_id}`);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
await sleep(pollIntervalMs);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
throw new CommandError("Timed out waiting for the hosted OAuth backend to finish authorization.");
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export async function waitForHostedTurnstileAuthorization(backend, session, context = {}) {
|
|
168
|
+
const startedAt = Date.now();
|
|
169
|
+
const pollIntervalMs = session.poll_interval_ms ?? 2000;
|
|
170
|
+
const expiresAt = session.expires_at ? new Date(session.expires_at).getTime() : Date.now() + 300000;
|
|
171
|
+
|
|
172
|
+
while (Date.now() <= expiresAt) {
|
|
173
|
+
let status;
|
|
174
|
+
try {
|
|
175
|
+
status = await backend.getTurnstileSession(session.session_id, session.session_secret);
|
|
176
|
+
} catch (error) {
|
|
177
|
+
if (error instanceof ApiError && error.status === 404 && error.details?.status === "expired") {
|
|
178
|
+
throw new CommandError("Turnstile session expired before verification completed.");
|
|
179
|
+
}
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (status.status === "completed") {
|
|
184
|
+
return backend.claimTurnstileSession(session.session_id, session.session_secret);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (status.status === "failed") {
|
|
188
|
+
throw new CommandError(`Turnstile verification failed: ${status.error ?? "unknown_error"}`);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (status.status === "expired") {
|
|
192
|
+
throw new CommandError("Turnstile session expired before verification completed.");
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (Date.now() - startedAt < 1000 || (Date.now() - startedAt) % 10000 < pollIntervalMs) {
|
|
196
|
+
writeProgress(context, `Waiting for Turnstile verification... session ${session.session_id}`);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
await sleep(pollIntervalMs);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
throw new CommandError("Timed out waiting for the hosted Turnstile backend to finish verification.");
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export async function startHostedRelayReceiver({ kind, timeoutMs = 300000 }) {
|
|
206
|
+
const listenHost = "127.0.0.1";
|
|
207
|
+
const server = http.createServer();
|
|
208
|
+
let settled = false;
|
|
209
|
+
let timeout = null;
|
|
210
|
+
let closed = false;
|
|
211
|
+
let resolveCompletion;
|
|
212
|
+
let rejectCompletion;
|
|
213
|
+
|
|
214
|
+
const completion = new Promise((resolve, reject) => {
|
|
215
|
+
resolveCompletion = resolve;
|
|
216
|
+
rejectCompletion = reject;
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
server.on("request", async (req, res) => {
|
|
220
|
+
try {
|
|
221
|
+
const origin = callbackUrl ? new URL(callbackUrl).origin : `http://${listenHost}`;
|
|
222
|
+
const requestUrl = new URL(req.url ?? "/", origin);
|
|
223
|
+
|
|
224
|
+
if (req.method === "OPTIONS" && requestUrl.pathname === "/callback") {
|
|
225
|
+
respondHostedRelayPreflight(req, res);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (req.method === "POST" && requestUrl.pathname === "/callback") {
|
|
230
|
+
const payload = await readHostedRelayJsonBody(req);
|
|
231
|
+
|
|
232
|
+
if (kind === "oauth") {
|
|
233
|
+
if (!payload || typeof payload.access_token !== "string") {
|
|
234
|
+
respondHostedRelayJson(req, res, 400, { error: "missing_access_token" });
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (kind === "turnstile") {
|
|
240
|
+
if (!payload || typeof payload.turnstileToken !== "string") {
|
|
241
|
+
respondHostedRelayJson(req, res, 400, { error: "missing_turnstile_token" });
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
respondHostedRelayJson(req, res, 200, {
|
|
247
|
+
ok: true,
|
|
248
|
+
message: "Payload received. You can return to the terminal.",
|
|
249
|
+
});
|
|
250
|
+
finishResolve(payload);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (req.method === "GET" && requestUrl.pathname === "/health") {
|
|
255
|
+
res.writeHead(200, { "Content-Type": "application/json; charset=utf-8" });
|
|
256
|
+
res.end(JSON.stringify({ ok: true, kind }));
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
respondHtml(res, 404, "Not Found", "<h1>Not Found</h1>");
|
|
261
|
+
} catch (error) {
|
|
262
|
+
finishReject(error);
|
|
263
|
+
respondHostedRelayJson(req, res, 500, { error: "internal_error" });
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
await new Promise((resolve, reject) => {
|
|
268
|
+
const onError = (error) => reject(new CommandError(`Failed to start local relay receiver: ${error.message}`));
|
|
269
|
+
server.once("error", onError);
|
|
270
|
+
server.listen(0, listenHost, () => resolve());
|
|
271
|
+
server.once("listening", () => {
|
|
272
|
+
server.off("error", onError);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
const address = server.address();
|
|
277
|
+
if (!address || typeof address === "string") {
|
|
278
|
+
server.close();
|
|
279
|
+
throw new CommandError("Failed to determine local relay receiver address.");
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const callbackUrl = `http://${listenHost}:${address.port}/callback`;
|
|
283
|
+
timeout = setTimeout(() => {
|
|
284
|
+
finishReject(new CommandError(`Timed out waiting for the hosted ${kind} callback relay.`));
|
|
285
|
+
}, timeoutMs);
|
|
286
|
+
|
|
287
|
+
return {
|
|
288
|
+
callbackUrl,
|
|
289
|
+
completion,
|
|
290
|
+
timeoutMs,
|
|
291
|
+
close: cleanup,
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
function cleanup() {
|
|
295
|
+
if (closed) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
closed = true;
|
|
299
|
+
if (timeout) {
|
|
300
|
+
clearTimeout(timeout);
|
|
301
|
+
}
|
|
302
|
+
server.close();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function finishResolve(value) {
|
|
306
|
+
if (settled) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
settled = true;
|
|
310
|
+
cleanup();
|
|
311
|
+
resolveCompletion(value);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function finishReject(error) {
|
|
315
|
+
if (settled) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
settled = true;
|
|
319
|
+
cleanup();
|
|
320
|
+
rejectCompletion(error);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export async function runPrivateSessionLogin(options, context = {}) {
|
|
325
|
+
if (context.json) {
|
|
326
|
+
throw new CommandError("bgm auth session-login does not support --json because it requires interactive prompts.");
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const loginUrl = getPrivateLoginUrl();
|
|
330
|
+
const manualOnly = toBoolean(options.manual, false);
|
|
331
|
+
let openedBrowser = false;
|
|
332
|
+
|
|
333
|
+
writeProgress(context, "Private API login can save an optional next.bgm.tv session for p1 requests.");
|
|
334
|
+
writeProgress(context, "This does not replace the normal Access Token login path.");
|
|
335
|
+
writeProgress(context, "This session helper also does not replace Turnstile verification for group write operations.");
|
|
336
|
+
writeProgress(context, `Official login page: ${loginUrl}`);
|
|
337
|
+
writeProgress(context, "After signing in successfully, copy the `chiiNextSessionID` cookie value from your browser and paste it here.");
|
|
338
|
+
writeProgress(context, "You can paste either the raw session ID or a full cookie string that includes chiiNextSessionID=...");
|
|
339
|
+
|
|
340
|
+
if (!manualOnly) {
|
|
341
|
+
openedBrowser = tryOpenExternalUrl(loginUrl);
|
|
342
|
+
writeProgress(context, openedBrowser ? "Browser opened." : "Automatic browser launch failed or is unavailable.");
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const rl = readline.createInterface({
|
|
346
|
+
input: process.stdin,
|
|
347
|
+
output: process.stdout,
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
try {
|
|
351
|
+
const rawValue = await askRequired(rl, "Paste chiiNextSessionID or cookie string");
|
|
352
|
+
const sessionId = extractPrivateSessionId(rawValue);
|
|
353
|
+
if (!sessionId) {
|
|
354
|
+
throw new CommandError("Could not find chiiNextSessionID in the pasted value.");
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
await setConfigValues({
|
|
358
|
+
privateSessionId: sessionId,
|
|
359
|
+
privateSessionUpdatedAt: new Date().toISOString(),
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
return {
|
|
363
|
+
resource: "private-session-mutation",
|
|
364
|
+
saved: true,
|
|
365
|
+
configFile: getConfigFilePath(),
|
|
366
|
+
sessionPreview: previewToken(sessionId),
|
|
367
|
+
loginUrl,
|
|
368
|
+
openedBrowser,
|
|
369
|
+
};
|
|
370
|
+
} finally {
|
|
371
|
+
rl.close();
|
|
372
|
+
}
|
|
373
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth-related utilities shared across the CLI.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { CommandError } from "../core/output.js";
|
|
6
|
+
|
|
7
|
+
export function createState() {
|
|
8
|
+
return `bgm-cli-${Date.now().toString(36)}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function fallbackUserAgent(config) {
|
|
12
|
+
const developerId = deriveDeveloperId(config);
|
|
13
|
+
const appName = config.appName ?? "bgm-cli";
|
|
14
|
+
const version = config.appVersion ?? "1.0.0";
|
|
15
|
+
const homepageLink = config.homepageLink;
|
|
16
|
+
|
|
17
|
+
let userAgent = developerId
|
|
18
|
+
? `${developerId}/${appName}/${version}`
|
|
19
|
+
: `${appName}/${version}`;
|
|
20
|
+
|
|
21
|
+
if (homepageLink) {
|
|
22
|
+
userAgent += ` (${homepageLink})`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return userAgent;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function deriveDeveloperId(config) {
|
|
29
|
+
if (config.developerId) {
|
|
30
|
+
return config.developerId;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (config.homepageLink) {
|
|
34
|
+
const githubMatch = String(config.homepageLink).match(/^https?:\/\/github\.com\/([^/]+)/i);
|
|
35
|
+
if (githubMatch) {
|
|
36
|
+
return githubMatch[1];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function isLocalRedirectUri(redirectUri) {
|
|
44
|
+
try {
|
|
45
|
+
const url = new URL(redirectUri);
|
|
46
|
+
return ["127.0.0.1", "localhost"].includes(url.hostname);
|
|
47
|
+
} catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function extractAuthorizationInput(rawValue) {
|
|
53
|
+
const value = String(rawValue ?? "").trim();
|
|
54
|
+
if (!value) {
|
|
55
|
+
return { kind: "none", value: "" };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (value.startsWith("http://") || value.startsWith("https://")) {
|
|
59
|
+
const url = new URL(value);
|
|
60
|
+
const code = url.searchParams.get("code");
|
|
61
|
+
if (!code) {
|
|
62
|
+
throw new CommandError("Callback URL does not contain a code query parameter.");
|
|
63
|
+
}
|
|
64
|
+
return { kind: "code", value: code };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return { kind: "code", value };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function getPrivateLoginUrl() {
|
|
71
|
+
return "https://next.bgm.tv/login";
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function extractPrivateSessionId(rawValue) {
|
|
75
|
+
const value = String(rawValue ?? "").trim();
|
|
76
|
+
if (!value) {
|
|
77
|
+
return "";
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const cookieMatch = value.match(/(?:^|[;\s])chiiNextSessionID=([^;\s]+)/);
|
|
81
|
+
if (cookieMatch?.[1]) {
|
|
82
|
+
return cookieMatch[1].trim();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!value.includes("=") && !value.includes(";")) {
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return "";
|
|
90
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calendar/weekday utilities.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export function todayWeekdayId() {
|
|
6
|
+
const jsDay = new Date().getDay();
|
|
7
|
+
return jsDay === 0 ? 7 : jsDay; // 1=Mon ... 7=Sun
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function resolveWeekdaySubcommand(cmd) {
|
|
11
|
+
const map = {
|
|
12
|
+
today: null, // sentinel for explicit today
|
|
13
|
+
all: "all", // sentinel for all
|
|
14
|
+
monday: 1, mon: 1,
|
|
15
|
+
tuesday: 2, tue: 2,
|
|
16
|
+
wednesday: 3, wed: 3,
|
|
17
|
+
thursday: 4, thu: 4,
|
|
18
|
+
friday: 5, fri: 5,
|
|
19
|
+
saturday: 6, sat: 6,
|
|
20
|
+
sunday: 7, sun: 7,
|
|
21
|
+
};
|
|
22
|
+
return map[cmd] !== undefined ? map[cmd] : null;
|
|
23
|
+
}
|