mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-11-02 10:52:22 +00:00
fix: separate LXC package checks from installation
This commit is contained in:
@@ -4,6 +4,17 @@ interface UpdateObservation {
|
||||
last_check?: string | null
|
||||
stale?: boolean
|
||||
stale_after_seconds?: number
|
||||
available?: boolean
|
||||
count?: number | null
|
||||
error?: string | null
|
||||
}
|
||||
|
||||
export function getLxcOsUpdateState(observation?: UpdateObservation, now = Date.now()): "unknown" | "pending" | "current" {
|
||||
if (isLxcUpdateStale(observation, now) || observation?.error
|
||||
|| typeof observation?.available !== "boolean"
|
||||
|| !Number.isInteger(observation.count) || (observation.count ?? -1) < 0
|
||||
|| observation.available !== ((observation.count ?? 0) > 0)) return "unknown"
|
||||
return observation.available ? "pending" : "current"
|
||||
}
|
||||
|
||||
export function isLxcUpdateStale(observation?: UpdateObservation, now = Date.now()): boolean {
|
||||
@@ -19,3 +30,18 @@ export function isLxcUpdateStale(observation?: UpdateObservation, now = Date.now
|
||||
export function checkLxcUpdates<T>(vmid: number): Promise<T> {
|
||||
return fetchApi<T>(`/api/vms/${vmid}/updates/check`, { method: "POST" })
|
||||
}
|
||||
|
||||
// Separate explicit action: refresh indexes, check only, restore stopped CT.
|
||||
// The backend owns the job even if the browser closes or navigates away.
|
||||
export async function refreshCheckLxcUpdates<T>(vmid: number): Promise<T> {
|
||||
const job = await fetchApi<{ job_id: string }>(`/api/vms/${vmid}/updates/refresh-check`, { method: "POST" })
|
||||
const deadline = Date.now() + 8 * 60_000
|
||||
while (Date.now() < deadline) {
|
||||
const result = await fetchApi<{ state: string; error?: string; update_check?: T }>(
|
||||
`/api/vms/${vmid}/updates/refresh-check/${job.job_id}`)
|
||||
if (result.state === "failed") throw new Error("osStatusUnavailable")
|
||||
if (result.state === "complete") return result.update_check as T
|
||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
||||
}
|
||||
throw new Error("checkStillRunning")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// Use the dashboard's existing update colors for every executable action.
|
||||
// Version availability remains separate from action styling and enablement.
|
||||
export function getUpdateActionButtonClass(hasUpdate: boolean, isCurrent: boolean): string {
|
||||
return !hasUpdate && isCurrent
|
||||
? "bg-green-500/10 hover:bg-green-500/20 border border-green-500/30 text-green-400 hover:text-green-300"
|
||||
: "bg-purple-600/15 hover:bg-purple-600/25 border border-purple-500/40 text-purple-300 hover:text-purple-200"
|
||||
}
|
||||
Reference in New Issue
Block a user