mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
cancel old request and base interval on tor (#2439)
This commit is contained in:
@@ -4,7 +4,6 @@ import { ApiService } from 'src/app/services/api/embassy-api.service'
|
|||||||
import { AuthService } from 'src/app/services/auth.service'
|
import { AuthService } from 'src/app/services/auth.service'
|
||||||
import { Router } from '@angular/router'
|
import { Router } from '@angular/router'
|
||||||
import { ConfigService } from 'src/app/services/config.service'
|
import { ConfigService } from 'src/app/services/config.service'
|
||||||
import { pauseFor, RELATIVE_URL } from '@start9labs/shared'
|
|
||||||
import { DOCUMENT } from '@angular/common'
|
import { DOCUMENT } from '@angular/common'
|
||||||
import { WINDOW } from '@ng-web-apis/common'
|
import { WINDOW } from '@ng-web-apis/common'
|
||||||
|
|
||||||
@@ -18,58 +17,16 @@ export class LoginPage {
|
|||||||
unmasked = false
|
unmasked = false
|
||||||
error = ''
|
error = ''
|
||||||
|
|
||||||
downloadClicked = false
|
|
||||||
instructionsClicked = false
|
|
||||||
polling = false
|
|
||||||
caTrusted = false
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly router: Router,
|
private readonly router: Router,
|
||||||
private readonly authService: AuthService,
|
private readonly authService: AuthService,
|
||||||
private readonly loadingCtrl: LoadingController,
|
private readonly loadingCtrl: LoadingController,
|
||||||
private readonly api: ApiService,
|
private readonly api: ApiService,
|
||||||
public readonly config: ConfigService,
|
public readonly config: ConfigService,
|
||||||
@Inject(RELATIVE_URL) private readonly relativeUrl: string,
|
|
||||||
@Inject(DOCUMENT) public readonly document: Document,
|
@Inject(DOCUMENT) public readonly document: Document,
|
||||||
@Inject(WINDOW) private readonly windowRef: Window,
|
@Inject(WINDOW) private readonly windowRef: Window,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async ngOnInit() {
|
|
||||||
if (!this.config.isSecure()) {
|
|
||||||
await this.testHttps().catch(e =>
|
|
||||||
console.warn('Failed Https connection attempt'),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
download() {
|
|
||||||
this.downloadClicked = true
|
|
||||||
this.document.getElementById('install-cert')?.click()
|
|
||||||
}
|
|
||||||
|
|
||||||
instructions() {
|
|
||||||
this.windowRef.open(
|
|
||||||
'https://docs.start9.com/getting-started/trust-ca/#trust-your-server-s-root-ca',
|
|
||||||
'_blank',
|
|
||||||
'noreferrer',
|
|
||||||
)
|
|
||||||
this.instructionsClicked = true
|
|
||||||
this.startDaemon()
|
|
||||||
}
|
|
||||||
|
|
||||||
private async startDaemon(): Promise<void> {
|
|
||||||
this.polling = true
|
|
||||||
while (this.polling) {
|
|
||||||
try {
|
|
||||||
await this.testHttps()
|
|
||||||
this.polling = false
|
|
||||||
} catch (e) {
|
|
||||||
console.warn('Failed Https connection attempt')
|
|
||||||
await pauseFor(2000)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
launchHttps() {
|
launchHttps() {
|
||||||
const host = this.config.getHost()
|
const host = this.config.getHost()
|
||||||
this.windowRef.open(`https://${host}`, '_blank', 'noreferrer')
|
this.windowRef.open(`https://${host}`, '_blank', 'noreferrer')
|
||||||
@@ -104,13 +61,4 @@ export class LoginPage {
|
|||||||
loader.dismiss()
|
loader.dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async testHttps() {
|
|
||||||
const url = `https://${this.document.location.host}${this.relativeUrl}`
|
|
||||||
await this.api.echo({ message: 'ping' }, url).then(() => {
|
|
||||||
this.downloadClicked = true
|
|
||||||
this.instructionsClicked = true
|
|
||||||
this.caTrusted = true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export module RR {
|
|||||||
|
|
||||||
// server
|
// server
|
||||||
|
|
||||||
export type EchoReq = { message: string } // server.echo
|
export type EchoReq = { message: string; timeout?: number } // server.echo
|
||||||
export type EchoRes = string
|
export type EchoRes = string
|
||||||
|
|
||||||
export type GetSystemTimeReq = {} // server.time
|
export type GetSystemTimeReq = {} // server.time
|
||||||
|
|||||||
@@ -91,7 +91,11 @@ export class LiveApiService extends ApiService {
|
|||||||
// server
|
// server
|
||||||
|
|
||||||
async echo(params: RR.EchoReq, urlOverride?: string): Promise<RR.EchoRes> {
|
async echo(params: RR.EchoReq, urlOverride?: string): Promise<RR.EchoRes> {
|
||||||
return this.rpcRequest({ method: 'echo', params }, false, urlOverride)
|
return this.rpcRequest(
|
||||||
|
{ method: 'echo', params, timeout: 4000 },
|
||||||
|
false,
|
||||||
|
urlOverride,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
openPatchWebsocket$(): Observable<Update<DataModel>> {
|
openPatchWebsocket$(): Observable<Update<DataModel>> {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { defer, EMPTY, from, interval, merge, Observable } from 'rxjs'
|
|||||||
import { AuthService } from '../auth.service'
|
import { AuthService } from '../auth.service'
|
||||||
import { ConnectionService } from '../connection.service'
|
import { ConnectionService } from '../connection.service'
|
||||||
import { ApiService } from '../api/embassy-api.service'
|
import { ApiService } from '../api/embassy-api.service'
|
||||||
|
import { ConfigService } from '../config.service'
|
||||||
|
|
||||||
export const PATCH_SOURCE = new InjectionToken<Observable<Update<DataModel>[]>>(
|
export const PATCH_SOURCE = new InjectionToken<Observable<Update<DataModel>[]>>(
|
||||||
'',
|
'',
|
||||||
@@ -26,6 +27,9 @@ export function sourceFactory(
|
|||||||
const api = injector.get(ApiService)
|
const api = injector.get(ApiService)
|
||||||
const authService = injector.get(AuthService)
|
const authService = injector.get(AuthService)
|
||||||
const connectionService = injector.get(ConnectionService)
|
const connectionService = injector.get(ConnectionService)
|
||||||
|
const configService = injector.get(ConfigService)
|
||||||
|
const isTor = configService.isTor()
|
||||||
|
const timeout = isTor ? 16000 : 4000
|
||||||
|
|
||||||
const websocket$ = api.openPatchWebsocket$().pipe(
|
const websocket$ = api.openPatchWebsocket$().pipe(
|
||||||
bufferTime(250),
|
bufferTime(250),
|
||||||
@@ -33,9 +37,11 @@ export function sourceFactory(
|
|||||||
catchError((_, watch$) => {
|
catchError((_, watch$) => {
|
||||||
connectionService.websocketConnected$.next(false)
|
connectionService.websocketConnected$.next(false)
|
||||||
|
|
||||||
return interval(4000).pipe(
|
return interval(timeout).pipe(
|
||||||
switchMap(() =>
|
switchMap(() =>
|
||||||
from(api.echo({ message: 'ping' })).pipe(catchError(() => EMPTY)),
|
from(api.echo({ message: 'ping', timeout })).pipe(
|
||||||
|
catchError(() => EMPTY),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
take(1),
|
take(1),
|
||||||
switchMap(() => watch$),
|
switchMap(() => watch$),
|
||||||
|
|||||||
Reference in New Issue
Block a user