mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +00:00
fix initial request and some cleaning
This commit is contained in:
committed by
Aiden McClelland
parent
9825d66ef3
commit
3dae1a540b
24
setup-wizard/package-lock.json
generated
24
setup-wizard/package-lock.json
generated
@@ -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",
|
||||
|
||||
@@ -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]
|
||||
})
|
||||
|
||||
@@ -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']) {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { Subject } from 'rxjs'
|
||||
|
||||
export abstract class ApiService {
|
||||
protected error$: Subject<string> = new Subject();
|
||||
watchError$ = this.error$.asObservable();
|
||||
abstract verifyProductKey (key: string): Promise<VerifyProductKeyRes>;
|
||||
abstract verifyProductKey (): Promise<VerifyProductKeyRes>;
|
||||
abstract getDrives (): Promise<DiskInfo[]>;
|
||||
abstract getDataTransferProgress (): Promise<TransferProgressRes>;
|
||||
abstract verifyRecoveryPassword (logicalname: string, password: string): Promise<boolean>;
|
||||
|
||||
@@ -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<T> (body: RPCOptions): Promise<T> {
|
||||
|
||||
const httpOpts = {
|
||||
method: Method.POST,
|
||||
body,
|
||||
url: `this.fullUrl`,
|
||||
url: this.fullUrl,
|
||||
}
|
||||
|
||||
const res = await this.httpRequest<RPCResponse<T>>(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<T> (httpOpts: {
|
||||
body: RPCOptions;
|
||||
url: string;
|
||||
}): Promise<T> {
|
||||
body: RPCOptions;
|
||||
url: string;
|
||||
}): Promise<T> {
|
||||
|
||||
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
|
||||
|
||||
@@ -11,35 +11,40 @@ export class LiveApiService extends ApiService {
|
||||
private readonly http: HttpService
|
||||
) { super() }
|
||||
|
||||
async verifyProductKey() {
|
||||
async verifyProductKey () {
|
||||
return this.http.rpcRequest<VerifyProductKeyRes>({
|
||||
method: 'setup.status',
|
||||
params: {}
|
||||
})
|
||||
}
|
||||
|
||||
async getDataTransferProgress() {
|
||||
async getDataTransferProgress () {
|
||||
return this.http.rpcRequest<TransferProgressRes>({
|
||||
method: 'setup.recovery.status',
|
||||
params: {}
|
||||
})
|
||||
}
|
||||
|
||||
async getDrives() {
|
||||
async getDrives () {
|
||||
return this.http.rpcRequest<DiskInfo[]>({
|
||||
method: 'setup.disk.list',
|
||||
params: {}
|
||||
})
|
||||
}
|
||||
|
||||
async verifyRecoveryPassword(logicalname, password) {
|
||||
async verifyRecoveryPassword (logicalname: string, password: string) {
|
||||
return this.http.rpcRequest<boolean>({
|
||||
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<SetupEmbassyRes>({
|
||||
method: 'setup.execute',
|
||||
params: setupInfo
|
||||
|
||||
@@ -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' }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user