feat: restart to apply update, privileged helper, rollback

This commit is contained in:
fsylvain committed 2026-10-01 21:36:40 +02:00
1 parent 70460e4170
commit 54e8fd5fed
63 files changed
+8635 -164

No files matched your search

+36 -2
View File
@@ -21,7 +21,9 @@ export interface UpdateProgress {
total_bytes: number
}
export type UpdateErrorKind = 'download' | 'verification'
export type UpdateErrorKind = 'download' | 'verification' | 'rolled_back' | 'install'
export type RestartKind = 'update' | 'restart'
export interface UpdateStatus {
current: string
@@ -35,6 +37,7 @@ export interface UpdateStatus {
progress: UpdateProgress | null
error: UpdateErrorKind | null
started_at: string | null
finished_at: string | null
}
export function useUpdate() {
@@ -52,5 +55,36 @@ export function useUpdate() {
return request<UpdateStatus>('/v1/system/update/download', { method: 'POST' })
}
return { getUpdateStatus, checkForUpdate, startUpdateDownload }
function requestRestart(kind: RestartKind): Promise<UpdateStatus> {
return request<UpdateStatus>('/v1/system/update/restart', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ kind }),
})
}
function pollUpdateStatus(): Promise<UpdateStatus> {
return request<UpdateStatus>('/v1/system/update', {
onUnauthorized: 'passthrough',
onForbidden: 'passthrough',
})
}
async function isSiteUp(): Promise<boolean> {
try {
const response = await fetch('/healthz', { cache: 'no-store' })
return response.status === 200
} catch {
return false
}
}
return {
getUpdateStatus,
checkForUpdate,
startUpdateDownload,
requestRestart,
pollUpdateStatus,
isSiteUp,
}
}