send callibration
This commit is contained in:
@@ -426,6 +426,54 @@ app.post('/api/calibration/compute', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* POST /api/calibration/upload-npz
|
||||
* Liest {camera}_calibration.npz aus der aktuellen Session und
|
||||
* schickt sie per PUT an den Webcam-Service.
|
||||
* Body: { camera: "cam0" }
|
||||
*/
|
||||
app.post('/api/calibration/upload-npz', async (req, res) => {
|
||||
try {
|
||||
const { camera } = req.body ?? {};
|
||||
if (!camera) return res.status(400).json({ error: '"camera" parameter fehlt' });
|
||||
if (!WEBCAM_URL) return res.status(501).json({ error: 'WEBCAM_URL ist nicht konfiguriert' });
|
||||
|
||||
const session = await findLatestCalibSession();
|
||||
if (!session) return res.status(400).json({ error: 'Keine Kalibrierungs-Session vorhanden' });
|
||||
|
||||
const npzPath = path.join(calibDataDir, session, `${camera}_calibration.npz`);
|
||||
|
||||
try {
|
||||
await fsPromises.access(npzPath);
|
||||
} catch {
|
||||
return res.status(404).json({
|
||||
error: `Datei nicht gefunden: ${camera}_calibration.npz — bitte zuerst "Kalibrierung berechnen".`
|
||||
});
|
||||
}
|
||||
|
||||
const npzData = await fsPromises.readFile(npzPath);
|
||||
const putUrl = new URL(`/api/cameras/${camera}/calibration`, WEBCAM_URL).toString();
|
||||
|
||||
const putRes = await fetch(putUrl, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/octet-stream' },
|
||||
body: npzData,
|
||||
});
|
||||
|
||||
if (!putRes.ok) {
|
||||
const text = await putRes.text();
|
||||
return res.status(putRes.status).json({ error: `Webcam-Service: ${putRes.status} – ${text}` });
|
||||
}
|
||||
|
||||
const result = await putRes.json();
|
||||
return res.json({ ok: true, camera, session, size: npzData.length, webcam: result });
|
||||
|
||||
} catch (err) {
|
||||
console.error('calibration/upload-npz error:', err);
|
||||
return res.status(500).json({ error: String(err) });
|
||||
}
|
||||
});
|
||||
|
||||
async function checkServiceReachability(name, url) {
|
||||
try {
|
||||
const controller = new AbortController();
|
||||
|
||||
Reference in New Issue
Block a user