drive return type update

This commit is contained in:
Drew Ansbacher
2021-09-13 11:38:21 +02:00
committed by Matt Hill
parent cc90dd5151
commit eaacaeeb5f
11 changed files with 134 additions and 66 deletions

View File

@@ -12,19 +12,17 @@ setup.disk.list
Response Response
{ {
logicalname: string logicalname: string
labels: string[] partitions: {
logicalname: string
label: string | null
capacity: number
used: number | null
}[],
capacity: number capacity: number
used: number 'embassy-os': {
}[] version: string
name: string
setup.recovery.list } | null
Request
Response
{
logicalname: string
version: string
name: string
}[] }[]
setup.recovery.status setup.recovery.status

View File

@@ -44,8 +44,8 @@
<ion-icon slot="start" name="save-outline"></ion-icon> <ion-icon slot="start" name="save-outline"></ion-icon>
<ion-label class="ion-text-wrap"> <ion-label class="ion-text-wrap">
<h1>{{ drive.logicalname }}</h1> <h1>{{ drive.logicalname }}</h1>
<h2 style="min-height: 19px;">{{ drive.labels.length ? drive.labels.join(' / ') : 'unnamed' }}</h2> <h2 style="min-height: 19px;">{{ getLabelLabel(drive) }}</h2>
<p> Using {{drive.used.toFixed(2)}} of {{drive.capacity.toFixed(2)}} GiB</p> <p> Using {{ getUsage(drive) }} of {{drive.capacity.toFixed(2)}} GiB</p>
</ion-label> </ion-label>
</ion-item> </ion-item>
</ng-container> </ng-container>

View File

@@ -1,6 +1,6 @@
import { Component } from '@angular/core' import { Component } from '@angular/core'
import { iosTransitionAnimation, LoadingController, ModalController, NavController } from '@ionic/angular' import { iosTransitionAnimation, LoadingController, ModalController, NavController } from '@ionic/angular'
import { ApiService, EmbassyDrive } from 'src/app/services/api/api.service' import { ApiService, Drive } from 'src/app/services/api/api.service'
import { StateService } from 'src/app/services/state.service' import { StateService } from 'src/app/services/state.service'
import { PasswordPage } from '../password/password.page' import { PasswordPage } from '../password/password.page'
@@ -11,7 +11,7 @@ import { PasswordPage } from '../password/password.page'
}) })
export class EmbassyPage { export class EmbassyPage {
embassyDrives = [] embassyDrives = []
selectedDrive: EmbassyDrive = null selectedDrive: Drive = null
loading = true loading = true
window = window window = window
@@ -24,11 +24,12 @@ export class EmbassyPage {
) {} ) {}
async ngOnInit() { async ngOnInit() {
this.embassyDrives = await this.apiService.getEmbassyDrives() const drives = (await this.apiService.getDrives()).filter(d => !d['embassy-os'])
this.embassyDrives = (await this.apiService.getDrives()).filter(d => !d['embassy-os'])
this.loading = false this.loading = false
} }
async chooseDrive(drive: EmbassyDrive) { async chooseDrive(drive: Drive) {
const modal = await this.modalController.create({ const modal = await this.modalController.create({
component: PasswordPage, component: PasswordPage,
componentProps: { componentProps: {
@@ -62,4 +63,19 @@ export class EmbassyPage {
}) })
await modal.present(); await modal.present();
} }
getLabelLabel(drive: Drive) {
const labels = drive.partitions.map(p => p.label).filter(l => !!l)
return labels.length ? labels.join(' / ') : 'unnamed'
}
getUsage(drive: Drive) {
let usage = 0
drive.partitions.forEach(par => {
if(par.used) {
usage += par.used
}
})
return usage.toFixed(2)
}
} }

View File

@@ -11,7 +11,7 @@
<form (ngSubmit)="!!recoveryDrive ? verifyPw() : submitPw()"> <form (ngSubmit)="!!recoveryDrive ? verifyPw() : submitPw()">
<div style="padding: 8px 24px;"> <div style="padding: 8px 24px;">
<p *ngIf="!!embassyDrive">Choose a password for your embassy. You will need it every time you log in. If you lose it you will be permanently locked out of your embassy.</p> <p *ngIf="!!embassyDrive">Choose a password for your embassy. You will need it every time you log in. If you lose it you will be permanently locked out of your embassy.</p>
<p *ngIf="embassyDrive && embassyDrive.used > 0" style="padding-bottom: 15px;color: var(--ion-color-warning);"><b>Warning:</b> After submit, any data currently stored on <b>{{ embassyDrive.labels.length ? embassyDrive.labels.join(' / ') : embassyDrive.logicalname }}</b> will be wiped.</p> <p *ngIf="embassyDrive && getUsage(embassyDrive) > 0" style="padding-bottom: 15px;color: var(--ion-color-warning);"><b>Warning:</b> After submit, any data currently stored on <b>{{ getLabelLabel(embassyDrive) }}</b> will be wiped.</p>
<h4 class="input-label"> <h4 class="input-label">
Password: Password:

View File

@@ -1,6 +1,6 @@
import { Component, Input } from '@angular/core' import { Component, Input } from '@angular/core'
import { LoadingController, ModalController } from '@ionic/angular' import { LoadingController, ModalController } from '@ionic/angular'
import { ApiService, EmbassyDrive, RecoveryDrive } from 'src/app/services/api/api.service' import { ApiService, Drive } from 'src/app/services/api/api.service'
import { StateService } from 'src/app/services/state.service' import { StateService } from 'src/app/services/state.service'
@Component({ @Component({
@@ -9,8 +9,8 @@ import { StateService } from 'src/app/services/state.service'
styleUrls: ['password.page.scss'], styleUrls: ['password.page.scss'],
}) })
export class PasswordPage { export class PasswordPage {
@Input() recoveryDrive: RecoveryDrive @Input() recoveryDrive: Drive
@Input() embassyDrive: EmbassyDrive @Input() embassyDrive: Drive
pwError = '' pwError = ''
password = '' password = ''
@@ -53,7 +53,6 @@ export class PasswordPage {
async submitPw () { async submitPw () {
this.validate() this.validate()
console.log('here')
if (this.password !== this.passwordVer) { if (this.password !== this.passwordVer) {
this.verError="*passwords do not match" this.verError="*passwords do not match"
} }
@@ -84,4 +83,19 @@ export class PasswordPage {
cancel () { cancel () {
this.modalController.dismiss() this.modalController.dismiss()
} }
getLabelLabel(drive: Drive) {
const labels = drive.partitions.map(p => p.label).filter(l => !!l)
return labels.length ? labels.join(' / ') : 'unnamed'
}
getUsage(drive: Drive) {
let usage = 0
drive.partitions.forEach(par => {
if(par.used) {
usage += par.used
}
})
return usage
}
} }

View File

@@ -44,17 +44,17 @@
<ion-icon slot="start" name="save-outline"></ion-icon> <ion-icon slot="start" name="save-outline"></ion-icon>
<ion-label class="ion-text-wrap"> <ion-label class="ion-text-wrap">
<h1>{{ drive.logicalname }}</h1> <h1>{{ drive.logicalname }}</h1>
<h2>{{ drive.name }}</h2> <h2>{{ drive['embassy-os'].name }}</h2>
<p> Embassy version: {{drive.version}}</p> <p> Embassy version: {{drive['embassy-os'].version}}</p>
</ion-label> </ion-label>
<ion-icon *ngIf="drive.version.startsWith('0.2') || passwords[drive.logicalname]" color="success" slot="end" name="lock-open-outline"></ion-icon> <ion-icon *ngIf="drive['embassy-os'].version.startsWith('0.2') || passwords[drive.logicalname]" color="success" slot="end" name="lock-open-outline"></ion-icon>
<ion-icon *ngIf="!drive.version.startsWith('0.2') && !passwords[drive.logicalname]" color="danger" slot="end" name="lock-closed-outline"></ion-icon> <ion-icon *ngIf="!drive['embassy-os'].version.startsWith('0.2') && !passwords[drive.logicalname]" color="danger" slot="end" name="lock-closed-outline"></ion-icon>
</ion-item> </ion-item>
</ng-container> </ng-container>
<ion-button <ion-button
(click)="selectRecoveryDrive()" (click)="selectRecoveryDrive()"
[disabled]="!selectedDrive || (!passwords[selectedDrive.logicalname] && !selectedDrive.version.startsWith('0.2'))" [disabled]="!selectedDrive || (!passwords[selectedDrive.logicalname] && !selectedDrive['embassy-os'].version.startsWith('0.2'))"
class="claim-button" class="claim-button"
> >
Next Next

View File

@@ -1,6 +1,6 @@
import { Component } from '@angular/core' import { Component } from '@angular/core'
import { iosTransitionAnimation, ModalController, NavController } from '@ionic/angular' import { iosTransitionAnimation, ModalController, NavController } from '@ionic/angular'
import { ApiService, RecoveryDrive } from 'src/app/services/api/api.service' import { ApiService, Drive } from 'src/app/services/api/api.service'
import { StateService } from 'src/app/services/state.service' import { StateService } from 'src/app/services/state.service'
import { PasswordPage } from '../password/password.page' import { PasswordPage } from '../password/password.page'
@@ -12,7 +12,7 @@ import { PasswordPage } from '../password/password.page'
export class RecoverPage { export class RecoverPage {
passwords = {} passwords = {}
recoveryDrives = [] recoveryDrives = []
selectedDrive: RecoveryDrive = null selectedDrive: Drive = null
loading = true loading = true
window = window window = window
@@ -24,11 +24,11 @@ export class RecoverPage {
) {} ) {}
async ngOnInit() { async ngOnInit() {
this.recoveryDrives = await this.apiService.getRecoveryDrives() this.recoveryDrives = (await this.apiService.getDrives()).filter(d => !!d['embassy-os'])
this.loading = false this.loading = false
} }
async chooseDrive(drive: RecoveryDrive) { async chooseDrive(drive: Drive) {
if (this.selectedDrive?.logicalname === drive.logicalname) { if (this.selectedDrive?.logicalname === drive.logicalname) {
this.selectedDrive = null this.selectedDrive = null
@@ -37,7 +37,7 @@ export class RecoverPage {
this.selectedDrive = drive this.selectedDrive = drive
} }
if (drive.version.startsWith('0.2') || this.passwords[drive.logicalname]) return if (drive['embassy-os'].version.startsWith('0.2') || this.passwords[drive.logicalname]) return
const modal = await this.modalController.create({ const modal = await this.modalController.create({
component: PasswordPage, component: PasswordPage,

View File

@@ -4,8 +4,7 @@ export abstract class ApiService {
protected error$: Subject<string> = new Subject(); protected error$: Subject<string> = new Subject();
watchError$ = this.error$.asObservable(); watchError$ = this.error$.asObservable();
abstract verifyProductKey (key: string): Promise<VerifyProductKeyRes>; abstract verifyProductKey (key: string): Promise<VerifyProductKeyRes>;
abstract getEmbassyDrives (): Promise<EmbassyDrive[]>; abstract getDrives (): Promise<Drive[]>;
abstract getRecoveryDrives (): Promise<RecoveryDrive[]>;
abstract getDataTransferProgress (): Promise<TransferProgressRes>; abstract getDataTransferProgress (): Promise<TransferProgressRes>;
abstract verifyRecoveryPassword (logicalname: string, password: string): Promise<boolean>; abstract verifyRecoveryPassword (logicalname: string, password: string): Promise<boolean>;
abstract setupEmbassy (setupInfo: { abstract setupEmbassy (setupInfo: {
@@ -30,15 +29,17 @@ export interface SetupEmbassyRes {
"tor-address": string "tor-address": string
} }
export interface EmbassyDrive { export interface Drive {
logicalname: string; logicalname: string
labels: string[]; partitions: {
capacity: number; logicalname: string
used: number; label: string | null
} capacity: number
used: number | null
export interface RecoveryDrive { }[],
logicalname: string; capacity: number
version: string; 'embassy-os': {
name: string; version: string
} name: string
} | null
}[]

View File

@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core' import { Injectable } from '@angular/core'
import { ApiService, EmbassyDrive, RecoveryDrive, SetupEmbassyRes, TransferProgressRes, VerifyProductKeyRes } from './api.service' import { ApiService, Drive, SetupEmbassyRes, TransferProgressRes, VerifyProductKeyRes } from './api.service'
import { HttpService } from './http.service' import { HttpService } from './http.service'
@Injectable({ @Injectable({
@@ -25,20 +25,13 @@ export class LiveApiService extends ApiService {
}) })
} }
async getEmbassyDrives() { async getDrives() {
return this.http.rpcRequest<EmbassyDrive[]>({ return this.http.rpcRequest<Drive[]>({
method: 'setup.disk.list', method: 'setup.disk.list',
params: {} params: {}
}) })
} }
async getRecoveryDrives() {
return this.http.rpcRequest<RecoveryDrive[]>({
method: 'setup.recovery.list',
params: {}
})
}
async verifyRecoveryPassword(logicalname, password) { async verifyRecoveryPassword(logicalname, password) {
return this.http.rpcRequest<boolean>({ return this.http.rpcRequest<boolean>({
method: 'setup.recovery.test-password', method: 'setup.recovery.test-password',

View File

@@ -27,20 +27,66 @@ export class MockApiService extends ApiService {
} }
} }
async getEmbassyDrives() { async getDrives() {
return [ return [
{ {
logicalname: 'Name1', logicalname: 'Name1',
labels: ['label 1', 'label 2'], partitions: [{
capacity: 1600.66666, logicalname: 'Name1',
used: 200.1255312, label: 'label 1',
capacity: 100000,
used: 200.1255312
}, {
logicalname: 'Name1',
label: 'label 2',
capacity: 50000,
used: 200.1255312
}],
capacity: 150000,
'embassy-os': null
}, },
{ {
logicalname: 'Name2', logicalname: 'Name2',
labels: [], partitions: [{
logicalname: 'Name2',
label: null,
capacity: 1600.01234,
used: 0.00,
}],
capacity: 1600.01234, capacity: 1600.01234,
used: 0.00, 'embassy-os': null
},
{
logicalname: 'Name3',
partitions: [{
logicalname: 'Name3',
label: 'label 1',
capacity: null,
used: null
}],
capacity: 100000,
'embassy-os': {
version: '0.3.3',
name: 'My Embassy'
}
},
{
logicalname: 'Name4',
partitions: [{
logicalname: 'Name4',
label: null,
capacity: 10000,
used: null
}],
capacity: 10000,
'embassy-os': {
version: '0.2.7',
name: 'My Embassy'
}
} }
] ]
} }

View File

@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core' import { Injectable } from '@angular/core'
import { BehaviorSubject } from 'rxjs'; import { BehaviorSubject } from 'rxjs';
import { ApiService, EmbassyDrive, RecoveryDrive } from './api/api.service' import { ApiService, Drive } from './api/api.service'
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -8,9 +8,9 @@ import { ApiService, EmbassyDrive, RecoveryDrive } from './api/api.service'
export class StateService { export class StateService {
polling = false polling = false
embassyDrive: EmbassyDrive; embassyDrive: Drive;
embassyPassword: string embassyPassword: string
recoveryDrive: RecoveryDrive; recoveryDrive: Drive;
recoveryPassword: string recoveryPassword: string
dataTransferProgress: { bytesTransfered: number; totalBytes: number } | null; dataTransferProgress: { bytesTransfered: number; totalBytes: number } | null;
dataProgress = 0; dataProgress = 0;