57 lines
2.0 KiB
JavaScript
57 lines
2.0 KiB
JavaScript
/**
|
|
* Registers dataset recording control routes.
|
|
* @param {Object} router - Route wrapper with get/post methods
|
|
* @param {Object} app - SignalK app instance
|
|
*/
|
|
function registerDatasetRoutes(router, app) {
|
|
router.post("/dataset/start", (req, res) => {
|
|
try {
|
|
if (!app.datasetControl) {
|
|
return res.status(503).json({ error: "Dataset control not available" });
|
|
}
|
|
const result = app.datasetControl.start();
|
|
res.json({ success: result, message: result ? "Recording started" : "Already recording" });
|
|
} catch (e) {
|
|
res.status(500).json({ error: e.message });
|
|
}
|
|
});
|
|
|
|
router.post("/dataset/stop", (req, res) => {
|
|
try {
|
|
if (!app.datasetControl) {
|
|
return res.status(503).json({ error: "Dataset control not available" });
|
|
}
|
|
const result = app.datasetControl.stop();
|
|
res.json({ success: result, message: result ? "Recording stopped" : "No active recording" });
|
|
} catch (e) {
|
|
res.status(500).json({ error: e.message });
|
|
}
|
|
});
|
|
|
|
router.post("/dataset/restart", (req, res) => {
|
|
try {
|
|
if (!app.datasetControl) {
|
|
return res.status(503).json({ error: "Dataset control not available" });
|
|
}
|
|
const result = app.datasetControl.restart();
|
|
res.json({ success: result, message: "Recording restarted" });
|
|
} catch (e) {
|
|
res.status(500).json({ error: e.message });
|
|
}
|
|
});
|
|
|
|
router.get("/dataset/status", (req, res) => {
|
|
try {
|
|
if (!app.datasetControl) {
|
|
return res.status(503).json({ error: "Dataset control not available" });
|
|
}
|
|
const status = app.datasetControl.getStatus();
|
|
res.json(status);
|
|
} catch (e) {
|
|
res.status(500).json({ error: e.message });
|
|
}
|
|
});
|
|
}
|
|
|
|
module.exports = registerDatasetRoutes;
|