mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-11-02 19:02:31 +00:00
fix: revalidate externally changed LXC state
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { fetchApi } from "./api-config"
|
||||
|
||||
interface UpdateObservation {
|
||||
last_check?: string | null
|
||||
stale?: boolean
|
||||
stale_after_seconds?: number
|
||||
}
|
||||
|
||||
export function isLxcUpdateStale(observation?: UpdateObservation, now = Date.now()): boolean {
|
||||
if (!observation || observation.stale === true) return true
|
||||
const checked = Date.parse(observation.last_check || "")
|
||||
const age = now - checked
|
||||
const limit = (observation.stale_after_seconds ?? 86400) * 1000
|
||||
return !Number.isFinite(checked) || age < 0 || age >= limit
|
||||
}
|
||||
|
||||
// Called only by the OS section's explicit button. Uses installed package
|
||||
// state and existing indexes; fetching this never upgrades or refreshes APT.
|
||||
export function checkLxcUpdates<T>(vmid: number): Promise<T> {
|
||||
return fetchApi<T>(`/api/vms/${vmid}/updates/check`, { method: "POST" })
|
||||
}
|
||||
Reference in New Issue
Block a user