This commit is contained in:
eric
2026-03-26 01:59:04 -05:00
parent aba40c8cb7
commit 3bc1599763
12 changed files with 629 additions and 72 deletions

21
lib/liveTelemetry.ts Normal file
View File

@@ -0,0 +1,21 @@
import { apiFetch } from '@/lib/api'
import type { BindPayload } from '@/lib/types'
import { pbCreateLiveSession } from '@/lib/pocketbase'
export async function reportLiveControlEvent(
bind: BindPayload | null,
pbToken: string | null,
userId: string | undefined,
process: string,
event: 'start' | 'restart' | 'stop',
): Promise<void> {
if (!bind || !pbToken?.trim() || !userId) return
let machine: Record<string, unknown> = {}
try {
const r = await apiFetch(bind, '/host/machine_summary', { pbToken: pbToken.trim() })
if (r.ok) machine = (await r.json()) as Record<string, unknown>
} catch {
/* 忽略 */
}
await pbCreateLiveSession(pbToken.trim(), userId, { process, event, machine })
}