import { Injectable } from '@angular/core' import { HttpService, Method } from '../../http.service' import { ApiService } from './embassy-api.service' import { RR } from '../api.types' import { parsePropertiesPermissive } from 'src/app/util/properties.util' import { ConfigService } from '../../config.service' @Injectable() export class LiveApiService extends ApiService { constructor ( private readonly http: HttpService, private readonly config: ConfigService, ) { super() } async getStatic (url: string): Promise { return this.http.httpRequest({ method: Method.GET, url }) } // db async getRevisions (since: number): Promise { return this.http.rpcRequest({ method: 'db.revisions', params: { since } }) } async getDump (): Promise { return this.http.rpcRequest({ method: 'db.dump' }) } async setDbValueRaw (params: RR.SetDBValueReq): Promise { return this.http.rpcRequest({ method: 'db.put.ui', params }) } // auth async login (params: RR.LoginReq): Promise { return this.http.rpcRequest({ method: 'auth.login', params }) } async logout (params: RR.LogoutReq): Promise { return this.http.rpcRequest({ method: 'auth.logout', params }) } // server async getServerLogs (params: RR.GetServerLogsReq): Promise { return this.http.rpcRequest( { method: 'server.logs', params }) } async getServerMetrics (params: RR.GetServerMetricsReq): Promise { return this.http.rpcRequest({ method: 'server.metrics', params }) } async updateServerRaw (params: RR.UpdateServerReq): Promise { return this.http.rpcRequest({ method: 'server.update', params }) } async restartServer (params: RR.RestartServerReq): Promise { return this.http.rpcRequest({ method: 'server.restart', params }) } async shutdownServer (params: RR.ShutdownServerReq): Promise { return this.http.rpcRequest({ method: 'server.shutdown', params }) } // network async refreshLan (params: RR.RefreshLanReq): Promise { return this.http.rpcRequest({ method: 'network.lan.refresh', params }) } // marketplace URLs async setEosMarketplaceRaw (isTor: boolean): Promise { const params: RR.SetEosMarketplaceReq = { url: isTor ? this.config.start9Marketplace.tor : this.config.start9Marketplace.clearnet, } return this.http.rpcRequest({ method: 'marketplace.eos.set', params }) } async setPackageMarketplaceRaw (params: RR.SetPackageMarketplaceReq): Promise { return this.http.rpcRequest({ method: 'marketplace.package.set', params }) } // password async updatePassword (params: RR.UpdatePasswordReq): Promise { return this.http.rpcRequest({ method: 'password.set', params }) } // notification async getNotificationsRaw (params: RR.GetNotificationsReq): Promise { return this.http.rpcRequest({ method: 'notifications.list', params }) } async deleteNotification (params: RR.DeleteNotificationReq): Promise { return this.http.rpcRequest({ method: 'notifications.delete', params }) } // wifi async addWifi (params: RR.AddWifiReq): Promise { return this.http.rpcRequest({ method: 'wifi.add', params }) } async connectWifiRaw (params: RR.ConnectWifiReq): Promise { return this.http.rpcRequest({ method: 'wifi.connect', params }) } async deleteWifiRaw (params: RR.DeleteWifiReq): Promise { return this.http.rpcRequest({ method: 'wifi.delete', params }) } // ssh async getSshKeys (params: RR.GetSSHKeysReq): Promise { return this.http.rpcRequest({ method: 'ssh.get', params }) } async addSshKey (params: RR.AddSSHKeyReq): Promise { return this.http.rpcRequest({ method: 'ssh.add', params }) } async deleteSshKey (params: RR.DeleteSSHKeyReq): Promise { return this.http.rpcRequest({ method: 'ssh.delete', params }) } // backup async createBackupRaw (params: RR.CreateBackupReq): Promise { return this.http.rpcRequest({ method: 'backup.create', params }) } async restoreBackupRaw (params: RR.RestoreBackupReq): Promise { return this.http.rpcRequest({ method: 'backup.restore', params }) } // disk getDisks (params: RR.GetDisksReq): Promise { return this.http.rpcRequest({ method: 'disk.list', params }) } ejectDisk (params: RR.EjectDisksReq): Promise { return this.http.rpcRequest({ method: 'disk.eject', params }) } // package async getPackageProperties (params: RR.GetPackagePropertiesReq): Promise['data']> { return this.http.rpcRequest({ method: 'package.properties', params }) .then(parsePropertiesPermissive) } async getPackageLogs (params: RR.GetPackageLogsReq): Promise { return this.http.rpcRequest( { method: 'package.logs', params }) } async getPkgMetrics (params: RR.GetPackageMetricsReq): Promise { return this.http.rpcRequest({ method: 'package.metrics', params }) } async installPackageRaw (params: RR.InstallPackageReq): Promise { return this.http.rpcRequest({ method: 'package.install', params }) } async dryUpdatePackage (params: RR.DryUpdatePackageReq): Promise { return this.http.rpcRequest({ method: 'package.update.dry', params }) } async getPackageConfig (params: RR.GetPackageConfigReq): Promise { return this.http.rpcRequest({ method: 'package.config.get', params }) } async drySetPackageConfig (params: RR.DrySetPackageConfigReq): Promise { return this.http.rpcRequest({ method: 'package.config.set.dry', params }) } async setPackageConfigRaw (params: RR.SetPackageConfigReq): Promise { return this.http.rpcRequest({ method: 'package.config.set', params }) } async restorePackageRaw (params: RR.RestorePackageReq): Promise { return this.http.rpcRequest({ method: 'package.restore', params }) } async executePackageAction (params: RR.ExecutePackageActionReq): Promise { return this.http.rpcRequest({ method: 'package.action', params }) } async startPackageRaw (params: RR.StartPackageReq): Promise { return this.http.rpcRequest({ method: 'package.start', params }) } async dryStopPackage (params: RR.DryStopPackageReq): Promise { return this.http.rpcRequest({ method: 'package.stop.dry', params }) } async stopPackageRaw (params: RR.StopPackageReq): Promise { return this.http.rpcRequest({ method: 'package.stop', params }) } async dryRemovePackage (params: RR.DryRemovePackageReq): Promise { return this.http.rpcRequest({ method: 'package.remove.dry', params }) } async removePackageRaw (params: RR.RemovePackageReq): Promise { return this.http.rpcRequest({ method: 'package.remove', params }) } async dryConfigureDependency (params: RR.DryConfigureDependencyReq): Promise { return this.http.rpcRequest({ method: 'package.dependency.configure.dry', params }) } }