mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 04:01:58 +00:00
UI/feature/enable disable lan (#192)
* ui: skip startup notifications in mocks * ui: enable-disable lan toggle in ui * ui: remove this.lanAddress for this.app.lanAddress
This commit is contained in:
committed by
Aiden McClelland
parent
a20970fa17
commit
5cf7d1ff88
@@ -20,6 +20,7 @@ export abstract class ApiService {
|
||||
this.$unauthorizedApiResponse$.next()
|
||||
}
|
||||
|
||||
abstract testConnection (url: string): Promise<true>
|
||||
abstract getCheckAuth (): Promise<Unit> // Throws an error on failed auth.
|
||||
abstract postLogin (password: string): Promise<Unit> // Throws an error on failed auth.
|
||||
abstract postLogout (): Promise<Unit> // Throws an error on failed auth.
|
||||
@@ -28,6 +29,7 @@ export abstract class ApiService {
|
||||
abstract getServerMetrics (): Promise<ReqRes.GetServerMetricsRes>
|
||||
abstract getNotifications (page: number, perPage: number): Promise<S9Notification[]>
|
||||
abstract deleteNotification (id: string): Promise<Unit>
|
||||
abstract toggleAppLAN (appId: string, toggle: 'enable' | 'disable'): Promise<Unit>
|
||||
abstract updateAgent (version: any): Promise<Unit>
|
||||
abstract acknowledgeOSWelcome (version: string): Promise<Unit>
|
||||
abstract getAvailableApps (): Promise<AppAvailablePreview[]>
|
||||
|
||||
@@ -5,11 +5,13 @@ import { AppAvailablePreview, AppAvailableFull, AppInstalledFull, AppInstalledPr
|
||||
import { S9Notification, SSHFingerprint, ServerModel, DiskInfo } from '../../models/server-model'
|
||||
import { ApiService, ReqRes } from './api.service'
|
||||
import { ApiServer, Unit } from './api-types'
|
||||
import { HttpErrorResponse } from '@angular/common/http'
|
||||
import { HttpClient, HttpErrorResponse } from '@angular/common/http'
|
||||
import { isUnauthorized } from 'src/app/util/web.util'
|
||||
import { Replace } from 'src/app/util/types.util'
|
||||
import { AppMetrics, parseMetricsPermissive } from 'src/app/util/metrics.util'
|
||||
import { modulateTime } from 'src/app/util/misc.util'
|
||||
import { Observable, of, throwError } from 'rxjs'
|
||||
import { catchError, mapTo } from 'rxjs/operators'
|
||||
|
||||
@Injectable()
|
||||
export class LiveApiService extends ApiService {
|
||||
@@ -20,6 +22,10 @@ export class LiveApiService extends ApiService {
|
||||
private readonly serverModel: ServerModel,
|
||||
) { super() }
|
||||
|
||||
testConnection (url: string): Promise<true> {
|
||||
return this.http.raw.get(url).pipe(mapTo(true as true), catchError(e => catchHttpStatusError(e))).toPromise()
|
||||
}
|
||||
|
||||
// Used to check whether password or key is valid. If so, it will be used implicitly by all other calls.
|
||||
async getCheckAuth (): Promise<Unit> {
|
||||
return this.http.serverRequest<Unit>({ method: Method.GET, url: '/authenticate' }, { version: '' })
|
||||
@@ -214,6 +220,10 @@ export class LiveApiService extends ApiService {
|
||||
})
|
||||
}
|
||||
|
||||
async toggleAppLAN (appId: string, toggle: 'enable' | 'disable'): Promise<Unit> {
|
||||
return this.authRequest({ method: Method.POST, url: `/apps/${appId}/lan/${toggle}` })
|
||||
}
|
||||
|
||||
async addSSHKey (sshKey: string): Promise<Unit> {
|
||||
const data: ReqRes.PostAddSSHKeyReq = {
|
||||
sshKey,
|
||||
@@ -275,3 +285,11 @@ const dryRunParam = (dryRun: boolean, first: boolean) => {
|
||||
return first ? `?dryrun` : `&dryrun`
|
||||
}
|
||||
|
||||
function catchHttpStatusError (error: HttpErrorResponse): Observable<true> {
|
||||
if (error.error instanceof ErrorEvent) {
|
||||
// A client-side or network error occurred. Handle it accordingly.
|
||||
return throwError('Not Connected')
|
||||
} else {
|
||||
return of(true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,18 @@ export class MockApiService extends ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
testCounter = 0
|
||||
async testConnection (): Promise<true> {
|
||||
console.log('testing connection')
|
||||
this.testCounter ++
|
||||
await pauseFor(1000)
|
||||
if (this.testCounter > 5) {
|
||||
return true
|
||||
} else {
|
||||
throw new Error('Not Connected')
|
||||
}
|
||||
}
|
||||
|
||||
async ejectExternalDisk (): Promise<Unit> {
|
||||
await pauseFor(2000)
|
||||
return { }
|
||||
@@ -144,6 +156,10 @@ export class MockApiService extends ApiService {
|
||||
return mockAppDependentBreakages
|
||||
}
|
||||
|
||||
async toggleAppLAN (appId: string, toggle: 'enable' | 'disable'): Promise<Unit> {
|
||||
return { }
|
||||
}
|
||||
|
||||
async restartApp (appId: string): Promise<Unit> {
|
||||
return { }
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ export function toInstalledPreview (f: AppInstalledFull): AppInstalledPreview {
|
||||
iconURL: f.iconURL,
|
||||
torAddress: f.torAddress,
|
||||
ui: f.ui,
|
||||
lanAddress: f.lanAddress,
|
||||
lanEnabled: f.lanEnabled,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,8 +49,10 @@ export function toServiceBreakage (f: BaseApp): DependentBreakage {
|
||||
export const bitcoinI: AppInstalledFull = {
|
||||
id: 'bitcoind',
|
||||
versionInstalled: '0.18.1',
|
||||
lanAddress: 'bitcoinLan.local',
|
||||
lanEnabled: true,
|
||||
title: 'Bitcoin Core',
|
||||
torAddress: 'sample-bitcoin-tor-address-and-some-more-tor-address.onion',
|
||||
torAddress: '4acth47i6kxnvkewtm6q7ib2s3ufpo5sqbsnzjpbi7utijcltosqemad.onion',
|
||||
status: AppStatus.STOPPED,
|
||||
iconURL: 'assets/img/service-icons/bitcoind.png',
|
||||
instructions: 'some instructions',
|
||||
@@ -61,10 +65,12 @@ export const bitcoinI: AppInstalledFull = {
|
||||
|
||||
export const lightningI: AppInstalledFull = {
|
||||
id: 'c-lightning',
|
||||
lanAddress: 'lightningLan.local',
|
||||
lanEnabled: true,
|
||||
status: AppStatus.RUNNING,
|
||||
title: 'C Lightning',
|
||||
versionInstalled: '1.0.0',
|
||||
torAddress: 'sample-bitcoin-tor-address-and-some-more-tor-address.onion',
|
||||
torAddress: '4acth47i6kxnvkewtm6q7ib2s3ufpo5sqbsnzjpbi7utijcltosqemad.onion',
|
||||
iconURL: 'assets/img/service-icons/bitwarden.png',
|
||||
instructions: 'some instructions',
|
||||
lastBackup: new Date().toISOString(),
|
||||
@@ -84,6 +90,8 @@ export const lightningI: AppInstalledFull = {
|
||||
|
||||
export const cupsI: AppInstalledFull = {
|
||||
id: 'cups',
|
||||
lanAddress: 'cupsLan.local',
|
||||
lanEnabled: false,
|
||||
versionInstalled: '2.1.0',
|
||||
title: 'Cups Messenger',
|
||||
torAddress: 'sample-cups-tor-address.onion',
|
||||
|
||||
Reference in New Issue
Block a user