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) {} getError(): Promise { return this.rpcRequest({ method: 'diagnostic.error', params: {}, }) } restart(): Promise { return this.rpcRequest({ method: 'diagnostic.restart', params: {}, }) } forgetDrive(): Promise { return this.rpcRequest({ method: 'diagnostic.disk.forget', params: {}, }) } repairDisk(): Promise { return this.rpcRequest({ method: 'diagnostic.disk.repair', params: {}, }) } 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 } }