mirror of
https://github.com/fankes/beszel.git
synced 2025-10-19 09:49:28 +08:00
refactor: updateSystemList function
This commit is contained in:
@@ -42,33 +42,28 @@ const verifyAuth = () => {
|
||||
})
|
||||
}
|
||||
|
||||
let isFetchingSystems = false;
|
||||
export const updateSystemList = (() => {
|
||||
let isFetchingSystems = false
|
||||
return async () => {
|
||||
if (isFetchingSystems) {
|
||||
return
|
||||
}
|
||||
isFetchingSystems = true
|
||||
try {
|
||||
const records = await pb
|
||||
.collection<SystemRecord>("systems")
|
||||
.getFullList({ sort: "+name", fields: "id,name,host,info,status" })
|
||||
|
||||
export const updateSystemList = async () => {
|
||||
|
||||
if (isFetchingSystems) return;
|
||||
isFetchingSystems = true
|
||||
|
||||
try {
|
||||
const records = await pb
|
||||
.collection<SystemRecord>("systems")
|
||||
.getFullList({ sort: "+name", fields: "id,name,host,info,status" });
|
||||
|
||||
if (records.length) {
|
||||
$systems.set(records);
|
||||
} else {
|
||||
verifyAuth();
|
||||
}
|
||||
} catch (e: any) {
|
||||
// Suppressing pocketbase auto-cancellation error
|
||||
|
||||
if (e.isAbort || e.status === 0) {
|
||||
return;
|
||||
}
|
||||
} finally {
|
||||
isFetchingSystems = false
|
||||
if (records.length) {
|
||||
$systems.set(records)
|
||||
} else {
|
||||
verifyAuth()
|
||||
}
|
||||
} finally {
|
||||
isFetchingSystems = false
|
||||
}
|
||||
}
|
||||
};
|
||||
})()
|
||||
|
||||
|
||||
export const updateAlerts = () => {
|
||||
|
Reference in New Issue
Block a user