From 3dae1a540b7826e896ab53b9b8d17cabe97ab2a8 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Tue, 14 Sep 2021 18:45:34 -0600 Subject: [PATCH] fix initial request and some cleaning --- setup-wizard/package-lock.json | 24 +++++-------------- setup-wizard/src/app/app-routing.module.ts | 6 ++++- .../app/pages/product-key/product-key.page.ts | 10 ++++---- .../src/app/services/api/api.service.ts | 4 +--- .../src/app/services/api/http.service.ts | 24 ++++++------------- .../src/app/services/api/live-api.service.ts | 15 ++++++++---- .../src/app/services/api/mock-api.service.ts | 17 ++++++++----- 7 files changed, 45 insertions(+), 55 deletions(-) diff --git a/setup-wizard/package-lock.json b/setup-wizard/package-lock.json index 2d18c4879..57169b644 100644 --- a/setup-wizard/package-lock.json +++ b/setup-wizard/package-lock.json @@ -18822,9 +18822,7 @@ "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz", "integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==", "dev": true, - "requires": { - "ajv": "^8.0.0" - } + "requires": {} }, "tslib": { "version": "2.3.0", @@ -18904,9 +18902,7 @@ "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz", "integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==", "dev": true, - "requires": { - "ajv": "^8.0.0" - } + "requires": {} } } }, @@ -18967,9 +18963,7 @@ "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz", "integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==", "dev": true, - "requires": { - "ajv": "^8.0.0" - } + "requires": {} } } }, @@ -19079,9 +19073,7 @@ "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz", "integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==", "dev": true, - "requires": { - "ajv": "^8.0.0" - } + "requires": {} } } }, @@ -20919,9 +20911,7 @@ "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz", "integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==", "dev": true, - "requires": { - "ajv": "^8.0.0" - } + "requires": {} } } }, @@ -21536,9 +21526,7 @@ "integrity": "sha512-Brah4Uo5/U8v76c6euTwtjVFFaVishwnJrQBYpev1JRh4vjA1F4HY3UzQez41YUCszUCXKagG8v6eVRBHV1gkw==", "dev": true, "peer": true, - "requires": { - "ajv": "^8.0.0" - } + "requires": {} }, "alphanum-sort": { "version": "1.0.2", diff --git a/setup-wizard/src/app/app-routing.module.ts b/setup-wizard/src/app/app-routing.module.ts index 2e98c1993..ff26f0368 100644 --- a/setup-wizard/src/app/app-routing.module.ts +++ b/setup-wizard/src/app/app-routing.module.ts @@ -29,7 +29,11 @@ const routes: Routes = [ @NgModule({ imports: [ - RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules }) + RouterModule.forRoot(routes, { + scrollPositionRestoration: 'enabled', + preloadingStrategy: PreloadAllModules, + useHash: true, + }) ], exports: [RouterModule] }) diff --git a/setup-wizard/src/app/pages/product-key/product-key.page.ts b/setup-wizard/src/app/pages/product-key/product-key.page.ts index 6c7de9ef2..4bdd5379c 100644 --- a/setup-wizard/src/app/pages/product-key/product-key.page.ts +++ b/setup-wizard/src/app/pages/product-key/product-key.page.ts @@ -15,10 +15,10 @@ export class ProductKeyPage { constructor( private readonly navCtrl: NavController, - private stateService: StateService, - private apiService: ApiService, - private loadingCtrl: LoadingController, - private httpService: HttpService + private readonly stateService: StateService, + private readonly apiService: ApiService, + private readonly loadingCtrl: LoadingController, + private readonly httpService: HttpService ) {} async submit () { @@ -30,8 +30,8 @@ export class ProductKeyPage { await loader.present() try { - const state = await this.apiService.verifyProductKey(this.productKey) this.httpService.productKey = this.productKey + const state = await this.apiService.verifyProductKey() if(state['is-recovering']) { await this.navCtrl.navigateForward(`/loading`, { animationDirection: 'forward', animation: iosTransitionAnimation }) } else if (!!state['tor-address']) { diff --git a/setup-wizard/src/app/services/api/api.service.ts b/setup-wizard/src/app/services/api/api.service.ts index 657944830..4e4a5fe28 100644 --- a/setup-wizard/src/app/services/api/api.service.ts +++ b/setup-wizard/src/app/services/api/api.service.ts @@ -1,9 +1,7 @@ import { Subject } from 'rxjs' export abstract class ApiService { - protected error$: Subject = new Subject(); - watchError$ = this.error$.asObservable(); - abstract verifyProductKey (key: string): Promise; + abstract verifyProductKey (): Promise; abstract getDrives (): Promise; abstract getDataTransferProgress (): Promise; abstract verifyRecoveryPassword (logicalname: string, password: string): Promise; diff --git a/setup-wizard/src/app/services/api/http.service.ts b/setup-wizard/src/app/services/api/http.service.ts index b43f03de1..779bb4c0b 100644 --- a/setup-wizard/src/app/services/api/http.service.ts +++ b/setup-wizard/src/app/services/api/http.service.ts @@ -9,7 +9,6 @@ import * as pbkdf2 from 'pbkdf2' providedIn: 'root', }) export class HttpService { - private unauthorizedApiResponse$ = new Subject() fullUrl: string productKey: string @@ -20,32 +19,25 @@ export class HttpService { this.fullUrl = `${window.location.protocol}//${window.location.hostname}:${port}` } - watchUnauth$ (): Observable<{ }> { - return this.unauthorizedApiResponse$.asObservable() - } - async rpcRequest (body: RPCOptions): Promise { const httpOpts = { method: Method.POST, body, - url: `this.fullUrl`, + url: this.fullUrl, } const res = await this.httpRequest>(httpOpts) - if (isRpcError(res)) { - if (res.error.code === 34) this.unauthorizedApiResponse$.next(true) - throw new RpcError(res.error) - } + if (isRpcError(res)) throw new RpcError(res.error) if (isRpcSuccess(res)) return res.result } async httpRequest (httpOpts: { - body: RPCOptions; - url: string; - }): Promise { + body: RPCOptions; + url: string; + }): Promise { const urlIsRelative = httpOpts.url.startsWith('/') const url = urlIsRelative ? @@ -54,15 +46,13 @@ export class HttpService { const options = { responseType: 'arraybuffer', - body: await AES_CTR.encryptPbkdf2( this.productKey, encodeUtf8( JSON.stringify(httpOpts.body))), + body: await AES_CTR.encryptPbkdf2(this.productKey, encodeUtf8( JSON.stringify(httpOpts.body))), observe: 'events', reportProgress: false, headers: { 'Content-Encoding': 'aesctr256', 'Content-Type': 'application/json' }, - // one minute - timeout: 60000, } as any const req = this.http.post(url, httpOpts.body, options) @@ -157,7 +147,7 @@ export interface HttpOptions { params?: HttpParams | { [param: string]: string | string[] } - responseType?: 'json' | 'text' + responseType?: 'json' | 'text' | 'arrayBuffer' withCredentials?: boolean body?: any timeout?: number diff --git a/setup-wizard/src/app/services/api/live-api.service.ts b/setup-wizard/src/app/services/api/live-api.service.ts index fffc19050..b2eb5c1fe 100644 --- a/setup-wizard/src/app/services/api/live-api.service.ts +++ b/setup-wizard/src/app/services/api/live-api.service.ts @@ -11,35 +11,40 @@ export class LiveApiService extends ApiService { private readonly http: HttpService ) { super() } - async verifyProductKey() { + async verifyProductKey () { return this.http.rpcRequest({ method: 'setup.status', params: {} }) } - async getDataTransferProgress() { + async getDataTransferProgress () { return this.http.rpcRequest({ method: 'setup.recovery.status', params: {} }) } - async getDrives() { + async getDrives () { return this.http.rpcRequest({ method: 'setup.disk.list', params: {} }) } - async verifyRecoveryPassword(logicalname, password) { + async verifyRecoveryPassword (logicalname: string, password: string) { return this.http.rpcRequest({ method: 'setup.recovery.test-password', params: {logicalname, password} }) } - async setupEmbassy (setupInfo) { + async setupEmbassy (setupInfo: { + 'embassy-logicalname': string, + 'embassy-password': string + 'recovery-logicalname'?: string, + 'recovery-password'?: string + }) { return this.http.rpcRequest({ method: 'setup.execute', params: setupInfo diff --git a/setup-wizard/src/app/services/api/mock-api.service.ts b/setup-wizard/src/app/services/api/mock-api.service.ts index 8ec33753a..5e156b833 100644 --- a/setup-wizard/src/app/services/api/mock-api.service.ts +++ b/setup-wizard/src/app/services/api/mock-api.service.ts @@ -11,7 +11,7 @@ export class MockApiService extends ApiService { super() } - async verifyProductKey(key) { + async verifyProductKey () { await pauseFor(2000) return { "is-recovering": false, @@ -19,7 +19,7 @@ export class MockApiService extends ApiService { } } - async getDataTransferProgress() { + async getDataTransferProgress () { tries = Math.min(tries + 1, 4) return { 'bytes-transfered': tries, @@ -27,7 +27,7 @@ export class MockApiService extends ApiService { } } - async getDrives() { + async getDrives () { return [ { vendor: 'Vendor', @@ -102,7 +102,7 @@ export class MockApiService extends ApiService { ] } - async getRecoveryDrives() { + async getRecoveryDrives () { await pauseFor(2000) return [ { @@ -118,12 +118,17 @@ export class MockApiService extends ApiService { ] } - async verifyRecoveryPassword(logicalname, password) { + async verifyRecoveryPassword (logicalname: string, password: string) { await pauseFor(2000) return password.length > 8 } - async setupEmbassy (setupInfo) { + async setupEmbassy (setupInfo: { + 'embassy-logicalname': string, + 'embassy-password': string + 'recovery-logicalname'?: string, + 'recovery-password'?: string + }) { await pauseFor(2000) return { "tor-address": 'asdfasdfasdf.onion' } }