Created toggle for hotspot in admin settings. User needs sudo privileges.

This commit is contained in:
Roland 2022-02-04 09:41:08 -07:00
parent bc22fb6a6c
commit f27e9fdf63
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
8 changed files with 398 additions and 6 deletions

View file

@ -34,7 +34,8 @@ async function apiCall(url, method, body, ms = 10000) {
// await the response or error.
let response = await timeoutPromise(ms, promise);
let copy = response.clone();
if (response.status === 403 && (await copy.json())['code'] === 17) {
let code = (await copy.json())['code'];
if (response.status === 403 && code === 17) {
toast({
type: 'error',
title: 'WROL Mode is enabled!',
@ -423,3 +424,40 @@ export async function getVersion() {
let data = await response.json();
return data['version'];
}
export async function getDevices() {
let response = await apiGet(`${API_URI}/hotspot`);
if (response.status === 200) {
let {devices} = await response.json();
return devices;
} else {
let code = (await response.json())['code'];
if (response.status === 400 && code === 34) {
// Must not be running on a RPi. Don't warn the user.
return null;
}
}
return null;
}
export async function setHotspot(on) {
let response;
if (on) {
response = await apiPost(`${API_URI}/hotspot/on`);
} else {
response = await apiPost(`${API_URI}/hotspot/off`);
}
if (response.status === 204) {
return null;
} else {
let code = (await response.json())['code'];
if (code === 34) {
toast({
type: 'error',
title: 'Unsupported!',
description: 'Hotspot is only supported on a Raspberry Pi!',
time: 5000,
});
}
}
}