fix: add json tags to all config structs — API serialization was broken

This commit is contained in:
Claus Lohmar 2026-08-05 12:17:32 +01:00
parent 1a017999fe
commit 6bb504258f
2 changed files with 22 additions and 15 deletions

View file

@ -12,10 +12,10 @@ import (
// Config represents the top-level application configuration. // Config represents the top-level application configuration.
type Config struct { type Config struct {
Server ServerConfig `yaml:"server"` Server ServerConfig `yaml:"server" json:"server"`
Storage StorageConfig `yaml:"storage"` Storage StorageConfig `yaml:"storage" json:"storage"`
Cameras []CameraConfig `yaml:"cameras"` Cameras []CameraConfig `yaml:"cameras" json:"cameras"`
Go2RTC Go2RTCConfig `yaml:"go2rtc"` Go2RTC Go2RTCConfig `yaml:"go2rtc" json:"go2rtc"`
} }
// ServerConfig holds HTTP server settings. // ServerConfig holds HTTP server settings.
@ -33,17 +33,17 @@ type StorageConfig struct {
// CameraConfig represents a single camera's configuration. // CameraConfig represents a single camera's configuration.
type CameraConfig struct { type CameraConfig struct {
ID string `yaml:"id"` ID string `yaml:"id" json:"id"`
Name string `yaml:"name"` Name string `yaml:"name" json:"name"`
IP string `yaml:"ip"` IP string `yaml:"ip" json:"ip"`
Username string `yaml:"username"` Username string `yaml:"username" json:"username"`
Password string `yaml:"password"` Password string `yaml:"password" json:"password"`
ONVIFPort int `yaml:"onvif_port"` ONVIFPort int `yaml:"onvif_port" json:"onvif_port"`
RTSPMain string `yaml:"rtsp_main"` RTSPMain string `yaml:"rtsp_main" json:"rtsp_main"`
RTSPSub string `yaml:"rtsp_sub"` RTSPSub string `yaml:"rtsp_sub" json:"rtsp_sub"`
Description string `yaml:"description"` Description string `yaml:"description" json:"description"`
Enabled bool `yaml:"enabled"` Enabled bool `yaml:"enabled" json:"enabled"`
Record bool `yaml:"record"` Record bool `yaml:"record" json:"record"`
} }
// Go2RTCConfig holds go2rtc child process settings. // Go2RTCConfig holds go2rtc child process settings.

View file

@ -239,6 +239,9 @@ async function renderCameraCards() {
container.innerHTML = cameras.map(c => ` container.innerHTML = cameras.map(c => `
<div class="camera-card" data-id="${c.id}"> <div class="camera-card" data-id="${c.id}">
<h3>📷 ${c.name || 'Unnamed'} <span style="font-size:11px;color:var(--text-muted)">${c.ip}</span></h3> <h3>📷 ${c.name || 'Unnamed'} <span style="font-size:11px;color:var(--text-muted)">${c.ip}</span></h3>
<input type="hidden" value="${escAttr(c.id)}" data-field="id">
<input type="hidden" value="${escAttr(c.ip)}" data-field="ip">
<input type="hidden" value="${c.onvif_port || 80}" data-field="onvif_port">
<label>Name <input type="text" value="${escAttr(c.name)}" data-field="name"></label> <label>Name <input type="text" value="${escAttr(c.name)}" data-field="name"></label>
<label>Description <textarea data-field="description">${escHtml(c.description)}</textarea></label> <label>Description <textarea data-field="description">${escHtml(c.description)}</textarea></label>
<label>RTSP Main <input type="text" value="${escAttr(c.rtsp_main)}" data-field="rtsp_main"></label> <label>RTSP Main <input type="text" value="${escAttr(c.rtsp_main)}" data-field="rtsp_main"></label>
@ -313,11 +316,15 @@ document.getElementById('btn-save').addEventListener('click', async () => {
const updatedCameras = []; const updatedCameras = [];
cards.forEach(card => { cards.forEach(card => {
const c = {}; const c = {};
// Collect hidden + visible fields.
card.querySelectorAll('[data-field]').forEach(el => { card.querySelectorAll('[data-field]').forEach(el => {
const field = el.dataset.field; const field = el.dataset.field;
if (el.type === 'checkbox') c[field] = el.checked; if (el.type === 'checkbox') c[field] = el.checked;
else c[field] = el.value; else c[field] = el.value;
}); });
// Ensure checkboxes default to true even if unchecked (hidden inputs override).
if (c.enabled === undefined) c.enabled = true;
if (c.record === undefined) c.record = true;
updatedCameras.push(c); updatedCameras.push(c);
}); });