's'
This commit is contained in:
21
lib/liveTelemetry.ts
Normal file
21
lib/liveTelemetry.ts
Normal 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 })
|
||||
}
|
||||
Reference in New Issue
Block a user