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

@@ -0,0 +1,86 @@
import { useEffect, useRef, useState } from 'react';
import { AlertTriangle } from 'lucide-react';
import { Modal } from '@/components/interior/modal';
import { Button } from '@/components/ui/button';
import {
LOW_INTEGRITY_PERMANENT_KEY,
readLowIntegrityDismissed,
saveLowIntegrityDismissed,
} from '@/lib/low-integrity-warning';
/** Mounted in the authenticated layout so polling and route changes cannot reopen it. */
export function LowIntegrityWarning({ lowIntegrity }: { lowIntegrity: boolean }) {
const [dismissed, setDismissed] = useState(readLowIntegrityDismissed);
const [error, setError] = useState<string | null>(null);
const temporaryButton = useRef<HTMLButtonElement>(null);
useEffect(() => {
const onStorage = (event: StorageEvent) => {
if (event.key === LOW_INTEGRITY_PERMANENT_KEY && event.newValue === '1') {
setDismissed(true);
}
};
window.addEventListener('storage', onStorage);
return () => window.removeEventListener('storage', onStorage);
}, []);
const dismiss = (scope: 'session' | 'permanent') => {
try {
saveLowIntegrityDismissed(scope);
} catch (caught) {
console.warn('failed to save low integrity warning preference', caught);
if (scope === 'permanent') {
setError('无法保存设置,请允许浏览器存储或选择临时关闭。');
return;
}
// Even with storage blocked, temporary dismissal must let the user continue.
}
setError(null);
setDismissed(true);
};
return (
<Modal
open={lowIntegrity && !dismissed}
onClose={() => dismiss('session')}
title={
<span className="flex items-center gap-2">
<AlertTriangle className="size-5 text-warning" />
Node 完整性过低
</span>
}
showClose={false}
closeOnBackdrop={false}
initialFocusRef={temporaryButton}
maxWidth={480}
footer={
<>
<Button type="button" variant="outline" onClick={() => dismiss('permanent')}>
永久关闭
</Button>
<Button ref={temporaryButton} type="button" onClick={() => dismiss('session')}>
临时关闭
</Button>
</>
}
>
<div className="space-y-3">
<p>
当前进程可能无法连接
QQ。请检查启动程序的完整性标签,修正后重启。详情见启动日志。
</p>
<p className="text-xs text-muted-foreground">
临时关闭仅对当前标签页会话有效;永久关闭保存在此浏览器。
</p>
{error && (
<p role="alert" className="text-sm text-destructive">
{error}
</p>
)}
</div>
</Modal>
);
}
@@ -93,17 +93,6 @@ function persist(): void {
}
}
/** Drop every cached contact list (the data layer's "清缓存" button). */
export function clearDebugContactsCache(): void {
mem.clear();
try {
localStorage.removeItem(LS_KEY);
} catch {
/* ignore */
}
}
type ParseRow = (row: Record<string, unknown>) => PickerOption | null;
interface ListState {
+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();
}
}
+2
View File
@@ -6,6 +6,7 @@ import { useHookProcessOps } from '@/hooks/use-hook-process-ops';
import { MainLayout } from '@/components/layout/main-layout';
import { NAV_ITEMS } from '@/components/layout/sidebar';
import { ConfirmDialog } from '@/components/confirm-dialog';
import { LowIntegrityWarning } from '@/components/low-integrity-warning';
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
import { AppStateProvider, type AppResourceState } from '@/contexts/AppStateContext';
import { KioskProvider } from '@/contexts/KioskContext';
@@ -529,6 +530,7 @@ export function AppLayout() {
</KioskProvider>
</LayoutProvider>
<LowIntegrityWarning lowIntegrity={systemInfo?.runtime.lowIntegrity === true} />
<ConfirmDialog
open={!!unloadFailedAlert}
onOpenChange={(open) => !open && dismissUnloadFailedAlert()}
+1
View File
@@ -461,6 +461,7 @@ export interface SystemInfo {
};
runtime: {
pid: number;
lowIntegrity: boolean;
rss: number;
heapTotal: number;
heapUsed: number;