mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-01 21:13:09 +00:00
* rename frontend to web and update contributing guide * rename this time * fix build * restructure rust code * update documentation * update descriptions * Update CONTRIBUTING.md Co-authored-by: J H <2364004+Blu-J@users.noreply.github.com> --------- Co-authored-by: Aiden McClelland <me@drbonez.dev> Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com> Co-authored-by: J H <2364004+Blu-J@users.noreply.github.com>
69 lines
1.5 KiB
TypeScript
69 lines
1.5 KiB
TypeScript
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<GetErrorRes> {
|
|
return this.rpcRequest<GetErrorRes>({
|
|
method: 'diagnostic.error',
|
|
params: {},
|
|
})
|
|
}
|
|
|
|
async restart(): Promise<void> {
|
|
return this.rpcRequest<void>({
|
|
method: 'diagnostic.restart',
|
|
params: {},
|
|
})
|
|
}
|
|
|
|
async forgetDrive(): Promise<void> {
|
|
return this.rpcRequest<void>({
|
|
method: 'diagnostic.disk.forget',
|
|
params: {},
|
|
})
|
|
}
|
|
|
|
async repairDisk(): Promise<void> {
|
|
return this.rpcRequest<void>({
|
|
method: 'diagnostic.disk.repair',
|
|
params: {},
|
|
})
|
|
}
|
|
|
|
async systemRebuild(): Promise<void> {
|
|
return this.rpcRequest<void>({
|
|
method: 'diagnostic.rebuild',
|
|
params: {},
|
|
})
|
|
}
|
|
|
|
async getLogs(params: ServerLogsReq): Promise<LogsRes> {
|
|
return this.rpcRequest<LogsRes>({
|
|
method: 'diagnostic.logs',
|
|
params,
|
|
})
|
|
}
|
|
|
|
private async rpcRequest<T>(opts: RPCOptions): Promise<T> {
|
|
const res = await this.http.rpcRequest<T>(opts)
|
|
|
|
const rpcRes = res.body
|
|
|
|
if (isRpcError(rpcRes)) {
|
|
throw new RpcError(rpcRes.error)
|
|
}
|
|
|
|
return rpcRes.result
|
|
}
|
|
}
|