mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 04:01:58 +00:00
status info change
This commit is contained in:
committed by
Aiden McClelland
parent
4aafacfa8b
commit
d3592f068e
@@ -290,16 +290,18 @@ export class AppComponent {
|
||||
}
|
||||
|
||||
private watchStatus (): Subscription {
|
||||
return this.patch.watch$('server-info', 'status').subscribe(status => {
|
||||
if (status === ServerStatus.Updated && !this.updateToast) {
|
||||
this.presentToastUpdated()
|
||||
}
|
||||
})
|
||||
return this.patch
|
||||
.watch$('server-info', 'status-info', 'updated')
|
||||
.subscribe(isUpdated => {
|
||||
if (isUpdated && !this.updateToast) {
|
||||
this.presentToastUpdated()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private watchUpdateProgress (): Subscription {
|
||||
return this.patch
|
||||
.watch$('server-info', 'update-progress')
|
||||
.watch$('server-info', 'status-info', 'update-progress')
|
||||
.subscribe(progress => {
|
||||
this.osUpdateProgress = progress
|
||||
})
|
||||
@@ -454,9 +456,7 @@ export class AppComponent {
|
||||
await loader.present()
|
||||
|
||||
try {
|
||||
await this.embassyApi.restartServer({
|
||||
'marketplace-url': this.config.marketplace.url,
|
||||
})
|
||||
await this.embassyApi.restartServer({})
|
||||
} catch (e) {
|
||||
this.errToast.present(e)
|
||||
} finally {
|
||||
|
||||
@@ -1,14 +1,28 @@
|
||||
import { Component } from '@angular/core'
|
||||
import { LoadingController, ModalController, NavController } from '@ionic/angular'
|
||||
import {
|
||||
LoadingController,
|
||||
ModalController,
|
||||
NavController,
|
||||
} from '@ionic/angular'
|
||||
import { ApiService } from 'src/app/services/api/embassy-api.service'
|
||||
import { GenericInputComponent, GenericInputOptions } from 'src/app/modals/generic-input/generic-input.component'
|
||||
import {
|
||||
GenericInputComponent,
|
||||
GenericInputOptions,
|
||||
} from 'src/app/modals/generic-input/generic-input.component'
|
||||
import { PatchDbService } from 'src/app/services/patch-db/patch-db.service'
|
||||
import { PackageDataEntry, PackageMainStatus, ServerStatus } from 'src/app/services/patch-db/data-model'
|
||||
import {
|
||||
PackageDataEntry,
|
||||
PackageMainStatus,
|
||||
ServerStatus,
|
||||
} from 'src/app/services/patch-db/data-model'
|
||||
import { Subscription } from 'rxjs'
|
||||
import { take } from 'rxjs/operators'
|
||||
import { MappedBackupTarget } from 'src/app/util/misc.util'
|
||||
import * as argon2 from '@start9labs/argon2'
|
||||
import { CifsBackupTarget, DiskBackupTarget } from 'src/app/services/api/api.types'
|
||||
import {
|
||||
CifsBackupTarget,
|
||||
DiskBackupTarget,
|
||||
} from 'src/app/services/api/api.types'
|
||||
|
||||
@Component({
|
||||
selector: 'server-backup',
|
||||
@@ -20,20 +34,21 @@ export class ServerBackupPage {
|
||||
pkgs: PkgInfo[] = []
|
||||
subs: Subscription[]
|
||||
|
||||
constructor (
|
||||
constructor(
|
||||
private readonly loadingCtrl: LoadingController,
|
||||
private readonly modalCtrl: ModalController,
|
||||
private readonly embassyApi: ApiService,
|
||||
private readonly patch: PatchDbService,
|
||||
private readonly navCtrl: NavController,
|
||||
) { }
|
||||
) {}
|
||||
|
||||
ngOnInit () {
|
||||
ngOnInit() {
|
||||
this.subs = [
|
||||
this.patch.watch$('server-info', 'status')
|
||||
this.patch
|
||||
.watch$('server-info', 'status-info', 'backing-up')
|
||||
.pipe()
|
||||
.subscribe(status => {
|
||||
if (status === ServerStatus.BackingUp) {
|
||||
.subscribe(isBackingUp => {
|
||||
if (isBackingUp) {
|
||||
if (!this.backingUp) {
|
||||
this.backingUp = true
|
||||
this.subscribeToBackup()
|
||||
@@ -49,15 +64,20 @@ export class ServerBackupPage {
|
||||
]
|
||||
}
|
||||
|
||||
ngOnDestroy () {
|
||||
ngOnDestroy() {
|
||||
this.subs.forEach(sub => sub.unsubscribe())
|
||||
this.pkgs.forEach(pkg => pkg.sub.unsubscribe())
|
||||
}
|
||||
|
||||
async presentModalPassword (target: MappedBackupTarget<CifsBackupTarget | DiskBackupTarget>): Promise<void> {
|
||||
let message = 'Enter your master password to create an encrypted backup of your Embassy and all its services.'
|
||||
async presentModalPassword(
|
||||
target: MappedBackupTarget<CifsBackupTarget | DiskBackupTarget>,
|
||||
): Promise<void> {
|
||||
let message =
|
||||
'Enter your master password to create an encrypted backup of your Embassy and all its services.'
|
||||
if (!target.hasValidBackup) {
|
||||
message = message + ' Since this is a fresh backup, it could take a while. Future backups will likely be much faster.'
|
||||
message =
|
||||
message +
|
||||
' Since this is a fresh backup, it could take a while. Future backups will likely be much faster.'
|
||||
}
|
||||
|
||||
const options: GenericInputOptions = {
|
||||
@@ -79,7 +99,11 @@ export class ServerBackupPage {
|
||||
await m.present()
|
||||
}
|
||||
|
||||
private async test (target: MappedBackupTarget<CifsBackupTarget | DiskBackupTarget>, password: string, oldPassword?: string): Promise<void> {
|
||||
private async test(
|
||||
target: MappedBackupTarget<CifsBackupTarget | DiskBackupTarget>,
|
||||
password: string,
|
||||
oldPassword?: string,
|
||||
): Promise<void> {
|
||||
const passwordHash = this.patch.getData()['server-info']['password-hash']
|
||||
argon2.verify(passwordHash, password)
|
||||
|
||||
@@ -87,7 +111,10 @@ export class ServerBackupPage {
|
||||
await this.createBackup(target.id, password)
|
||||
} else {
|
||||
try {
|
||||
argon2.verify(target.entry['embassy-os']['password-hash'], oldPassword || password)
|
||||
argon2.verify(
|
||||
target.entry['embassy-os']['password-hash'],
|
||||
oldPassword || password,
|
||||
)
|
||||
await this.createBackup(target.id, password)
|
||||
} catch (e) {
|
||||
if (oldPassword) {
|
||||
@@ -99,15 +126,20 @@ export class ServerBackupPage {
|
||||
}
|
||||
}
|
||||
|
||||
private async presentModalOldPassword (target: MappedBackupTarget<CifsBackupTarget | DiskBackupTarget>, password: string): Promise<void> {
|
||||
private async presentModalOldPassword(
|
||||
target: MappedBackupTarget<CifsBackupTarget | DiskBackupTarget>,
|
||||
password: string,
|
||||
): Promise<void> {
|
||||
const options: GenericInputOptions = {
|
||||
title: 'Original Password Needed',
|
||||
message: 'This backup was created with a different password. Enter the ORIGINAL password that was used to encrypt this backup.',
|
||||
message:
|
||||
'This backup was created with a different password. Enter the ORIGINAL password that was used to encrypt this backup.',
|
||||
label: 'Original Password',
|
||||
placeholder: 'Enter original password',
|
||||
useMask: true,
|
||||
buttonText: 'Create Backup',
|
||||
submitFn: (oldPassword: string) => this.test(target, password, oldPassword),
|
||||
submitFn: (oldPassword: string) =>
|
||||
this.test(target, password, oldPassword),
|
||||
}
|
||||
|
||||
const m = await this.modalCtrl.create({
|
||||
@@ -119,7 +151,11 @@ export class ServerBackupPage {
|
||||
await m.present()
|
||||
}
|
||||
|
||||
private async createBackup (id: string, password: string, oldPassword?: string): Promise<void> {
|
||||
private async createBackup(
|
||||
id: string,
|
||||
password: string,
|
||||
oldPassword?: string,
|
||||
): Promise<void> {
|
||||
const loader = await this.loadingCtrl.create({
|
||||
spinner: 'lines',
|
||||
message: 'Beginning backup...',
|
||||
@@ -138,43 +174,56 @@ export class ServerBackupPage {
|
||||
}
|
||||
}
|
||||
|
||||
private subscribeToBackup () {
|
||||
this.patch.watch$('package-data')
|
||||
.pipe(
|
||||
take(1),
|
||||
)
|
||||
.subscribe(pkgs => {
|
||||
const pkgArr = Object.keys(pkgs).sort().map(key => pkgs[key])
|
||||
const activeIndex = pkgArr.findIndex(pkg => pkg.installed.status.main.status === PackageMainStatus.BackingUp)
|
||||
private subscribeToBackup() {
|
||||
this.patch
|
||||
.watch$('package-data')
|
||||
.pipe(take(1))
|
||||
.subscribe(pkgs => {
|
||||
const pkgArr = Object.keys(pkgs)
|
||||
.sort()
|
||||
.map(key => pkgs[key])
|
||||
const activeIndex = pkgArr.findIndex(
|
||||
pkg =>
|
||||
pkg.installed.status.main.status === PackageMainStatus.BackingUp,
|
||||
)
|
||||
|
||||
this.pkgs = pkgArr.map((pkg, i) => {
|
||||
const pkgInfo = {
|
||||
entry: pkg,
|
||||
active: i === activeIndex,
|
||||
complete: i < activeIndex,
|
||||
sub: null,
|
||||
}
|
||||
return pkgInfo
|
||||
})
|
||||
|
||||
// subscribe to pkg
|
||||
this.pkgs.forEach(pkg => {
|
||||
pkg.sub = this.patch.watch$('package-data', pkg.entry.manifest.id, 'installed', 'status', 'main', 'status').subscribe(status => {
|
||||
if (status === PackageMainStatus.BackingUp) {
|
||||
pkg.active = true
|
||||
} else if (pkg.active) {
|
||||
pkg.active = false
|
||||
pkg.complete = true
|
||||
this.pkgs = pkgArr.map((pkg, i) => {
|
||||
const pkgInfo = {
|
||||
entry: pkg,
|
||||
active: i === activeIndex,
|
||||
complete: i < activeIndex,
|
||||
sub: null,
|
||||
}
|
||||
return pkgInfo
|
||||
})
|
||||
|
||||
// subscribe to pkg
|
||||
this.pkgs.forEach(pkg => {
|
||||
pkg.sub = this.patch
|
||||
.watch$(
|
||||
'package-data',
|
||||
pkg.entry.manifest.id,
|
||||
'installed',
|
||||
'status',
|
||||
'main',
|
||||
'status',
|
||||
)
|
||||
.subscribe(status => {
|
||||
if (status === PackageMainStatus.BackingUp) {
|
||||
pkg.active = true
|
||||
} else if (pkg.active) {
|
||||
pkg.active = false
|
||||
pkg.complete = true
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
interface PkgInfo {
|
||||
entry: PackageDataEntry,
|
||||
entry: PackageDataEntry
|
||||
active: boolean
|
||||
complete: boolean,
|
||||
sub: Subscription,
|
||||
complete: boolean
|
||||
sub: Subscription
|
||||
}
|
||||
|
||||
@@ -41,16 +41,18 @@
|
||||
|
||||
<!-- "Create Backup" button only -->
|
||||
<p *ngIf="button.title === 'Create Backup'">
|
||||
<ng-container *ngIf="patch.data['server-info'].status as status">
|
||||
<ng-container
|
||||
*ngIf="patch.data['server-info']['status-info'] as statusInfo"
|
||||
>
|
||||
<ion-text
|
||||
color="warning"
|
||||
*ngIf="status === ServerStatus.Running"
|
||||
*ngIf="!statusInfo['backing-up'] && !statusInfo['update-progress']"
|
||||
>
|
||||
Last Backup: {{ patch.data['server-info']['last-backup'] ?
|
||||
(patch.data['server-info']['last-backup'] | date: 'short') :
|
||||
'never' }}
|
||||
</ion-text>
|
||||
<span *ngIf="status === ServerStatus.BackingUp" class="inline">
|
||||
<span *ngIf="!!statusInfo['update-progress']" class="inline">
|
||||
<ion-spinner
|
||||
color="success"
|
||||
style="height: 12px; width: 12px; margin-right: 6px"
|
||||
|
||||
@@ -17,7 +17,6 @@ import { WizardBaker } from 'src/app/components/install-wizard/prebaked-wizards'
|
||||
import { wizardModal } from 'src/app/components/install-wizard/install-wizard.component'
|
||||
import { exists, isEmptyObject } from 'src/app/util/misc.util'
|
||||
import { EOSService } from 'src/app/services/eos.service'
|
||||
import { ConfigService } from 'src/app/services/config.service'
|
||||
|
||||
@Component({
|
||||
selector: 'server-show',
|
||||
@@ -37,7 +36,6 @@ export class ServerShowPage {
|
||||
private readonly embassyApi: ApiService,
|
||||
private readonly navCtrl: NavController,
|
||||
private readonly route: ActivatedRoute,
|
||||
private readonly config: ConfigService,
|
||||
public readonly eosService: EOSService,
|
||||
public readonly patch: PatchDbService,
|
||||
) {}
|
||||
@@ -236,11 +234,9 @@ export class ServerShowPage {
|
||||
this.navCtrl.navigateForward(['restore'], { relativeTo: this.route }),
|
||||
detail: true,
|
||||
disabled: this.patch
|
||||
.watch$('server-info', 'status')
|
||||
.watch$('server-info', 'status-info')
|
||||
.pipe(
|
||||
map(status =>
|
||||
[ServerStatus.Updated, ServerStatus.BackingUp].includes(status),
|
||||
),
|
||||
map(status => status['backing-up'] || !!status['update-progress']),
|
||||
),
|
||||
},
|
||||
],
|
||||
|
||||
@@ -25,22 +25,22 @@ export class MockApiService extends ApiService {
|
||||
private readonly revertTime = 4000
|
||||
sequence: number
|
||||
|
||||
constructor(private readonly bootstrapper: LocalStorageBootstrap) {
|
||||
constructor (private readonly bootstrapper: LocalStorageBootstrap) {
|
||||
super()
|
||||
}
|
||||
|
||||
async getStatic(url: string): Promise<string> {
|
||||
async getStatic (url: string): Promise<string> {
|
||||
await pauseFor(2000)
|
||||
return markdown
|
||||
}
|
||||
|
||||
// db
|
||||
|
||||
async getRevisions(since: number): Promise<RR.GetRevisionsRes> {
|
||||
async getRevisions (since: number): Promise<RR.GetRevisionsRes> {
|
||||
return this.getDump()
|
||||
}
|
||||
|
||||
async getDump(): Promise<RR.GetDumpRes> {
|
||||
async getDump (): Promise<RR.GetDumpRes> {
|
||||
const cache = await this.bootstrapper.init()
|
||||
return {
|
||||
id: cache.sequence,
|
||||
@@ -49,7 +49,7 @@ export class MockApiService extends ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
async setDbValueRaw(params: RR.SetDBValueReq): Promise<RR.SetDBValueRes> {
|
||||
async setDbValueRaw (params: RR.SetDBValueReq): Promise<RR.SetDBValueRes> {
|
||||
await pauseFor(2000)
|
||||
const patch = [
|
||||
{
|
||||
@@ -63,7 +63,7 @@ export class MockApiService extends ApiService {
|
||||
|
||||
// auth
|
||||
|
||||
async login(params: RR.LoginReq): Promise<RR.loginRes> {
|
||||
async login (params: RR.LoginReq): Promise<RR.loginRes> {
|
||||
await pauseFor(2000)
|
||||
|
||||
setTimeout(() => {
|
||||
@@ -73,24 +73,24 @@ export class MockApiService extends ApiService {
|
||||
return null
|
||||
}
|
||||
|
||||
async logout(params: RR.LogoutReq): Promise<RR.LogoutRes> {
|
||||
async logout (params: RR.LogoutReq): Promise<RR.LogoutRes> {
|
||||
await pauseFor(2000)
|
||||
return null
|
||||
}
|
||||
|
||||
async getSessions(params: RR.GetSessionsReq): Promise<RR.GetSessionsRes> {
|
||||
async getSessions (params: RR.GetSessionsReq): Promise<RR.GetSessionsRes> {
|
||||
await pauseFor(2000)
|
||||
return Mock.Sessions
|
||||
}
|
||||
|
||||
async killSessions(params: RR.KillSessionsReq): Promise<RR.KillSessionsRes> {
|
||||
async killSessions (params: RR.KillSessionsReq): Promise<RR.KillSessionsRes> {
|
||||
await pauseFor(2000)
|
||||
return null
|
||||
}
|
||||
|
||||
// server
|
||||
|
||||
async getServerLogs(
|
||||
async getServerLogs (
|
||||
params: RR.GetServerLogsReq,
|
||||
): Promise<RR.GetServerLogsRes> {
|
||||
await pauseFor(2000)
|
||||
@@ -112,21 +112,21 @@ export class MockApiService extends ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
async getServerMetrics(
|
||||
async getServerMetrics (
|
||||
params: RR.GetServerMetricsReq,
|
||||
): Promise<RR.GetServerMetricsRes> {
|
||||
await pauseFor(2000)
|
||||
return Mock.getServerMetrics()
|
||||
}
|
||||
|
||||
async getPkgMetrics(
|
||||
async getPkgMetrics (
|
||||
params: RR.GetServerMetricsReq,
|
||||
): Promise<RR.GetPackageMetricsRes> {
|
||||
await pauseFor(2000)
|
||||
return Mock.getAppMetrics()
|
||||
}
|
||||
|
||||
async updateServerRaw(
|
||||
async updateServerRaw (
|
||||
params: RR.UpdateServerReq,
|
||||
): Promise<RR.UpdateServerRes> {
|
||||
await pauseFor(2000)
|
||||
@@ -142,7 +142,7 @@ export class MockApiService extends ApiService {
|
||||
const patch = [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: '/server-info/update-progress',
|
||||
path: '/server-info/status-info/update-progress',
|
||||
value: initialProgress,
|
||||
},
|
||||
]
|
||||
@@ -150,21 +150,21 @@ export class MockApiService extends ApiService {
|
||||
return this.withRevision(patch, 'updating')
|
||||
}
|
||||
|
||||
async restartServer(
|
||||
async restartServer (
|
||||
params: RR.RestartServerReq,
|
||||
): Promise<RR.RestartServerRes> {
|
||||
await pauseFor(2000)
|
||||
return null
|
||||
}
|
||||
|
||||
async shutdownServer(
|
||||
async shutdownServer (
|
||||
params: RR.ShutdownServerReq,
|
||||
): Promise<RR.ShutdownServerRes> {
|
||||
await pauseFor(2000)
|
||||
return null
|
||||
}
|
||||
|
||||
async systemRebuild(
|
||||
async systemRebuild (
|
||||
params: RR.RestartServerReq,
|
||||
): Promise<RR.RestartServerRes> {
|
||||
await pauseFor(2000)
|
||||
@@ -173,7 +173,7 @@ export class MockApiService extends ApiService {
|
||||
|
||||
// marketplace URLs
|
||||
|
||||
async marketplaceProxy(path: string, params: {}, url: string): Promise<any> {
|
||||
async marketplaceProxy (path: string, params: {}, url: string): Promise<any> {
|
||||
await pauseFor(2000)
|
||||
|
||||
if (path === '/package/v0/info') {
|
||||
@@ -196,7 +196,7 @@ export class MockApiService extends ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
async getEos(
|
||||
async getEos (
|
||||
params: RR.GetMarketplaceEOSReq,
|
||||
): Promise<RR.GetMarketplaceEOSRes> {
|
||||
await pauseFor(2000)
|
||||
@@ -211,7 +211,7 @@ export class MockApiService extends ApiService {
|
||||
|
||||
// notification
|
||||
|
||||
async getNotificationsRaw(
|
||||
async getNotificationsRaw (
|
||||
params: RR.GetNotificationsReq,
|
||||
): Promise<RR.GetNotificationsRes> {
|
||||
await pauseFor(2000)
|
||||
@@ -226,14 +226,14 @@ export class MockApiService extends ApiService {
|
||||
return this.withRevision(patch, Mock.Notifications)
|
||||
}
|
||||
|
||||
async deleteNotification(
|
||||
async deleteNotification (
|
||||
params: RR.DeleteNotificationReq,
|
||||
): Promise<RR.DeleteNotificationRes> {
|
||||
await pauseFor(2000)
|
||||
return null
|
||||
}
|
||||
|
||||
async deleteAllNotifications(
|
||||
async deleteAllNotifications (
|
||||
params: RR.DeleteAllNotificationsReq,
|
||||
): Promise<RR.DeleteAllNotificationsRes> {
|
||||
await pauseFor(2000)
|
||||
@@ -242,60 +242,60 @@ export class MockApiService extends ApiService {
|
||||
|
||||
// wifi
|
||||
|
||||
async getWifi(params: RR.GetWifiReq): Promise<RR.GetWifiRes> {
|
||||
async getWifi (params: RR.GetWifiReq): Promise<RR.GetWifiRes> {
|
||||
await pauseFor(2000)
|
||||
return Mock.Wifi
|
||||
}
|
||||
|
||||
async setWifiCountry(
|
||||
async setWifiCountry (
|
||||
params: RR.SetWifiCountryReq,
|
||||
): Promise<RR.SetWifiCountryRes> {
|
||||
await pauseFor(2000)
|
||||
return null
|
||||
}
|
||||
|
||||
async addWifi(params: RR.AddWifiReq): Promise<RR.AddWifiRes> {
|
||||
async addWifi (params: RR.AddWifiReq): Promise<RR.AddWifiRes> {
|
||||
await pauseFor(2000)
|
||||
return null
|
||||
}
|
||||
|
||||
async connectWifi(params: RR.ConnectWifiReq): Promise<RR.ConnectWifiRes> {
|
||||
async connectWifi (params: RR.ConnectWifiReq): Promise<RR.ConnectWifiRes> {
|
||||
await pauseFor(2000)
|
||||
return null
|
||||
}
|
||||
|
||||
async deleteWifi(params: RR.DeleteWifiReq): Promise<RR.DeleteWifiRes> {
|
||||
async deleteWifi (params: RR.DeleteWifiReq): Promise<RR.DeleteWifiRes> {
|
||||
await pauseFor(2000)
|
||||
return null
|
||||
}
|
||||
|
||||
// ssh
|
||||
|
||||
async getSshKeys(params: RR.GetSSHKeysReq): Promise<RR.GetSSHKeysRes> {
|
||||
async getSshKeys (params: RR.GetSSHKeysReq): Promise<RR.GetSSHKeysRes> {
|
||||
await pauseFor(2000)
|
||||
return Mock.SshKeys
|
||||
}
|
||||
|
||||
async addSshKey(params: RR.AddSSHKeyReq): Promise<RR.AddSSHKeyRes> {
|
||||
async addSshKey (params: RR.AddSSHKeyReq): Promise<RR.AddSSHKeyRes> {
|
||||
await pauseFor(2000)
|
||||
return Mock.SshKey
|
||||
}
|
||||
|
||||
async deleteSshKey(params: RR.DeleteSSHKeyReq): Promise<RR.DeleteSSHKeyRes> {
|
||||
async deleteSshKey (params: RR.DeleteSSHKeyReq): Promise<RR.DeleteSSHKeyRes> {
|
||||
await pauseFor(2000)
|
||||
return null
|
||||
}
|
||||
|
||||
// backup
|
||||
|
||||
async getBackupTargets(
|
||||
async getBackupTargets (
|
||||
params: RR.GetBackupTargetsReq,
|
||||
): Promise<RR.GetBackupTargetsRes> {
|
||||
await pauseFor(2000)
|
||||
return Mock.BackupTargets
|
||||
}
|
||||
|
||||
async addBackupTarget(
|
||||
async addBackupTarget (
|
||||
params: RR.AddBackupTargetReq,
|
||||
): Promise<RR.AddBackupTargetRes> {
|
||||
await pauseFor(2000)
|
||||
@@ -312,7 +312,7 @@ export class MockApiService extends ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
async updateBackupTarget(
|
||||
async updateBackupTarget (
|
||||
params: RR.UpdateBackupTargetReq,
|
||||
): Promise<RR.UpdateBackupTargetRes> {
|
||||
await pauseFor(2000)
|
||||
@@ -327,21 +327,21 @@ export class MockApiService extends ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
async removeBackupTarget(
|
||||
async removeBackupTarget (
|
||||
params: RR.RemoveBackupTargetReq,
|
||||
): Promise<RR.RemoveBackupTargetRes> {
|
||||
await pauseFor(2000)
|
||||
return null
|
||||
}
|
||||
|
||||
async getBackupInfo(
|
||||
async getBackupInfo (
|
||||
params: RR.GetBackupInfoReq,
|
||||
): Promise<RR.GetBackupInfoRes> {
|
||||
await pauseFor(2000)
|
||||
return Mock.BackupInfo
|
||||
}
|
||||
|
||||
async createBackupRaw(
|
||||
async createBackupRaw (
|
||||
params: RR.CreateBackupReq,
|
||||
): Promise<RR.CreateBackupRes> {
|
||||
await pauseFor(2000)
|
||||
@@ -392,14 +392,14 @@ export class MockApiService extends ApiService {
|
||||
|
||||
// package
|
||||
|
||||
async getPackageProperties(
|
||||
async getPackageProperties (
|
||||
params: RR.GetPackagePropertiesReq,
|
||||
): Promise<RR.GetPackagePropertiesRes<2>['data']> {
|
||||
await pauseFor(2000)
|
||||
return parsePropertiesPermissive(Mock.PackageProperties)
|
||||
}
|
||||
|
||||
async getPackageLogs(
|
||||
async getPackageLogs (
|
||||
params: RR.GetPackageLogsReq,
|
||||
): Promise<RR.GetPackageLogsRes> {
|
||||
await pauseFor(2000)
|
||||
@@ -421,7 +421,7 @@ export class MockApiService extends ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
async installPackageRaw(
|
||||
async installPackageRaw (
|
||||
params: RR.InstallPackageReq,
|
||||
): Promise<RR.InstallPackageRes> {
|
||||
await pauseFor(2000)
|
||||
@@ -456,14 +456,14 @@ export class MockApiService extends ApiService {
|
||||
return this.withRevision(patch)
|
||||
}
|
||||
|
||||
async dryUpdatePackage(
|
||||
async dryUpdatePackage (
|
||||
params: RR.DryUpdatePackageReq,
|
||||
): Promise<RR.DryUpdatePackageRes> {
|
||||
await pauseFor(2000)
|
||||
return {}
|
||||
}
|
||||
|
||||
async getPackageConfig(
|
||||
async getPackageConfig (
|
||||
params: RR.GetPackageConfigReq,
|
||||
): Promise<RR.GetPackageConfigRes> {
|
||||
await pauseFor(2000)
|
||||
@@ -473,14 +473,14 @@ export class MockApiService extends ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
async drySetPackageConfig(
|
||||
async drySetPackageConfig (
|
||||
params: RR.DrySetPackageConfigReq,
|
||||
): Promise<RR.DrySetPackageConfigRes> {
|
||||
await pauseFor(2000)
|
||||
return {}
|
||||
}
|
||||
|
||||
async setPackageConfigRaw(
|
||||
async setPackageConfigRaw (
|
||||
params: RR.SetPackageConfigReq,
|
||||
): Promise<RR.SetPackageConfigRes> {
|
||||
await pauseFor(2000)
|
||||
@@ -494,7 +494,7 @@ export class MockApiService extends ApiService {
|
||||
return this.withRevision(patch)
|
||||
}
|
||||
|
||||
async restorePackagesRaw(
|
||||
async restorePackagesRaw (
|
||||
params: RR.RestorePackagesReq,
|
||||
): Promise<RR.RestorePackagesRes> {
|
||||
await pauseFor(2000)
|
||||
@@ -530,14 +530,14 @@ export class MockApiService extends ApiService {
|
||||
return this.withRevision(patch)
|
||||
}
|
||||
|
||||
async executePackageAction(
|
||||
async executePackageAction (
|
||||
params: RR.ExecutePackageActionReq,
|
||||
): Promise<RR.ExecutePackageActionRes> {
|
||||
await pauseFor(2000)
|
||||
return Mock.ActionResponse
|
||||
}
|
||||
|
||||
async startPackageRaw(
|
||||
async startPackageRaw (
|
||||
params: RR.StartPackageReq,
|
||||
): Promise<RR.StartPackageRes> {
|
||||
const path = `/package-data/${params.id}/installed/status/main`
|
||||
@@ -616,7 +616,7 @@ export class MockApiService extends ApiService {
|
||||
return this.withRevision(originalPatch)
|
||||
}
|
||||
|
||||
async dryStopPackage(
|
||||
async dryStopPackage (
|
||||
params: RR.DryStopPackageReq,
|
||||
): Promise<RR.DryStopPackageRes> {
|
||||
await pauseFor(2000)
|
||||
@@ -630,7 +630,7 @@ export class MockApiService extends ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
async stopPackageRaw(params: RR.StopPackageReq): Promise<RR.StopPackageRes> {
|
||||
async stopPackageRaw (params: RR.StopPackageReq): Promise<RR.StopPackageRes> {
|
||||
await pauseFor(2000)
|
||||
const path = `/package-data/${params.id}/installed/status/main`
|
||||
|
||||
@@ -661,14 +661,14 @@ export class MockApiService extends ApiService {
|
||||
return this.withRevision(patch)
|
||||
}
|
||||
|
||||
async dryUninstallPackage(
|
||||
async dryUninstallPackage (
|
||||
params: RR.DryUninstallPackageReq,
|
||||
): Promise<RR.DryUninstallPackageRes> {
|
||||
await pauseFor(2000)
|
||||
return {}
|
||||
}
|
||||
|
||||
async uninstallPackageRaw(
|
||||
async uninstallPackageRaw (
|
||||
params: RR.UninstallPackageReq,
|
||||
): Promise<RR.UninstallPackageRes> {
|
||||
await pauseFor(2000)
|
||||
@@ -694,7 +694,7 @@ export class MockApiService extends ApiService {
|
||||
return this.withRevision(patch)
|
||||
}
|
||||
|
||||
async deleteRecoveredPackageRaw(
|
||||
async deleteRecoveredPackageRaw (
|
||||
params: RR.DeleteRecoveredPackageReq,
|
||||
): Promise<RR.DeleteRecoveredPackageRes> {
|
||||
await pauseFor(2000)
|
||||
@@ -707,7 +707,7 @@ export class MockApiService extends ApiService {
|
||||
return this.withRevision(patch)
|
||||
}
|
||||
|
||||
async dryConfigureDependency(
|
||||
async dryConfigureDependency (
|
||||
params: RR.DryConfigureDependencyReq,
|
||||
): Promise<RR.DryConfigureDependencyRes> {
|
||||
await pauseFor(2000)
|
||||
@@ -718,7 +718,7 @@ export class MockApiService extends ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
private async updateProgress(
|
||||
private async updateProgress (
|
||||
id: string,
|
||||
initialProgress: InstallProgress,
|
||||
): Promise<void> {
|
||||
@@ -764,7 +764,7 @@ export class MockApiService extends ApiService {
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
private async updateOSProgress(size: number) {
|
||||
private async updateOSProgress (size: number) {
|
||||
let downloaded = 0
|
||||
while (downloaded < size) {
|
||||
await pauseFor(250)
|
||||
@@ -772,7 +772,7 @@ export class MockApiService extends ApiService {
|
||||
const patch = [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: `/server-info/update-progress/downloaded`,
|
||||
path: `/server-info/status-info/update-progress/downloaded`,
|
||||
value: downloaded,
|
||||
},
|
||||
]
|
||||
@@ -782,7 +782,7 @@ export class MockApiService extends ApiService {
|
||||
const patch2 = [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: `/server-info/update-progress/downloaded`,
|
||||
path: `/server-info/status-info/update-progress/downloaded`,
|
||||
value: size,
|
||||
},
|
||||
]
|
||||
@@ -797,7 +797,7 @@ export class MockApiService extends ApiService {
|
||||
},
|
||||
{
|
||||
op: PatchOp.REMOVE,
|
||||
path: '/server-info/update-progress',
|
||||
path: '/server-info/status-info/update-progress',
|
||||
},
|
||||
]
|
||||
this.updateMock(patch3)
|
||||
@@ -814,7 +814,7 @@ export class MockApiService extends ApiService {
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
private async updateMock(patch: Operation[]): Promise<void> {
|
||||
private async updateMock (patch: Operation[]): Promise<void> {
|
||||
if (!this.sequence) {
|
||||
const { sequence } = await this.bootstrapper.init()
|
||||
this.sequence = sequence
|
||||
@@ -827,7 +827,7 @@ export class MockApiService extends ApiService {
|
||||
this.mockPatch$.next(revision)
|
||||
}
|
||||
|
||||
private async withRevision<T>(
|
||||
private async withRevision<T> (
|
||||
patch: Operation[],
|
||||
response: T = null,
|
||||
): Promise<WithRevision<T>> {
|
||||
|
||||
@@ -21,13 +21,13 @@ export const mockPatchData: DataModel = {
|
||||
id: 'embassy-abcdefgh',
|
||||
version: '0.3.0',
|
||||
'last-backup': null,
|
||||
status: ServerStatus.Running,
|
||||
'lan-address': 'https://embassy-abcdefgh.local',
|
||||
'tor-address': 'http://myveryownspecialtoraddress.onion',
|
||||
'unread-notification-count': 4,
|
||||
'password-hash':
|
||||
'$argon2d$v=19$m=1024,t=1,p=1$YXNkZmFzZGZhc2RmYXNkZg$Ceev1I901G6UwU+hY0sHrFZ56D+o+LNJ',
|
||||
'eos-version-compat': '>=0.3.0',
|
||||
'status-info': null,
|
||||
},
|
||||
'recovered-packages': {
|
||||
'btc-rpc-proxy': {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { BehaviorSubject, combineLatest, fromEvent, merge, Subscription } from 'rxjs'
|
||||
import {
|
||||
BehaviorSubject,
|
||||
combineLatest,
|
||||
fromEvent,
|
||||
merge,
|
||||
Subscription,
|
||||
} from 'rxjs'
|
||||
import { PatchConnection, PatchDbService } from './patch-db/patch-db.service'
|
||||
import { distinctUntilChanged } from 'rxjs/operators'
|
||||
import { ConfigService } from './config.service'
|
||||
@@ -9,41 +15,37 @@ import { ConfigService } from './config.service'
|
||||
})
|
||||
export class ConnectionService {
|
||||
private readonly networkState$ = new BehaviorSubject<boolean>(true)
|
||||
private readonly connectionFailure$ = new BehaviorSubject<ConnectionFailure>(ConnectionFailure.None)
|
||||
private readonly connectionFailure$ = new BehaviorSubject<ConnectionFailure>(
|
||||
ConnectionFailure.None,
|
||||
)
|
||||
|
||||
constructor (
|
||||
constructor(
|
||||
private readonly configService: ConfigService,
|
||||
private readonly patch: PatchDbService,
|
||||
) { }
|
||||
) {}
|
||||
|
||||
watchFailure$ () {
|
||||
watchFailure$() {
|
||||
return this.connectionFailure$.asObservable()
|
||||
}
|
||||
|
||||
start (): Subscription[] {
|
||||
const sub1 = merge(fromEvent(window, 'online'), fromEvent(window, 'offline'))
|
||||
.subscribe(event => {
|
||||
start(): Subscription[] {
|
||||
const sub1 = merge(
|
||||
fromEvent(window, 'online'),
|
||||
fromEvent(window, 'offline'),
|
||||
).subscribe(event => {
|
||||
this.networkState$.next(event.type === 'online')
|
||||
})
|
||||
|
||||
const sub2 = combineLatest([
|
||||
// 1
|
||||
this.networkState$
|
||||
.pipe(
|
||||
distinctUntilChanged(),
|
||||
),
|
||||
this.networkState$.pipe(distinctUntilChanged()),
|
||||
// 2
|
||||
this.patch.watchPatchConnection$()
|
||||
.pipe(
|
||||
distinctUntilChanged(),
|
||||
),
|
||||
this.patch.watchPatchConnection$().pipe(distinctUntilChanged()),
|
||||
// 3
|
||||
this.patch.watch$('server-info', 'update-progress')
|
||||
.pipe(
|
||||
distinctUntilChanged(),
|
||||
),
|
||||
])
|
||||
.subscribe(async ([network, patchConnection, progress]) => {
|
||||
this.patch
|
||||
.watch$('server-info', 'status-info', 'update-progress')
|
||||
.pipe(distinctUntilChanged()),
|
||||
]).subscribe(async ([network, patchConnection, progress]) => {
|
||||
if (!network) {
|
||||
this.connectionFailure$.next(ConnectionFailure.Network)
|
||||
} else if (patchConnection !== PatchConnection.Disconnected) {
|
||||
|
||||
@@ -31,11 +31,11 @@ export interface ServerInfo {
|
||||
'last-backup': string | null
|
||||
'lan-address': URL
|
||||
'tor-address': URL
|
||||
status: ServerStatus
|
||||
'unread-notification-count': number
|
||||
'update-progress'?: {
|
||||
size: number
|
||||
downloaded: number
|
||||
'status-info': {
|
||||
'backing-up': boolean
|
||||
updated: boolean
|
||||
'update-progress': { size: number | null; downloaded: number } | null
|
||||
}
|
||||
'eos-version-compat': string
|
||||
'password-hash': string
|
||||
@@ -377,17 +377,17 @@ export interface DependencyInfo {
|
||||
export interface DependencyEntry {
|
||||
version: string
|
||||
requirement:
|
||||
| {
|
||||
type: 'opt-in'
|
||||
how: string
|
||||
}
|
||||
| {
|
||||
type: 'opt-out'
|
||||
how: string
|
||||
}
|
||||
| {
|
||||
type: 'required'
|
||||
}
|
||||
| {
|
||||
type: 'opt-in'
|
||||
how: string
|
||||
}
|
||||
| {
|
||||
type: 'opt-out'
|
||||
how: string
|
||||
}
|
||||
| {
|
||||
type: 'required'
|
||||
}
|
||||
description: string | null
|
||||
config: {
|
||||
check: ActionImpl
|
||||
|
||||
Reference in New Issue
Block a user