feat: update button (download, verify, stage)

This commit is contained in:
fsylvain committed 2026-10-01 18:13:45 +02:00
1 parent 834493a4f5
commit 70460e4170
41 files changed
+5345 -97

No files matched your search

+30
View File
@@ -13,6 +13,10 @@ export const NOTE_ITEMS = [
export const STATUS_PATH = '/v1/system/update'
export const CHECK_PATH = '/v1/system/update/check'
export const DOWNLOAD_PATH = '/v1/system/update/download'
export const BOARD_TOTAL_BYTES = 27262976
export const BOARD_DONE_BYTES = 11534336
export function hoursAgo(hours: number) {
return new Date(Date.now() - hours * 60 * 60 * 1000).toISOString()
@@ -64,3 +68,29 @@ export function findButton(label: string, root: ParentNode = document.body) {
(button) => button.textContent?.trim() === label,
)
}
export function startable(overrides: Partial<UpdateStatus> = {}): UpdateStatus {
return newerAvailable({ can_apply: true, ...overrides })
}
export function downloading(percent = 42): UpdateStatus {
const downloaded =
percent === 42 ? BOARD_DONE_BYTES : Math.floor((BOARD_TOTAL_BYTES * percent) / 100)
return startable({
state: 'downloading',
started_at: '2026-09-30T09:51:00Z',
progress: { percent, downloaded_bytes: downloaded, total_bytes: BOARD_TOTAL_BYTES },
})
}
export function verifying(): UpdateStatus {
return startable({ state: 'verifying', started_at: '2026-09-30T09:51:00Z' })
}
export function ready(): UpdateStatus {
return startable({ state: 'ready', started_at: '2026-09-30T09:51:00Z' })
}
export function failedWith(error: 'download' | 'verification'): UpdateStatus {
return startable({ state: 'failed', error, started_at: '2026-09-30T09:51:00Z' })
}