feat: add async SQLite on Node 24 and improve messaging diagnostics (#520)

Move database work off the main thread on Node.js 24 and improve message handling and runtime diagnostics.

Preserve migration, restart, and concurrency coverage with the async SQLite driver.
This commit is contained in:
MliKiowa authored and GitHub committed 2026-10-13 10:12:47 +08:00
1 parent 20f48d11ec
commit c7428363cb
170 files changed
+7748 -3913

No files matched your search

+22 -4
View File
@@ -53,11 +53,29 @@ interface ErrorPayload {
}
async function readJson<T>(res: Response): Promise<T> {
let payload: unknown;
try {
return (await res.json()) as T;
} catch {
return {} as T;
payload = await res.json();
} catch (error) {
if (!(error instanceof SyntaxError)) {
throw error;
}
throw invalidJsonResponse(res);
}
if (payload === null || typeof payload !== 'object' || Array.isArray(payload)) {
throw invalidJsonResponse(res);
}
return payload as T;
}
function invalidJsonResponse(res: Response): ApiError {
return res.ok
? new ApiError(502, '服务端返回了无效的 JSON 响应', 'INVALID_RESPONSE')
: new ApiError(res.status, res.statusText || '请求失败');
}
function extractErrorMessage(payload: ErrorPayload, fallback: string): string {
@@ -1088,7 +1106,7 @@ class HttpApiClient implements ApiClient {
}
if (!res.ok || !res.body) {
const payload = await readJson<ErrorPayload>(res).catch(() => ({}) as ErrorPayload);
const payload = await readJson<ErrorPayload>(res);
throw new ApiError(
res.status,
extractErrorMessage(payload, '流式调用失败'),
@@ -0,0 +1,33 @@
export const LOW_INTEGRITY_PERMANENT_KEY = 'snowluma.low-integrity.dismissed.v1';
export const LOW_INTEGRITY_SESSION_KEY = 'snowluma.low-integrity.session-dismissed.v1';
export function readLowIntegrityDismissed(): boolean {
if (typeof window === 'undefined') {
return false;
}
// Read independently: blocking one storage must not discard a preference
// successfully saved in the other.
for (const [storage, key] of [
['localStorage', LOW_INTEGRITY_PERMANENT_KEY],
['sessionStorage', LOW_INTEGRITY_SESSION_KEY],
] as const) {
try {
if (window[storage].getItem(key) === '1') {
return true;
}
} catch (error) {
console.warn('failed to read low integrity warning preference', error);
}
}
return false;
}
export function saveLowIntegrityDismissed(scope: 'session' | 'permanent'): void {
if (scope === 'permanent') {
window.localStorage.setItem(LOW_INTEGRITY_PERMANENT_KEY, '1');
} else {
window.sessionStorage.setItem(LOW_INTEGRITY_SESSION_KEY, '1');
}
}
+6 -5
View File
@@ -57,7 +57,6 @@ export function downloadBlob(blob: Blob, filename: string): void {
setTimeout(() => URL.revokeObjectURL(url), 1000);
}
/** Clipboard write that still works on LAN HTTP and inside a modal focus trap. */
/** WebKit `<input type="color">` only accepts `#rrggbb`. */
export function toColorInputValue(raw: string, fallback = '#0ea5e9'): string {
const v = raw.trim();
@@ -73,6 +72,7 @@ export function toColorInputValue(raw: string, fallback = '#0ea5e9'): string {
return fallback;
}
/** Clipboard write that still works on LAN HTTP and inside a modal focus trap. */
export async function copyText(value: string): Promise<boolean> {
try {
if (navigator.clipboard?.writeText) {
@@ -83,8 +83,9 @@ export async function copyText(value: string): Promise<boolean> {
/* insecure origin / permission — fall through */
}
const ta = document.createElement('textarea');
try {
const ta = document.createElement('textarea');
ta.value = value;
ta.setAttribute('readonly', '');
ta.style.position = 'fixed';
@@ -95,10 +96,10 @@ export async function copyText(value: string): Promise<boolean> {
host.appendChild(ta);
ta.focus();
ta.setSelectionRange(0, ta.value.length);
const ok = document.execCommand('copy');
host.removeChild(ta);
return ok;
return document.execCommand('copy');
} catch {
return false;
} finally {
ta.remove();
}
}