systemUpdate.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import type { JsonValue } from '@shared/types'
  2. import { apiRequest } from './client'
  3. export interface ReleaseManifest {
  4. schemaVersion: 1
  5. releaseVersion: string
  6. webVersion: string
  7. pluginVersion: string
  8. gitTag: string
  9. }
  10. export type UpdateJobState =
  11. | 'queued'
  12. | 'downloading'
  13. | 'building'
  14. | 'installing'
  15. | 'restarting'
  16. | 'verifying'
  17. | 'rolling_back'
  18. | 'succeeded'
  19. | 'failed'
  20. | 'rolled_back'
  21. export interface UpdateJob {
  22. id: string
  23. operation: 'update' | 'rollback'
  24. state: UpdateJobState
  25. message: string
  26. createdAt: string
  27. updatedAt: string
  28. target?: ReleaseManifest
  29. error?: string
  30. }
  31. export interface SystemUpdateStatus {
  32. current: ReleaseManifest
  33. installedPluginVersion?: string
  34. versionsMatch: boolean
  35. installationMode: 'source' | 'release'
  36. latest?: ReleaseManifest
  37. updateAvailable: boolean
  38. supported: boolean
  39. unsupportedReason?: string
  40. canRollback: boolean
  41. job?: UpdateJob
  42. }
  43. export function systemUpdateStatus(): Promise<SystemUpdateStatus> {
  44. return apiRequest('/api/app/system/update/status')
  45. }
  46. export function checkSystemUpdate(): Promise<SystemUpdateStatus> {
  47. return apiRequest('/api/app/system/update/check', { method: 'POST', body: {}, timeoutMs: 90_000 })
  48. }
  49. export function applySystemUpdate(targetVersion: string): Promise<UpdateJob> {
  50. return apiRequest('/api/app/system/update/apply', {
  51. method: 'POST',
  52. body: { targetVersion } as JsonValue,
  53. timeoutMs: 90_000,
  54. })
  55. }
  56. export function systemUpdateJob(jobID: string): Promise<UpdateJob> {
  57. return apiRequest(`/api/app/system/update/jobs/${encodeURIComponent(jobID)}`, {
  58. notifyUnauthorized: false,
  59. timeoutMs: 5_000,
  60. })
  61. }
  62. export function rollbackSystemUpdate(): Promise<UpdateJob> {
  63. return apiRequest('/api/app/system/update/rollback', { method: 'POST', body: {} })
  64. }
  65. export function reconcileYaoyaoPlugin(): Promise<{
  66. ok: boolean
  67. updated: boolean
  68. installedPluginVersion?: string
  69. expectedPluginVersion: string
  70. }> {
  71. return apiRequest('/api/app/plugins/yaoyao/reconcile', {
  72. method: 'POST',
  73. body: {},
  74. timeoutMs: 90_000,
  75. })
  76. }