Files
gitlab-instance-0a899031_d2…/lib/liveTelemetry.ts
2026-03-26 01:59:04 -05:00

22 lines
723 B
TypeScript

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 })
}