import { Injectable } from '@angular/core' import { HttpService, isRpcError, RpcError, RPCOptions, } from '@start9labs/shared' import { ApiService, GetErrorRes } from './api.service' import { LogsRes, ServerLogsReq } from '@start9labs/shared' @Injectable() export class LiveApiService implements ApiService { constructor(private readonly http: HttpService) {} async getError(): Promise { return this.rpcRequest({ method: 'diagnostic.error', params: {}, }) } async restart(): Promise { return this.rpcRequest({ method: 'diagnostic.restart', params: {}, }) } async forgetDrive(): Promise { return this.rpcRequest({ method: 'diagnostic.disk.forget', params: {}, }) } async repairDisk(): Promise { return this.rpcRequest({ method: 'diagnostic.disk.repair', params: {}, }) } async systemRebuild(): Promise { return this.rpcRequest({ method: 'diagnostic.rebuild', params: {}, }) } async getLogs(params: ServerLogsReq): Promise { return this.rpcRequest({ method: 'diagnostic.logs', params, }) } private async rpcRequest(opts: RPCOptions): Promise { const res = await this.http.rpcRequest(opts) const rpcRes = res.body if (isRpcError(rpcRes)) { throw new RpcError(rpcRes.error) } return rpcRes.result } }