address comments and more

This commit is contained in:
Matt Hill
2024-08-15 08:05:37 -06:00
parent a730543c76
commit 015131f198
24 changed files with 316 additions and 396 deletions

View File

@@ -2,9 +2,7 @@ import * as jose from 'node-jose'
import {
DiskInfo,
DiskListResponse,
FollowLogsReq,
FollowLogsRes,
Log,
PartitionInfo,
StartOSDiskInfo,
} from '@start9labs/shared'
@@ -25,11 +23,8 @@ export abstract class ApiService {
abstract execute(setupInfo: T.SetupExecuteParams): Promise<T.SetupProgress> // setup.execute
abstract complete(): Promise<T.SetupResult> // setup.complete
abstract exit(): Promise<void> // setup.exit
abstract followServerLogs(params: FollowLogsReq): Promise<FollowLogsRes> // setup.logs.follow
abstract openLogsWebsocket$(
config: WebSocketSubjectConfig<Log>,
): Observable<Log>
abstract openProgressWebsocket$(guid: string): Observable<T.FullProgress>
abstract followServerLogs(): Promise<FollowLogsRes> // setup.logs.follow
abstract openWebsocket$<T>(guid: string): Observable<T>
async encrypt(toEncrypt: string): Promise<T.EncryptedWire> {
if (!this.pubkey) throw new Error('No pubkey found!')

View File

@@ -3,11 +3,9 @@ import { Inject, Injectable } from '@angular/core'
import {
DiskListResponse,
encodeBase64,
FollowLogsReq,
FollowLogsRes,
HttpService,
isRpcError,
Log,
RpcError,
RPCOptions,
StartOSDiskInfo,
@@ -15,7 +13,7 @@ import {
import { T } from '@start9labs/start-sdk'
import * as jose from 'node-jose'
import { Observable } from 'rxjs'
import { webSocket, WebSocketSubjectConfig } from 'rxjs/webSocket'
import { webSocket } from 'rxjs/webSocket'
import { ApiService } from './api.service'
@Injectable({
@@ -29,12 +27,13 @@ export class LiveApiService extends ApiService {
super()
}
openProgressWebsocket$(guid: string): Observable<T.FullProgress> {
openWebsocket$<T>(guid: string): Observable<T> {
const { location } = this.document.defaultView!
const protocol = location.protocol === 'http:' ? 'ws' : 'wss'
const host = location.host
return webSocket({
url: `ws://${host}/ws/rpc/${guid}`,
url: `${protocol}://${host}/ws/rpc/${guid}`,
})
}
@@ -99,12 +98,8 @@ export class LiveApiService extends ApiService {
})
}
async followServerLogs(params: FollowLogsReq): Promise<FollowLogsRes> {
return this.rpcRequest({ method: 'setup.logs.follow', params })
}
openLogsWebsocket$({ url }: WebSocketSubjectConfig<Log>): Observable<Log> {
return webSocket(`http://start.local/ws/${url}`)
async followServerLogs(): Promise<FollowLogsRes> {
return this.rpcRequest({ method: 'setup.logs.follow', params: {} })
}
async complete(): Promise<T.SetupResult> {

View File

@@ -2,16 +2,13 @@ import { Injectable } from '@angular/core'
import {
DiskListResponse,
encodeBase64,
FollowLogsReq,
FollowLogsRes,
Log,
pauseFor,
StartOSDiskInfo,
} from '@start9labs/shared'
import { T } from '@start9labs/start-sdk'
import * as jose from 'node-jose'
import { interval, map, Observable, of } from 'rxjs'
import { WebSocketSubjectConfig } from 'rxjs/webSocket'
import { interval, map, Observable } from 'rxjs'
import { ApiService } from './api.service'
@Injectable({
@@ -47,68 +44,102 @@ export class MockApiService extends ApiService {
// websocket
openProgressWebsocket$(guid: string): Observable<T.FullProgress> {
return of(PROGRESS)
// const numPhases = PROGRESS.phases.length
// oldMockProgress$(): Promise<T.FullProgress> {
// const numPhases = PROGRESS.phases.length
// return of(PROGRESS).pipe(
// switchMap(full =>
// from(PROGRESS.phases).pipe(
// mergeScan((full, phase, i) => {
// if (
// !phase.progress ||
// typeof phase.progress !== 'object' ||
// !phase.progress.total
// ) {
// full.phases[i].progress = true
// return of(PROGRESS).pipe(
// switchMap(full =>
// from(PROGRESS.phases).pipe(
// mergeScan((full, phase, i) => {
// if (
// !phase.progress ||
// typeof phase.progress !== 'object' ||
// !phase.progress.total
// ) {
// full.phases[i].progress = true
// if (
// full.overall &&
// typeof full.overall === 'object' &&
// full.overall.total
// ) {
// const step = full.overall.total / numPhases
// full.overall.done += step
// }
// if (
// full.overall &&
// typeof full.overall === 'object' &&
// full.overall.total
// ) {
// const step = full.overall.total / numPhases
// full.overall.done += step
// }
// return of(full).pipe(delay(2000))
// } else {
// const total = phase.progress.total
// const step = total / 4
// let done = phase.progress.done
// return of(full).pipe(delay(2000))
// } else {
// const total = phase.progress.total
// const step = total / 4
// let done = phase.progress.done
// return interval(1000).pipe(
// takeWhile(() => done < total),
// map(() => {
// done += step
// return interval(1000).pipe(
// takeWhile(() => done < total),
// map(() => {
// done += step
// console.error(done)
// console.error(done)
// if (
// full.overall &&
// typeof full.overall === 'object' &&
// full.overall.total
// ) {
// const step = full.overall.total / numPhases / 4
// if (
// full.overall &&
// typeof full.overall === 'object' &&
// full.overall.total
// ) {
// const step = full.overall.total / numPhases / 4
// full.overall.done += step
// }
// full.overall.done += step
// }
// if (done === total) {
// full.phases[i].progress = true
// if (done === total) {
// full.phases[i].progress = true
// if (i === numPhases - 1) {
// full.overall = true
// }
// }
// return full
// }),
// )
// }
// }, full),
// ),
// ),
// )
// if (i === numPhases - 1) {
// full.overall = true
// }
// }
// return full
// }),
// )
// }
// }, full),
// ),
// ),
// )
// }
openWebsocket$<T>(guid: string): Observable<T> {
if (guid === 'logs-guid') {
return interval(500).pipe(
map(() => ({
timestamp: new Date().toISOString(),
message: 'fake log entry',
bootId: 'boot-id',
})),
) as Observable<T>
} else if (guid === 'progress-guid') {
// @TODO mock progress
return interval(1000).pipe(
map(() => ({
overall: true,
phases: [
{
name: 'Preparing Data',
progress: true,
},
{
name: 'Transferring Data',
progress: true,
},
{
name: 'Finalizing Setup',
progress: true,
},
],
})),
) as Observable<T>
} else {
throw new Error('invalid guid type')
}
}
private statusIndex = 0
@@ -270,24 +301,14 @@ export class MockApiService extends ApiService {
}
}
async followServerLogs(params: FollowLogsReq): Promise<FollowLogsRes> {
async followServerLogs(): Promise<FollowLogsRes> {
await pauseFor(1000)
return {
startCursor: 'fakestartcursor',
guid: 'fake-guid',
guid: 'logs-guid',
}
}
openLogsWebsocket$(config: WebSocketSubjectConfig<Log>): Observable<Log> {
return interval(500).pipe(
map(() => ({
timestamp: new Date().toISOString(),
message: 'fake log entry',
bootId: 'boot-id',
})),
)
}
async complete(): Promise<T.SetupResult> {
await pauseFor(1000)
return {