mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
update bootstrapper and startup flow
This commit is contained in:
committed by
Aiden McClelland
parent
f364202ae9
commit
12c44565ff
@@ -8,6 +8,7 @@ import { RR } from './api-types'
|
||||
import { parsePropertiesPermissive } from 'src/app/util/properties.util'
|
||||
import { Mock } from './mock-app-fixures'
|
||||
import { HttpService } from '../http.service'
|
||||
import { ConfigService } from '../config.service'
|
||||
|
||||
@Injectable()
|
||||
export class MockApiService extends ApiService {
|
||||
@@ -36,40 +37,40 @@ export class MockApiService extends ApiService {
|
||||
// db
|
||||
|
||||
async getRevisions (since: number): Promise<RR.GetRevisionsRes> {
|
||||
await pauseFor(2000)
|
||||
return {
|
||||
...Mock.DbDump,
|
||||
id: this.nextSequence(),
|
||||
}
|
||||
// return this.http.rpcRequest({ method: 'db.revisions', params: { since } })
|
||||
// await pauseFor(2000)
|
||||
// return {
|
||||
// ...Mock.DbDump,
|
||||
// id: this.nextSequence(),
|
||||
// }
|
||||
return this.http.rpcRequest({ method: 'db.revisions', params: { since } })
|
||||
}
|
||||
|
||||
async getDump (): Promise<RR.GetDumpRes> {
|
||||
await pauseFor(2000)
|
||||
return {
|
||||
...Mock.DbDump,
|
||||
id: this.nextSequence(),
|
||||
}
|
||||
// return this.http.rpcRequest({ method: 'db.dump' })
|
||||
// await pauseFor(2000)
|
||||
// return {
|
||||
// ...Mock.DbDump,
|
||||
// id: this.nextSequence(),
|
||||
// }
|
||||
return this.http.rpcRequest({ method: 'db.dump' })
|
||||
}
|
||||
|
||||
async setDbValueRaw (params: RR.SetDBValueReq): Promise<RR.SetDBValueRes> {
|
||||
await pauseFor(2000)
|
||||
return {
|
||||
response: null,
|
||||
revision: {
|
||||
id: this.nextSequence(),
|
||||
patch: [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: params.pointer,
|
||||
value: params.value,
|
||||
},
|
||||
],
|
||||
expireId: null,
|
||||
},
|
||||
}
|
||||
// return this.http.rpcRequest({ method: 'db.put.ui', params })
|
||||
// await pauseFor(2000)
|
||||
// return {
|
||||
// response: null,
|
||||
// revision: {
|
||||
// id: this.nextSequence(),
|
||||
// patch: [
|
||||
// {
|
||||
// op: PatchOp.REPLACE,
|
||||
// path: params.pointer,
|
||||
// value: params.value,
|
||||
// },
|
||||
// ],
|
||||
// expireId: null,
|
||||
// },
|
||||
// }
|
||||
return this.http.rpcRequest({ method: 'db.put.ui', params })
|
||||
}
|
||||
|
||||
// auth
|
||||
|
||||
@@ -19,19 +19,11 @@ export class AuthService {
|
||||
constructor (
|
||||
private readonly api: ApiService,
|
||||
private readonly storage: Storage,
|
||||
) {
|
||||
this.storage.create()
|
||||
}
|
||||
) { }
|
||||
|
||||
async init (): Promise<AuthState> {
|
||||
async init (): Promise<void> {
|
||||
const loggedIn = await this.storage.get(StorageKeys.LOGGED_IN_KEY)
|
||||
if (loggedIn) {
|
||||
this.authState$.next(AuthState.VERIFIED)
|
||||
return AuthState.VERIFIED
|
||||
} else {
|
||||
this.authState$.next(AuthState.UNVERIFIED)
|
||||
return AuthState.UNVERIFIED
|
||||
}
|
||||
this.authState$.next( loggedIn ? AuthState.VERIFIED : AuthState.UNVERIFIED)
|
||||
}
|
||||
|
||||
watch$ (): Observable<AuthState> {
|
||||
|
||||
@@ -11,14 +11,15 @@ import { Revision } from 'patch-db-client'
|
||||
export class HttpService {
|
||||
private unauthorizedApiResponse$ = new Subject()
|
||||
authReqEnabled: boolean = false
|
||||
rootUrl: string
|
||||
fullUrl: string
|
||||
|
||||
constructor (
|
||||
private readonly http: HttpClient,
|
||||
private readonly config: ConfigService,
|
||||
) {
|
||||
const { url, version } = this.config.api
|
||||
this.rootUrl = `${url}/${version}`
|
||||
const port = config.mocks.enabled ? this.config.mocks.rpcPort : window.location.port
|
||||
this.fullUrl = `${window.location.protocol}//${window.location.hostname}:${port}/${url}/${version}`
|
||||
}
|
||||
|
||||
watch401$ (): Observable<{ }> {
|
||||
@@ -41,16 +42,14 @@ export class HttpService {
|
||||
}
|
||||
|
||||
async httpRequest<T> (httpOpts: HttpOptions): Promise<T> {
|
||||
let { url, body, timeout, ...rest} = translateOptions(httpOpts)
|
||||
url = this.rootUrl + url
|
||||
|
||||
let { body, timeout, ...rest} = this.translateOptions(httpOpts)
|
||||
let req: Observable<{ body: T }>
|
||||
switch (httpOpts.method){
|
||||
case Method.GET: req = this.http.get(url, rest) as any; break
|
||||
case Method.POST: req = this.http.post(url, body, rest) as any; break
|
||||
case Method.PUT: req = this.http.put(url, body, rest) as any; break
|
||||
case Method.PATCH: req = this.http.patch(url, body, rest) as any; break
|
||||
case Method.DELETE: req = this.http.delete(url, rest) as any; break
|
||||
case Method.GET: req = this.http.get(this.fullUrl, rest) as any; break
|
||||
case Method.POST: req = this.http.post(this.fullUrl, body, rest) as any; break
|
||||
case Method.PUT: req = this.http.put(this.fullUrl, body, rest) as any; break
|
||||
case Method.PATCH: req = this.http.patch(this.fullUrl, body, rest) as any; break
|
||||
case Method.DELETE: req = this.http.delete(this.fullUrl, rest) as any; break
|
||||
}
|
||||
|
||||
return (timeout ? withTimeout(req, timeout) : req)
|
||||
@@ -58,6 +57,20 @@ export class HttpService {
|
||||
.then(res => res.body)
|
||||
.catch(e => { throw new HttpError(e) })
|
||||
}
|
||||
|
||||
translateOptions (httpOpts: HttpOptions): HttpJsonOptions {
|
||||
return {
|
||||
observe: 'events',
|
||||
responseType: 'json',
|
||||
reportProgress: false,
|
||||
withCredentials: this.config.mocks.enabled ? false : true,
|
||||
headers: httpOpts.headers,
|
||||
params: httpOpts.params,
|
||||
body: httpOpts.data || { },
|
||||
url: httpOpts.url,
|
||||
timeout: httpOpts.readTimeout,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function RpcError (e: RPCError['error']): void {
|
||||
@@ -167,20 +180,6 @@ export interface HttpJsonOptions {
|
||||
timeout: number
|
||||
}
|
||||
|
||||
function translateOptions (httpOpts: HttpOptions): HttpJsonOptions {
|
||||
return {
|
||||
observe: 'events',
|
||||
responseType: 'json',
|
||||
reportProgress: false,
|
||||
withCredentials: true,
|
||||
headers: httpOpts.headers,
|
||||
params: httpOpts.params,
|
||||
body: httpOpts.data || { },
|
||||
url: httpOpts.url,
|
||||
timeout: httpOpts.readTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
function withTimeout<U> (req: Observable<U>, timeout: number): Observable<U> {
|
||||
return race(
|
||||
from(req.toPromise()), // this guarantees it only emits on completion, intermediary emissions are suppressed.
|
||||
|
||||
Reference in New Issue
Block a user