mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-11-28 12:53:04 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0efd8a8674 | |||
| 1bf01cadc7 | |||
| 1bd2f64729 | |||
| 58971d0e66 |
@@ -32,7 +32,7 @@
|
||||
"prettier-plugin-svelte": "^3.3.3",
|
||||
"prettier-plugin-tailwindcss": "^0.6.11",
|
||||
"svelte": "^5.28.6",
|
||||
"svelte-check": "^4.1.7",
|
||||
"svelte-check": "^4.2.0",
|
||||
"tailwindcss": "^4.1.6",
|
||||
"tslib": "^2.8.1",
|
||||
"typescript": "^5.8.3",
|
||||
|
||||
Generated
+5
-5
@@ -87,8 +87,8 @@ importers:
|
||||
specifier: ^5.28.6
|
||||
version: 5.28.6
|
||||
svelte-check:
|
||||
specifier: ^4.1.7
|
||||
version: 4.1.7(picomatch@4.0.2)(svelte@5.28.6)(typescript@5.8.3)
|
||||
specifier: ^4.2.0
|
||||
version: 4.2.0(picomatch@4.0.2)(svelte@5.28.6)(typescript@5.8.3)
|
||||
tailwindcss:
|
||||
specifier: ^4.1.6
|
||||
version: 4.1.6
|
||||
@@ -2728,10 +2728,10 @@ packages:
|
||||
}
|
||||
engines: { node: '>=8' }
|
||||
|
||||
svelte-check@4.1.7:
|
||||
svelte-check@4.2.0:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-1jX4BzXrQJhC/Jt3SqYf6Ntu//vmfc6VWp07JkRfK2nn+22yIblspVUo96gzMkg0Zov8lQicxhxsMzOctwcMQQ==
|
||||
integrity: sha512-79ozTLjGBQ2R5PvZ7enSYBsMyY1fy3pwQ/N1BtuTVXtQRH9Vc10eV66LePV52t1ZlflZBTkIGz79cStPnCUEEQ==
|
||||
}
|
||||
engines: { node: '>= 18.0.0' }
|
||||
hasBin: true
|
||||
@@ -4492,7 +4492,7 @@ snapshots:
|
||||
dependencies:
|
||||
has-flag: 4.0.0
|
||||
|
||||
svelte-check@4.1.7(picomatch@4.0.2)(svelte@5.28.6)(typescript@5.8.3):
|
||||
svelte-check@4.2.0(picomatch@4.0.2)(svelte@5.28.6)(typescript@5.8.3):
|
||||
dependencies:
|
||||
'@jridgewell/trace-mapping': 0.3.25
|
||||
chokidar: 4.0.3
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
let hoverText = '';
|
||||
let disabled = false;
|
||||
let timeout = 120;
|
||||
var interval: number;
|
||||
let interval: number;
|
||||
let modalWake: HTMLDialogElement;
|
||||
let modalShutdown: HTMLDialogElement;
|
||||
|
||||
@@ -45,6 +45,9 @@
|
||||
}
|
||||
|
||||
function wake() {
|
||||
countdown(Date.now(), 'wake');
|
||||
device.status = 'pending';
|
||||
|
||||
fetch(`${backendUrl}api/upsnap/wake/${device.id}`, {
|
||||
headers: {
|
||||
Authorization: $pocketbase.authStore.token
|
||||
@@ -52,8 +55,11 @@
|
||||
})
|
||||
.then((resp) => resp.json())
|
||||
.then(async (data) => {
|
||||
if (data.status !== 200) {
|
||||
device.status = 'offline';
|
||||
return;
|
||||
}
|
||||
device = data as Device;
|
||||
await countdown(Date.parse(device.updated), 'wake');
|
||||
if (device.status === 'online' && device.link && device.link_open !== '') {
|
||||
if (device.link_open === 'new_tab') {
|
||||
window.open(device.link, '_blank');
|
||||
@@ -68,15 +74,21 @@
|
||||
}
|
||||
|
||||
function shutdown() {
|
||||
countdown(Date.now(), 'shutdown');
|
||||
device.status = 'pending';
|
||||
|
||||
fetch(`${backendUrl}api/upsnap/shutdown/${device.id}`, {
|
||||
headers: {
|
||||
Authorization: $pocketbase.authStore.token
|
||||
}
|
||||
})
|
||||
.then((resp) => resp.json())
|
||||
.then((data) => {
|
||||
.then(async (data) => {
|
||||
if (data.status !== 200) {
|
||||
device.status = 'online';
|
||||
return;
|
||||
}
|
||||
device = data as Device;
|
||||
countdown(Date.parse(device.updated), 'shutdown');
|
||||
})
|
||||
.catch((err) => {
|
||||
toast.error(err.message);
|
||||
@@ -84,33 +96,26 @@
|
||||
}
|
||||
|
||||
function countdown(updated: number, action: 'wake' | 'shutdown') {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
timeout = action === 'wake' ? device.wake_timeout : device.shutdown_timeout;
|
||||
if (timeout <= 0) {
|
||||
timeout = 120;
|
||||
}
|
||||
timeout = action === 'wake' ? device.wake_timeout : device.shutdown_timeout;
|
||||
if (timeout <= 0) {
|
||||
timeout = 120;
|
||||
}
|
||||
|
||||
const end = updated + timeout * 1000;
|
||||
const end = updated + timeout * 1000;
|
||||
|
||||
if (interval) {
|
||||
clearInterval(interval);
|
||||
interval = 0;
|
||||
}
|
||||
if (interval) {
|
||||
clearInterval(interval);
|
||||
interval = 0;
|
||||
}
|
||||
|
||||
interval = setInterval(() => {
|
||||
timeout = Math.round((end - Date.now()) / 1000);
|
||||
interval = setInterval(() => {
|
||||
timeout = Math.round((end - Date.now()) / 1000);
|
||||
|
||||
if (timeout <= 0 || device.status !== 'pending') {
|
||||
clearInterval(interval);
|
||||
interval = 0;
|
||||
resolve(interval);
|
||||
}
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
if (timeout <= 0 || device.status !== 'pending') {
|
||||
clearInterval(interval);
|
||||
interval = 0;
|
||||
}
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function handleClick() {
|
||||
|
||||
@@ -59,17 +59,27 @@
|
||||
await $pocketbase
|
||||
.collection('_superusers')
|
||||
.authRefresh()
|
||||
.catch(() => {
|
||||
$pocketbase.authStore.clear();
|
||||
goto('/login');
|
||||
.catch((err) => {
|
||||
// clear the store only on invalidated/expired token
|
||||
const status = err?.status << 0;
|
||||
if (status == 401 || status == 403) {
|
||||
$pocketbase.authStore.clear();
|
||||
goto('/login');
|
||||
} else {
|
||||
console.log('NOT CLEARED');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
await $pocketbase
|
||||
.collection('users')
|
||||
.authRefresh()
|
||||
.catch(() => {
|
||||
$pocketbase.authStore.clear();
|
||||
goto('/login');
|
||||
.catch((err) => {
|
||||
// clear the store only on invalidated/expired token
|
||||
const status = err?.status << 0;
|
||||
if (status == 401 || status == 403) {
|
||||
$pocketbase.authStore.clear();
|
||||
goto('/login');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
localStorage.setItem('orderByGroups', String(orderByGroups));
|
||||
}
|
||||
|
||||
onMount(() => {});
|
||||
const filteredDevices = () =>
|
||||
devices.filter(
|
||||
(dev) =>
|
||||
|
||||
Reference in New Issue
Block a user