change disk type, add endpoint, share stats prompt

This commit is contained in:
Matt Hill
2021-10-17 08:18:25 -06:00
committed by Aiden McClelland
parent effcd5ea57
commit c27fd487b9
22 changed files with 350 additions and 148 deletions

View File

@@ -985,12 +985,10 @@ export module Mock {
label: 'Matt Stuff',
capacity: 1000000000000,
used: 0,
'embassy-os': null,
},
],
capacity: 1000000000000,
'embassy-os': {
version: '0.3.0',
},
},
{
logicalname: '/dev/sdb',
@@ -1002,21 +1000,35 @@ export module Mock {
label: 'Partition 1',
capacity: 1000000000,
used: 1000000000,
'embassy-os': {
version: '0.3.0',
full: true,
},
},
{
logicalname: 'sdba2',
label: 'Partition 2',
capacity: 900000000,
used: 300000000,
'embassy-os': null,
},
],
capacity: 10000000000,
'embassy-os': {
version: '0.3.0',
},
},
]
export const BackupInfo: RR.GetBackupInfoRes = {
version: '0.3.0',
timestamp: new Date().toISOString(),
'package-backups': {
bitcoind: {
version: '0.21.0',
'os-version': '0.3.0',
timestamp: new Date().toISOString(),
},
},
}
export const PackageProperties: RR.GetPackagePropertiesRes<2> = {
version: 2,
data: {
@@ -1534,6 +1546,7 @@ export module Mock {
manifest: MockManifestBitcoind,
installed: {
manifest: MockManifestBitcoind,
'last-backup': null,
status: {
configured: true,
main: {
@@ -1571,6 +1584,7 @@ export module Mock {
},
manifest: MockManifestBitcoinProxy,
installed: {
'last-backup': null,
status: {
configured: true,
main: {
@@ -1623,6 +1637,7 @@ export module Mock {
},
manifest: MockManifestLnd,
installed: {
'last-backup': null,
status: {
configured: true,
main: {

View File

@@ -46,7 +46,7 @@ export module RR {
export type GetSessionsReq = { } // sessions.list
export type GetSessionsRes = {
current: string,
current: string
sessions: { [hash: string]: Session }
}
@@ -126,8 +126,8 @@ export module RR {
export type GetDisksReq = { } // disk.list
export type GetDisksRes = DiskInfo[]
export type EjectDisksReq = { logicalname: string } // disk.eject
export type EjectDisksRes = null
export type GetBackupInfoReq = { logicalname: string, password: string } // disk.backup-info
export type GetBackupInfoRes = BackupInfo
// package
@@ -214,7 +214,7 @@ export type WithExpire<T> = { 'expire-id'?: string } & T
export type WithRevision<T> = { response: T, revision?: Revision }
export interface MarketplaceData {
categories: string[],
categories: string[]
}
export interface MarketplaceEOS {
@@ -243,8 +243,8 @@ export interface Breakages {
}
export interface TaggedDependencyError {
dependency: string,
error: DependencyError,
dependency: string
error: DependencyError
}
export interface Log {
@@ -289,22 +289,35 @@ export type PlatformType = 'cli' | 'ios' | 'ipad' | 'iphone' | 'android' | 'phab
export interface DiskInfo {
logicalname: string
vendor: string | null,
model: string | null,
partitions: PartitionInfo[],
vendor: string | null
model: string | null
partitions: PartitionInfo[]
capacity: number
'embassy-os': EmbassyOsDiskInfo | null
}
export interface PartitionInfo {
logicalname: string,
label: string | null,
capacity: number,
used: number | null,
logicalname: string
label: string | null
capacity: number
used: number | null
'embassy-os': EmbassyOsDiskInfo | null
}
export interface EmbassyOsDiskInfo {
version: string
full: boolean
}
export interface BackupInfo {
version: string,
timestamp: string,
'package-backups': {
[id: string]: {
version: string
'os-version': string
timestamp: string
}
}
}
export interface ServerSpecs {

View File

@@ -130,7 +130,7 @@ export abstract class ApiService implements Source<DataModel>, Http<DataModel> {
abstract getDisks (params: RR.GetDisksReq): Promise<RR.GetDisksRes>
abstract ejectDisk (params: RR.EjectDisksReq): Promise<RR.EjectDisksRes>
abstract getBackupInfo (params: RR.GetBackupInfoReq): Promise<RR.GetBackupInfoRes>
// package

View File

@@ -197,8 +197,8 @@ export class LiveApiService extends ApiService {
return this.http.rpcRequest({ method: 'disk.list', params })
}
ejectDisk (params: RR.EjectDisksReq): Promise <RR.EjectDisksRes> {
return this.http.rpcRequest({ method: 'disk.eject', params })
getBackupInfo (params: RR.GetBackupInfoReq): Promise <RR.GetBackupInfoRes> {
return this.http.rpcRequest({ method: 'disk.backup-info', params })
}
// package

View File

@@ -291,9 +291,9 @@ export class MockApiService extends ApiService {
return Mock.Disks
}
async ejectDisk (params: RR.EjectDisksReq): Promise<RR.EjectDisksRes> {
async getBackupInfo (params: RR.GetBackupInfoReq): Promise<RR.GetBackupInfoRes> {
await pauseFor(2000)
return null
return Mock.BackupInfo
}
// package
@@ -415,12 +415,13 @@ export class MockApiService extends ApiService {
const patch = [
{
op: PatchOp.REPLACE,
path,
value: {
status: PackageMainStatus.Running,
started: new Date().toISOString(), // UTC date string
health: { },
},
path: path + '/status',
value: PackageMainStatus.Running,
},
{
op: PatchOp.REPLACE,
path: path + '/started',
value: new Date().toISOString(),
},
]
return this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
@@ -440,14 +441,12 @@ export class MockApiService extends ApiService {
async stopPackageRaw (params: RR.StopPackageReq): Promise<RR.StopPackageRes> {
await pauseFor(2000)
const path = `/package-data/${params.id}/installed/status/main`
const path = `/package-data/${params.id}/installed/status/main/status`
const patch = [
{
op: PatchOp.REPLACE,
path,
value: {
status: PackageMainStatus.Stopping,
},
value: PackageMainStatus.Stopping,
},
]
const res = await this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
@@ -455,7 +454,7 @@ export class MockApiService extends ApiService {
const patch = [
{
op: PatchOp.REPLACE,
path: path + '/status',
path,
value: PackageMainStatus.Stopped,
},
]

View File

@@ -9,8 +9,8 @@ export class Emver {
constructor () { }
compare (lhs: string, rhs: string): number {
const compare = emver.compare(lhs, rhs)
return compare
if (!lhs || !rhs) return null
return emver.compare(lhs, rhs)
}
satisfies (version: string, range: string): boolean {

View File

@@ -9,19 +9,22 @@ export interface DataModel {
export interface UIData {
name: string
'welcome-ack': string
'auto-check-updates': boolean
'pkg-order': string[]
'ack-welcome': string // EOS version
'ack-share-stats': boolean
}
export interface ServerInfo {
id: string
version: string
'last-backup': string | null
'lan-address': URL
'tor-address': URL
status: ServerStatus
'eos-marketplace': URL
'package-marketplace': URL | null // uses EOS marketplace if null
'share-stats': boolean
'unread-notification-count': number
'update-progress'?: {
size: number
@@ -66,6 +69,7 @@ export interface InstallProgress {
export interface InstalledPackageDataEntry {
status: Status
manifest: Manifest,
'last-backup': string | null
'system-pointers': any[]
'current-dependents': { [id: string]: CurrentDependencyInfo }
'current-dependencies': { [id: string]: CurrentDependencyInfo }

View File

@@ -17,7 +17,7 @@ export class ServerConfigService {
private readonly embassyApi: ApiService,
) { }
async presentAlert (key: string, current?: any): Promise<void> {
async presentAlert (key: string, current?: any): Promise<HTMLIonAlertElement> {
const spec = serverConfig[key]
let inputs: AlertInput[]
@@ -78,6 +78,7 @@ export class ServerConfigService {
buttons,
})
await alert.present()
return alert
}
// async presentModalForm (key: string) {

View File

@@ -14,6 +14,7 @@ import { filter, take } from 'rxjs/operators'
import { isEmptyObject } from '../util/misc.util'
import { ApiService } from './api/embassy-api.service'
import { Subscription } from 'rxjs'
import { ServerConfigService } from './server-config.service'
@Injectable({
providedIn: 'root',
@@ -32,6 +33,7 @@ export class StartupAlertsService {
private readonly emver: Emver,
private readonly wizardBaker: WizardBaker,
private readonly patch: PatchDbService,
private readonly serverConfig: ServerConfigService,
) {
const osWelcome: Check<boolean> = {
name: 'osWelcome',
@@ -39,6 +41,12 @@ export class StartupAlertsService {
check: async () => true,
display: () => this.displayOsWelcome(),
}
const shareStats: Check<boolean> = {
name: 'shareStats',
shouldRun: () => this.shouldRunShareStats(),
check: async () => true,
display: () => this.displayShareStats(),
}
const osUpdate: Check<RR.GetMarketplaceEOSRes | undefined> = {
name: 'osUpdate',
shouldRun: () => this.shouldRunOsUpdateCheck(),
@@ -51,7 +59,7 @@ export class StartupAlertsService {
check: () => this.appsCheck(),
display: () => this.displayAppsCheck(),
}
this.checks = [osWelcome, osUpdate, pkgsUpdate]
this.checks = [osWelcome, shareStats, osUpdate, pkgsUpdate]
}
// This takes our three checks and filters down to those that should run.
@@ -87,8 +95,13 @@ export class StartupAlertsService {
})
}
// ** should run **
private shouldRunOsWelcome (): boolean {
return this.data.ui['welcome-ack'] !== this.config.version
return this.data.ui['ack-welcome'] !== this.config.version
}
private shouldRunShareStats (): boolean {
return !this.data.ui['ack-share-stats']
}
private shouldRunOsUpdateCheck (): boolean {
@@ -99,6 +112,8 @@ export class StartupAlertsService {
return this.data.ui['auto-check-updates']
}
// ** check **
private async osUpdateCheck (): Promise<RR.GetMarketplaceEOSRes | undefined> {
const res = await this.api.getEos({ })
@@ -114,6 +129,8 @@ export class StartupAlertsService {
return !!updates.length
}
// ** display **
private async displayOsWelcome (): Promise<boolean> {
return new Promise(async resolve => {
const modal = await this.modalCtrl.create({
@@ -124,7 +141,7 @@ export class StartupAlertsService {
},
})
modal.onWillDismiss().then(() => {
this.api.setDbValue({ pointer: '/welcome-ack', value: this.config.version })
this.api.setDbValue({ pointer: '/ack-welcome', value: this.config.version })
.catch()
return resolve(true)
})
@@ -132,6 +149,18 @@ export class StartupAlertsService {
})
}
private async displayShareStats (): Promise<boolean> {
return new Promise(async resolve => {
const alert = await this.serverConfig.presentAlert('share-stats', this.data['server-info']['share-stats'])
alert.onDidDismiss().then(() => {
this.api.setDbValue({ pointer: '/ack-share-stats', value: this.config.version })
.catch()
return resolve(true)
})
})
}
private async displayOsUpdateCheck (eos: RR.GetMarketplaceEOSRes): Promise<boolean> {
const { update } = await this.presentAlertNewOS(eos.version)
if (update) {
@@ -180,6 +209,8 @@ export class StartupAlertsService {
})
}
// more
private async presentAlertNewOS (versionLatest: string): Promise<{ cancel?: true, update?: true }> {
return new Promise(async resolve => {
const alert = await this.alertCtrl.create({