diff --git a/demo/capture-upload.sh b/demo/capture-upload.sh index 9ae841d..acee225 100755 --- a/demo/capture-upload.sh +++ b/demo/capture-upload.sh @@ -376,10 +376,10 @@ apply_camera_settings() { local applied=0 for ctrl in $keys; do local value - value=$(echo "$values" | jq -r ".[\"$ctrl\"] // empty") + value=$(echo "$values" | jq -r ".\"$ctrl\" // empty") if [[ -n "$value" && "$value" != "null" ]]; then if v4l2-ctl -d "$VIDEO_DEVICE" --set-ctrl="${ctrl}=${value}" 2>/dev/null; then - ((applied++)) + ((applied++)) || true fi fi done diff --git a/server.js b/server.js index 8ac7e00..b763153 100644 --- a/server.js +++ b/server.js @@ -147,15 +147,18 @@ app.post('/upload', authenticate, upload.single('image'), async (req, res) => { const settings = allSettings[storageKey] || {}; // Check if we need to modify the image - if (settings.rotation || settings.crop) { + const shouldRotate = settings.rotation && settings.rotation !== 0; + const shouldCrop = settings.crop && settings.crop.width > 0 && settings.crop.height > 0; + + if (shouldRotate || shouldCrop) { console.log(`Applying transformations for ${cameraId}:`, { rotation: settings.rotation, crop: settings.crop }); let pipeline = sharp(req.file.path); - if (settings.rotation) { + if (shouldRotate) { pipeline = pipeline.rotate(settings.rotation); } - if (settings.crop) { + if (shouldCrop) { // crop format: { left, top, width, height } pipeline = pipeline.extract(settings.crop); } @@ -542,8 +545,19 @@ app.post('/settings/:cameraId/available', authenticate, express.json(), (req, re const allSettings = loadCameraSettings(); const existing = allSettings[storageKey] || {}; + // Default config values for new entries + const defaultConfig = { + rotation: 0, + crop: { left: 0, top: 0, width: 0, height: 0 }, + ocr: { enabled: false, minval: 0, maxval: 9999 }, + chartLabel: null, + insertBrightnessToDb: false + }; + // Preserve existing configured values, but update available controls allSettings[storageKey] = { + // Start with defaults, then overlay existing config + ...defaultConfig, ...existing, availableControls: controls, // Merge current camera values as defaults if no values configured yet