Commit 8551b9df authored by vertighel's avatar vertighel
Browse files

fix: update loop URLs and API contract in control.html and viewer.html



POST /api/viewer/<cam_id>/loop {action,exposure} → POST /api/<cam_id>/loop {exptime}
stop: POST {action:stop} → DELETE /api/<cam_id>/loop

Co-Authored-By: default avatarClaude Sonnet 4.6 <noreply@anthropic.com>
parent 444d6c06
Loading
Loading
Loading
Loading
+6 −10
Original line number Diff line number Diff line
@@ -262,26 +262,22 @@
                if (stopBtn)  stopBtn.disabled  = !running;
            }

            async function loopPost(action, extra = {}) {
                return fetch(`${apiBase}/viewer/${cam_id}/loop`, {
            startBtn?.addEventListener('click', async () => {
                const exp = parseFloat(expInput?.value) || 1.0;
                const r = await fetch(`${apiBase}/${cam_id}/loop`, {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ action, ...extra }),
                    body: JSON.stringify({ exptime: exp }),
                });
            }

            startBtn?.addEventListener('click', async () => {
                const exp = parseFloat(expInput?.value) || 1.0;
                const r = await loopPost('start', { exposure: exp });
                if (r.ok) setLoopUI(true);
            });

            stopBtn?.addEventListener('click', async () => {
                await loopPost('stop');
                await fetch(`${apiBase}/${cam_id}/loop`, { method: 'DELETE' });
                setLoopUI(false);
            });

            fetch(`${apiBase}/viewer/${cam_id}/loop`)
            fetch(`${apiBase}/${cam_id}/loop`)
                .then(r => r.json())
                .then(d => setLoopUI(d.running))
                .catch(() => {});
+6 −10
Original line number Diff line number Diff line
@@ -54,26 +54,22 @@ function initViewer(panelId, cam_id, hasLoop, apiBase) {
            if (stopBtn)  stopBtn.disabled  = !running;
        }

        async function loopPost(action, extra = {}) {
            return fetch(`${apiBase}/viewer/${cam_id}/loop`, {
        startBtn?.addEventListener('click', async () => {
            const exp = parseFloat(expInput?.value) || 1.0;
            const r = await fetch(`${apiBase}/${cam_id}/loop`, {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify({ action, ...extra }),
                body: JSON.stringify({ exptime: exp }),
            });
        }

        startBtn?.addEventListener('click', async () => {
            const exp = parseFloat(expInput?.value) || 1.0;
            const r = await loopPost('start', { exposure: exp });
            if (r.ok) setLoopUI(true);
        });

        stopBtn?.addEventListener('click', async () => {
            await loopPost('stop');
            await fetch(`${apiBase}/${cam_id}/loop`, { method: 'DELETE' });
            setLoopUI(false);
        });

        fetch(`${apiBase}/viewer/${cam_id}/loop`)
        fetch(`${apiBase}/${cam_id}/loop`)
            .then(r => r.json())
            .then(d => setLoopUI(d.running))
            .catch(() => {});