mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Created toggle for hotspot in admin settings. User needs sudo privileges.
This commit is contained in:
parent
bc22fb6a6c
commit
f27e9fdf63
8 changed files with 398 additions and 6 deletions
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue