mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 04:01:58 +00:00
* add disk repair actions to diagnostic ui and server menu * only display repair disk button when activated * fix typo * add repairDrive fn with restart to diagnostic ui * fix copy * add alert before repairing disk in diagnostic ui * fix repair disk message spacing and hidden display * fix version comparisons and enable dismissable refresh modal * eager load medkit and fix storefront to outline icon
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import { Injectable } from '@angular/core'
|
|
import { IonicSafeString } from '@ionic/core'
|
|
import { ApiService } from 'src/app/services/api/embassy-api.service'
|
|
import {
|
|
BackupTarget,
|
|
CifsBackupTarget,
|
|
DiskBackupTarget,
|
|
} from 'src/app/services/api/api.types'
|
|
import { MappedBackupTarget } from 'src/app/types/mapped-backup-target'
|
|
import { getErrorMessage, Emver } from '@start9labs/shared'
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class BackupService {
|
|
cifs: MappedBackupTarget<CifsBackupTarget>[]
|
|
drives: MappedBackupTarget<DiskBackupTarget>[]
|
|
loading = true
|
|
loadingError: string | IonicSafeString
|
|
|
|
constructor(
|
|
private readonly embassyApi: ApiService,
|
|
private readonly emver: Emver,
|
|
) {}
|
|
|
|
async getBackupTargets(): Promise<void> {
|
|
this.loading = true
|
|
|
|
try {
|
|
const targets = await this.embassyApi.getBackupTargets({})
|
|
// cifs
|
|
this.cifs = Object.entries(targets)
|
|
.filter(([_, target]) => target.type === 'cifs')
|
|
.map(([id, cifs]) => {
|
|
return {
|
|
id,
|
|
hasValidBackup: this.hasValidBackup(cifs),
|
|
entry: cifs as CifsBackupTarget,
|
|
}
|
|
})
|
|
// drives
|
|
this.drives = Object.entries(targets)
|
|
.filter(([_, target]) => target.type === 'disk')
|
|
.map(([id, drive]) => {
|
|
return {
|
|
id,
|
|
hasValidBackup: this.hasValidBackup(drive),
|
|
entry: drive as DiskBackupTarget,
|
|
}
|
|
})
|
|
} catch (e) {
|
|
this.loadingError = getErrorMessage(e)
|
|
} finally {
|
|
this.loading = false
|
|
}
|
|
}
|
|
|
|
hasValidBackup(target: BackupTarget): boolean {
|
|
return this.emver.compare(target['embassy-os']?.version, '0.3.0') !== -1
|
|
}
|
|
}
|