22 lines
723 B
TypeScript
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 })
|
|
}
|