drive return type update

This commit is contained in:
Drew Ansbacher
2021-09-13 11:38:21 +02:00
committed by Aiden McClelland
parent 6b3570e150
commit c21ebd2c5e
11 changed files with 134 additions and 66 deletions

View File

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

View File

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

View File

@@ -1,6 +1,6 @@
import { Component } from '@angular/core'
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 { PasswordPage } from '../password/password.page'
@@ -11,7 +11,7 @@ import { PasswordPage } from '../password/password.page'
})
export class EmbassyPage {
embassyDrives = []
selectedDrive: EmbassyDrive = null
selectedDrive: Drive = null
loading = true
window = window
@@ -24,11 +24,12 @@ export class EmbassyPage {
) {}
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
}
async chooseDrive(drive: EmbassyDrive) {
async chooseDrive(drive: Drive) {
const modal = await this.modalController.create({
component: PasswordPage,
componentProps: {
@@ -62,4 +63,19 @@ export class EmbassyPage {
})
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()">
<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 && 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">
Password:

View File

@@ -1,6 +1,6 @@
import { Component, Input } from '@angular/core'
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'
@Component({
@@ -9,8 +9,8 @@ import { StateService } from 'src/app/services/state.service'
styleUrls: ['password.page.scss'],
})
export class PasswordPage {
@Input() recoveryDrive: RecoveryDrive
@Input() embassyDrive: EmbassyDrive
@Input() recoveryDrive: Drive
@Input() embassyDrive: Drive
pwError = ''
password = ''
@@ -53,7 +53,6 @@ export class PasswordPage {
async submitPw () {
this.validate()
console.log('here')
if (this.password !== this.passwordVer) {
this.verError="*passwords do not match"
}
@@ -84,4 +83,19 @@ export class PasswordPage {
cancel () {
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-label class="ion-text-wrap">
<h1>{{ drive.logicalname }}</h1>
<h2>{{ drive.name }}</h2>
<p> Embassy version: {{drive.version}}</p>
<h2>{{ drive['embassy-os'].name }}</h2>
<p> Embassy version: {{drive['embassy-os'].version}}</p>
</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.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="success" slot="end" name="lock-open-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>
</ng-container>
<ion-button
(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"
>
Next

View File

@@ -1,6 +1,6 @@
import { Component } from '@angular/core'
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 { PasswordPage } from '../password/password.page'
@@ -12,7 +12,7 @@ import { PasswordPage } from '../password/password.page'
export class RecoverPage {
passwords = {}
recoveryDrives = []
selectedDrive: RecoveryDrive = null
selectedDrive: Drive = null
loading = true
window = window
@@ -24,11 +24,11 @@ export class RecoverPage {
) {}
async ngOnInit() {
this.recoveryDrives = await this.apiService.getRecoveryDrives()
this.recoveryDrives = (await this.apiService.getDrives()).filter(d => !!d['embassy-os'])
this.loading = false
}
async chooseDrive(drive: RecoveryDrive) {
async chooseDrive(drive: Drive) {
if (this.selectedDrive?.logicalname === drive.logicalname) {
this.selectedDrive = null
@@ -37,7 +37,7 @@ export class RecoverPage {
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({
component: PasswordPage,

View File

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

View File

@@ -1,5 +1,5 @@
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'
@Injectable({
@@ -25,20 +25,13 @@ export class LiveApiService extends ApiService {
})
}
async getEmbassyDrives() {
return this.http.rpcRequest<EmbassyDrive[]>({
async getDrives() {
return this.http.rpcRequest<Drive[]>({
method: 'setup.disk.list',
params: {}
})
}
async getRecoveryDrives() {
return this.http.rpcRequest<RecoveryDrive[]>({
method: 'setup.recovery.list',
params: {}
})
}
async verifyRecoveryPassword(logicalname, password) {
return this.http.rpcRequest<boolean>({
method: 'setup.recovery.test-password',

View File

@@ -27,20 +27,66 @@ export class MockApiService extends ApiService {
}
}
async getEmbassyDrives() {
async getDrives() {
return [
{
logicalname: 'Name1',
labels: ['label 1', 'label 2'],
capacity: 1600.66666,
used: 200.1255312,
partitions: [{
logicalname: 'Name1',
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',
labels: [],
partitions: [{
logicalname: 'Name2',
label: null,
capacity: 1600.01234,
used: 0.00,
}],
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 { BehaviorSubject } from 'rxjs';
import { ApiService, EmbassyDrive, RecoveryDrive } from './api/api.service'
import { ApiService, Drive } from './api/api.service'
@Injectable({
providedIn: 'root'
@@ -8,9 +8,9 @@ import { ApiService, EmbassyDrive, RecoveryDrive } from './api/api.service'
export class StateService {
polling = false
embassyDrive: EmbassyDrive;
embassyDrive: Drive;
embassyPassword: string
recoveryDrive: RecoveryDrive;
recoveryDrive: Drive;
recoveryPassword: string
dataTransferProgress: { bytesTransfered: number; totalBytes: number } | null;
dataProgress = 0;