2023-03-07 00:56:35 +01:00
|
|
|
import { RadioState } from '../../app/types';
|
|
|
|
|
|
|
|
export const requestToStart = async () => {
|
|
|
|
console.log("[REST] request to start");
|
|
|
|
|
|
|
|
let success = false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const startUrl = window.location.href + 'start';
|
|
|
|
const resp = await fetch(startUrl, {
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify({ "change": true, "newState": RadioState.STARTED }),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (resp.ok) {
|
|
|
|
console.log("[REST] Start: success");
|
|
|
|
success = true;
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.log("[REST] Start: failure: %s", err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const requestToStop = async () => {
|
|
|
|
console.log("[REST] request to stop");
|
|
|
|
|
|
|
|
let success = false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const stopUrl = window.location.href + 'stop';
|
|
|
|
const resp = await fetch(stopUrl, {
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify({ "change": true, "newState": RadioState.STOPPED }),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (resp.ok) {
|
|
|
|
console.log("[REST] Stop: success");
|
|
|
|
success = true;
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.log("[REST] Stop: failure: %s", err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2023-03-13 23:41:23 +01:00
|
|
|
export const requestLogs = async () => {
|
|
|
|
console.log("[REST] request logs");
|
|
|
|
|
|
|
|
try {
|
|
|
|
const logsUrl = window.location.href + 'status';
|
|
|
|
const resp = await fetch(logsUrl);
|
|
|
|
|
|
|
|
if (resp.ok) {
|
|
|
|
console.log("[REST] Logs: success");
|
|
|
|
const body = await resp.json();
|
|
|
|
if (Array.isArray(body['lines'])) {
|
|
|
|
return body['lines'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.log("[REST] Logs: failure: %s", err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|