mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-02 05:23:14 +00:00
remove product key from setup flow (#1750)
* remove product key flow from setup * feat: backend turned off encryption + new Id + no package id * implement new encryption scheme in FE * decode response string * crypto not working * update setup wizard closes #1762 * feat: Get the encryption key * fix: Get to recovery * remove old code * fix build * fix: Install works for now * fix bug in config for adding new list items * dismiss action modal on success * clear button in config * wip: Currently broken in avahi mdns * include headers with req/res and refactor patchDB init and usage * fix: Can now run in the main * flatline on failed init * update patch DB * add last-wifi-region to data model even though not used by FE * chore: Fix the start. * wip: Fix wrong order for getting hostname before sql has been created * fix edge case where union keys displayed as new when not new * fix: Can start * last backup color, markdown links always new tab, fix bug with login * refactor to remove WithRevision * resolve circular dep issue * update submodule * fix patch-db * update patchDB * update patch again * escape error * decodeuricomponent * increase proxy buffer size * increase proxy buffer size * fix nginx Co-authored-by: BluJ <mogulslayer@gmail.com> Co-authored-by: BluJ <dragondef@gmail.com> Co-authored-by: Aiden McClelland <me@drbonez.dev>
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
import { Inject, Injectable } from '@angular/core'
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'
|
||||
import { HttpError, RpcError, WorkspaceConfig } from '@start9labs/shared'
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { HttpError } from '../classes/http-error'
|
||||
import {
|
||||
HttpAngularOptions,
|
||||
HttpOptions,
|
||||
LocalHttpResponse,
|
||||
Method,
|
||||
} from '../types/http.types'
|
||||
import { RPCResponse, RPCOptions } from '../types/rpc.types'
|
||||
import { WorkspaceConfig } from '../types/workspace-config'
|
||||
import {
|
||||
firstValueFrom,
|
||||
from,
|
||||
@@ -32,20 +40,21 @@ export class HttpService {
|
||||
this.fullUrl = `${protocol}//${hostname}:${port}`
|
||||
}
|
||||
|
||||
async rpcRequest<T>(opts: RPCOptions): Promise<T> {
|
||||
const { method, params, timeout } = opts
|
||||
async rpcRequest<T>(
|
||||
opts: RPCOptions,
|
||||
): Promise<LocalHttpResponse<RPCResponse<T>>> {
|
||||
const { method, headers, params, timeout } = opts
|
||||
|
||||
const res = await this.httpRequest<RPCResponse<T>>({
|
||||
return this.httpRequest<RPCResponse<T>>({
|
||||
method: Method.POST,
|
||||
url: this.relativeUrl,
|
||||
headers,
|
||||
body: { method, params },
|
||||
timeout,
|
||||
})
|
||||
if (isRpcError(res)) throw new RpcError(res.error)
|
||||
return res.result
|
||||
}
|
||||
|
||||
async httpRequest<T>(opts: HttpOptions): Promise<T> {
|
||||
async httpRequest<T>(opts: HttpOptions): Promise<LocalHttpResponse<T>> {
|
||||
let { method, url, headers, body, responseType, timeout } = opts
|
||||
|
||||
url = opts.url.startsWith('/') ? this.fullUrl + url : url
|
||||
@@ -67,113 +76,21 @@ export class HttpService {
|
||||
responseType: responseType || 'json',
|
||||
}
|
||||
|
||||
let req: Observable<{ body: T }>
|
||||
let req: Observable<LocalHttpResponse<T>>
|
||||
if (method === Method.GET) {
|
||||
req = this.http.get(url, options as any) as any
|
||||
} else {
|
||||
req = this.http.post(url, body, options as any) as any
|
||||
}
|
||||
|
||||
return firstValueFrom(timeout ? withTimeout(req, timeout) : req)
|
||||
.then(res => res.body)
|
||||
.catch(e => {
|
||||
return firstValueFrom(timeout ? withTimeout(req, timeout) : req).catch(
|
||||
e => {
|
||||
throw new HttpError(e)
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// ** RPC types **
|
||||
|
||||
interface RPCBase {
|
||||
jsonrpc: '2.0'
|
||||
id: string
|
||||
}
|
||||
|
||||
export interface RPCRequest<T> extends RPCBase {
|
||||
method: string
|
||||
params?: T
|
||||
}
|
||||
|
||||
export interface RPCSuccess<T> extends RPCBase {
|
||||
result: T
|
||||
}
|
||||
|
||||
export interface RPCError extends RPCBase {
|
||||
error: {
|
||||
code: number
|
||||
message: string
|
||||
data?:
|
||||
| {
|
||||
details: string
|
||||
}
|
||||
| string
|
||||
}
|
||||
}
|
||||
|
||||
export type RPCResponse<T> = RPCSuccess<T> | RPCError
|
||||
|
||||
export interface RPCOptions {
|
||||
method: string
|
||||
params: {
|
||||
[param: string]:
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| object
|
||||
| string[]
|
||||
| number[]
|
||||
| null
|
||||
}
|
||||
timeout?: number
|
||||
}
|
||||
|
||||
export function isRpcError<Error, Result>(
|
||||
arg: { error: Error } | { result: Result },
|
||||
): arg is { error: Error } {
|
||||
return (arg as any).error !== undefined
|
||||
}
|
||||
|
||||
// ** HTTP types **
|
||||
|
||||
export enum Method {
|
||||
GET = 'GET',
|
||||
POST = 'POST',
|
||||
}
|
||||
|
||||
export interface HttpOptions {
|
||||
method: Method
|
||||
url: string
|
||||
headers?:
|
||||
| HttpHeaders
|
||||
| {
|
||||
[header: string]: string | string[]
|
||||
}
|
||||
params?:
|
||||
| HttpParams
|
||||
| {
|
||||
[param: string]: string | string[]
|
||||
}
|
||||
responseType?: 'json' | 'text' | 'arrayBuffer'
|
||||
body?: any
|
||||
timeout?: number
|
||||
}
|
||||
|
||||
interface HttpAngularOptions {
|
||||
observe: 'response'
|
||||
withCredentials: true
|
||||
headers?:
|
||||
| HttpHeaders
|
||||
| {
|
||||
[header: string]: string | string[]
|
||||
}
|
||||
params?:
|
||||
| HttpParams
|
||||
| {
|
||||
[param: string]: string | string[]
|
||||
}
|
||||
responseType?: 'json' | 'text' | 'arrayBuffer'
|
||||
}
|
||||
|
||||
function hasParams(
|
||||
params?: HttpOptions['params'],
|
||||
): params is Record<string, string | string[]> {
|
||||
@@ -191,9 +108,3 @@ function withTimeout<U>(req: Observable<U>, timeout: number): Observable<U> {
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
export interface RequestError {
|
||||
code: number
|
||||
message: string
|
||||
details: string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user