Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : MacLustr Vision8 * File : server/src/control.ts9 * Module : server10 * Repository : https://git.spboucher.ai/maclustr-vision11 * Project Website : https://camera.spboucher.ai12 * Created : 2026-11-3013 * Last Modified : 2026-11-3014 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Jeton du canal de commande local entre vision-api et vision-core (dérivé du secret serveur, jamais transmis hors de 127.0.0.1).43import crypto from 'node:crypto';44import { loadServerSecret } from './auth.ts';45import type { Config } from './config.ts';4647export function controlToken(cfg: Config): string {48 return crypto.createHmac('sha256', loadServerSecret(cfg)).update('maclustr-vision/core-control/v1').digest('base64url');49}5051export async function coreCommand(cfg: Config, path: string, body: unknown): Promise<{ status: number; data: any }> {52 const res = await fetch(`http://127.0.0.1:${cfg.go2rtc.controlPort}${path}`, {53 method: 'POST',54 headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${controlToken(cfg)}` },55 body: JSON.stringify(body),56 signal: AbortSignal.timeout(8000),57 redirect: 'error',58 });59 let data: any = null;60 try {61 data = await res.json();62 } catch {63 data = null;64 }65 return { status: res.status, data };66}67