* feat(sessions): add channelIdleMinutes config for per-channel session idle durations
Add new `channelIdleMinutes` config option to allow different session idle
timeouts per channel. For example, Discord sessions can now be configured
to last 7 days (10080 minutes) while other channels use shorter defaults.
Config example:
sessions:
channelIdleMinutes:
discord: 10080 # 7 days
The channel-specific idle is passed as idleMinutesOverride to the existing
resolveSessionResetPolicy, integrating cleanly with the new reset policy
architecture.
* fix
* feat: add per-channel session reset overrides (#1353) (thanks @cash-echo-bot)
---------
Co-authored-by: Cash Williams <cashwilliams@gmail.com>
Co-authored-by: Peter Steinberger <steipete@gmail.com>
48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
type FetchWithPreconnect = typeof fetch & {
|
|
preconnect: (url: string, init?: { credentials?: RequestCredentials }) => void;
|
|
};
|
|
|
|
export function wrapFetchWithAbortSignal(fetchImpl: typeof fetch): typeof fetch {
|
|
const wrapped = ((input: RequestInfo | URL, init?: RequestInit) => {
|
|
const signal = init?.signal;
|
|
if (!signal) return fetchImpl(input, init);
|
|
if (typeof AbortSignal !== "undefined" && signal instanceof AbortSignal) {
|
|
return fetchImpl(input, init);
|
|
}
|
|
if (typeof AbortController === "undefined") {
|
|
return fetchImpl(input, init);
|
|
}
|
|
if (typeof signal.addEventListener !== "function") {
|
|
return fetchImpl(input, init);
|
|
}
|
|
const controller = new AbortController();
|
|
const onAbort = () => controller.abort();
|
|
if (signal.aborted) {
|
|
controller.abort();
|
|
} else {
|
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
}
|
|
const response = fetchImpl(input, { ...init, signal: controller.signal });
|
|
if (typeof signal.removeEventListener === "function") {
|
|
void response.finally(() => {
|
|
signal.removeEventListener("abort", onAbort);
|
|
});
|
|
}
|
|
return response;
|
|
}) as FetchWithPreconnect;
|
|
|
|
const fetchWithPreconnect = fetchImpl as FetchWithPreconnect;
|
|
wrapped.preconnect =
|
|
typeof fetchWithPreconnect.preconnect === "function"
|
|
? fetchWithPreconnect.preconnect.bind(fetchWithPreconnect)
|
|
: () => {};
|
|
|
|
return Object.assign(wrapped, fetchImpl);
|
|
}
|
|
|
|
export function resolveFetch(fetchImpl?: typeof fetch): typeof fetch | undefined {
|
|
const resolved = fetchImpl ?? globalThis.fetch;
|
|
if (!resolved) return undefined;
|
|
return wrapFetchWithAbortSignal(resolved);
|
|
}
|