mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 14:29:45 +00:00
fixes issue with action
This commit is contained in:
committed by
Aiden McClelland
parent
2189c5643d
commit
4fcdf5f832
@@ -3,7 +3,7 @@ import { HttpService, Method, HttpOptions } from '../http.service'
|
|||||||
import { AppModel, AppStatus } from '../../models/app-model'
|
import { AppModel, AppStatus } from '../../models/app-model'
|
||||||
import { AppAvailablePreview, AppAvailableFull, AppInstalledFull, AppInstalledPreview, DependentBreakage, AppAvailableVersionSpecificInfo, ServiceAction } from '../../models/app-types'
|
import { AppAvailablePreview, AppAvailableFull, AppInstalledFull, AppInstalledPreview, DependentBreakage, AppAvailableVersionSpecificInfo, ServiceAction } from '../../models/app-types'
|
||||||
import { S9Notification, SSHFingerprint, ServerModel, DiskInfo } from '../../models/server-model'
|
import { S9Notification, SSHFingerprint, ServerModel, DiskInfo } from '../../models/server-model'
|
||||||
import { ApiService, ReqRes } from './api.service'
|
import { ApiService, ReqRes } from './api.service'
|
||||||
import { ApiServer, Unit } from './api-types'
|
import { ApiServer, Unit } from './api-types'
|
||||||
import { HttpClient, HttpErrorResponse } from '@angular/common/http'
|
import { HttpClient, HttpErrorResponse } from '@angular/common/http'
|
||||||
import { isUnauthorized } from 'src/app/util/web.util'
|
import { isUnauthorized } from 'src/app/util/web.util'
|
||||||
@@ -17,47 +17,47 @@ import { METHODS } from 'http'
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class LiveApiService extends ApiService {
|
export class LiveApiService extends ApiService {
|
||||||
constructor (
|
constructor(
|
||||||
private readonly http: HttpService,
|
private readonly http: HttpService,
|
||||||
// TODO remove app + server model from here. updates to state should be done in a separate class wrapping ApiService + App/ServerModel
|
// TODO remove app + server model from here. updates to state should be done in a separate class wrapping ApiService + App/ServerModel
|
||||||
private readonly appModel: AppModel,
|
private readonly appModel: AppModel,
|
||||||
private readonly serverModel: ServerModel,
|
private readonly serverModel: ServerModel,
|
||||||
) { super() }
|
) { super() }
|
||||||
|
|
||||||
testConnection (url: string): Promise<true> {
|
testConnection(url: string): Promise<true> {
|
||||||
return this.http.raw.get(url).pipe(mapTo(true as true), catchError(e => catchHttpStatusError(e))).toPromise()
|
return this.http.raw.get(url).pipe(mapTo(true as true), catchError(e => catchHttpStatusError(e))).toPromise()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used to check whether password or key is valid. If so, it will be used implicitly by all other calls.
|
// Used to check whether password or key is valid. If so, it will be used implicitly by all other calls.
|
||||||
async getCheckAuth (): Promise<Unit> {
|
async getCheckAuth(): Promise<Unit> {
|
||||||
return this.http.serverRequest<Unit>({ method: Method.GET, url: '/authenticate' }, { version: '' })
|
return this.http.serverRequest<Unit>({ method: Method.GET, url: '/authenticate' }, { version: '' })
|
||||||
}
|
}
|
||||||
|
|
||||||
async postLogin (password: string): Promise<Unit> {
|
async postLogin(password: string): Promise<Unit> {
|
||||||
return this.http.serverRequest<Unit>({ method: Method.POST, url: '/auth/login', data: { password } }, { version: '' })
|
return this.http.serverRequest<Unit>({ method: Method.POST, url: '/auth/login', data: { password } }, { version: '' })
|
||||||
}
|
}
|
||||||
|
|
||||||
async postLogout (): Promise<Unit> {
|
async postLogout(): Promise<Unit> {
|
||||||
return this.http.serverRequest<Unit>({ method: Method.POST, url: '/auth/logout' }, { version: '' }).then(() => { this.authenticatedRequestsEnabled = false; return { } })
|
return this.http.serverRequest<Unit>({ method: Method.POST, url: '/auth/logout' }, { version: '' }).then(() => { this.authenticatedRequestsEnabled = false; return {} })
|
||||||
}
|
}
|
||||||
|
|
||||||
async getServer (timeout?: number): Promise<ApiServer> {
|
async getServer(timeout?: number): Promise<ApiServer> {
|
||||||
return this.authRequest<ReqRes.GetServerRes>({ method: Method.GET, url: '/', readTimeout: timeout })
|
return this.authRequest<ReqRes.GetServerRes>({ method: Method.GET, url: '/', readTimeout: timeout })
|
||||||
}
|
}
|
||||||
|
|
||||||
async acknowledgeOSWelcome (version: string): Promise<Unit> {
|
async acknowledgeOSWelcome(version: string): Promise<Unit> {
|
||||||
return this.authRequest<Unit>({ method: Method.POST, url: `/welcome/${version}` })
|
return this.authRequest<Unit>({ method: Method.POST, url: `/welcome/${version}` })
|
||||||
}
|
}
|
||||||
|
|
||||||
async getVersionLatest (): Promise<ReqRes.GetVersionLatestRes> {
|
async getVersionLatest(): Promise<ReqRes.GetVersionLatestRes> {
|
||||||
return this.authRequest<ReqRes.GetVersionLatestRes>({ method: Method.GET, url: '/versionLatest' }, { version: '' })
|
return this.authRequest<ReqRes.GetVersionLatestRes>({ method: Method.GET, url: '/versionLatest' }, { version: '' })
|
||||||
}
|
}
|
||||||
|
|
||||||
async getServerMetrics (): Promise<ReqRes.GetServerMetricsRes> {
|
async getServerMetrics(): Promise<ReqRes.GetServerMetricsRes> {
|
||||||
return this.authRequest<ReqRes.GetServerMetricsRes>({ method: Method.GET, url: `/metrics` })
|
return this.authRequest<ReqRes.GetServerMetricsRes>({ method: Method.GET, url: `/metrics` })
|
||||||
}
|
}
|
||||||
|
|
||||||
async getNotifications (page: number, perPage: number): Promise<S9Notification[]> {
|
async getNotifications(page: number, perPage: number): Promise<S9Notification[]> {
|
||||||
const params: ReqRes.GetNotificationsReq = {
|
const params: ReqRes.GetNotificationsReq = {
|
||||||
page: String(page),
|
page: String(page),
|
||||||
perPage: String(perPage),
|
perPage: String(perPage),
|
||||||
@@ -65,37 +65,37 @@ export class LiveApiService extends ApiService {
|
|||||||
return this.authRequest<ReqRes.GetNotificationsRes>({ method: Method.GET, url: `/notifications`, params })
|
return this.authRequest<ReqRes.GetNotificationsRes>({ method: Method.GET, url: `/notifications`, params })
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteNotification (id: string): Promise<Unit> {
|
async deleteNotification(id: string): Promise<Unit> {
|
||||||
return this.authRequest({ method: Method.DELETE, url: `/notifications/${id}` })
|
return this.authRequest({ method: Method.DELETE, url: `/notifications/${id}` })
|
||||||
}
|
}
|
||||||
|
|
||||||
async getExternalDisks (): Promise<DiskInfo[]> {
|
async getExternalDisks(): Promise<DiskInfo[]> {
|
||||||
return this.authRequest<ReqRes.GetExternalDisksRes>({ method: Method.GET, url: `/disks` })
|
return this.authRequest<ReqRes.GetExternalDisksRes>({ method: Method.GET, url: `/disks` })
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: EJECT-DISKS
|
// TODO: EJECT-DISKS
|
||||||
async ejectExternalDisk (logicalName: string): Promise<Unit> {
|
async ejectExternalDisk(logicalName: string): Promise<Unit> {
|
||||||
return this.authRequest({ method: Method.POST, url: `/disks/eject`, data: { logicalName } })
|
return this.authRequest({ method: Method.POST, url: `/disks/eject`, data: { logicalName } })
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateAgent (version: string): Promise<Unit> {
|
async updateAgent(version: string): Promise<Unit> {
|
||||||
const data: ReqRes.PostUpdateAgentReq = {
|
const data: ReqRes.PostUpdateAgentReq = {
|
||||||
version: `=${version}`,
|
version: `=${version}`,
|
||||||
}
|
}
|
||||||
return this.authRequest({ method: Method.POST, url: '/update', data })
|
return this.authRequest({ method: Method.POST, url: '/update', data })
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAvailableAppVersionSpecificInfo (appId: string, versionSpec: string): Promise<AppAvailableVersionSpecificInfo> {
|
async getAvailableAppVersionSpecificInfo(appId: string, versionSpec: string): Promise<AppAvailableVersionSpecificInfo> {
|
||||||
return this
|
return this
|
||||||
.authRequest<Replace<ReqRes.GetAppAvailableVersionInfoRes, 'versionViewing', 'version'>>( { method: Method.GET, url: `/apps/${appId}/store/${versionSpec}` })
|
.authRequest<Replace<ReqRes.GetAppAvailableVersionInfoRes, 'versionViewing', 'version'>>({ method: Method.GET, url: `/apps/${appId}/store/${versionSpec}` })
|
||||||
.then( res => ({ ...res, versionViewing: res.version }))
|
.then(res => ({ ...res, versionViewing: res.version }))
|
||||||
.then( res => {
|
.then(res => {
|
||||||
delete res['version']
|
delete res['version']
|
||||||
return res
|
return res
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAvailableApps (): Promise<AppAvailablePreview[]> {
|
async getAvailableApps(): Promise<AppAvailablePreview[]> {
|
||||||
const res = await this.authRequest<ReqRes.GetAppsAvailableRes>({ method: Method.GET, url: '/apps/store' })
|
const res = await this.authRequest<ReqRes.GetAppsAvailableRes>({ method: Method.GET, url: '/apps/store' })
|
||||||
return res.map(a => {
|
return res.map(a => {
|
||||||
const latestVersionTimestamp = new Date(a.latestVersionTimestamp)
|
const latestVersionTimestamp = new Date(a.latestVersionTimestamp)
|
||||||
@@ -104,7 +104,7 @@ export class LiveApiService extends ApiService {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAvailableApp (appId: string): Promise<AppAvailableFull> {
|
async getAvailableApp(appId: string): Promise<AppAvailableFull> {
|
||||||
return this.authRequest<ReqRes.GetAppAvailableRes>({ method: Method.GET, url: `/apps/${appId}/store` })
|
return this.authRequest<ReqRes.GetAppAvailableRes>({ method: Method.GET, url: `/apps/${appId}/store` })
|
||||||
.then(res => {
|
.then(res => {
|
||||||
return {
|
return {
|
||||||
@@ -114,33 +114,33 @@ export class LiveApiService extends ApiService {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async getInstalledApp (appId: string): Promise<AppInstalledFull> {
|
async getInstalledApp(appId: string): Promise<AppInstalledFull> {
|
||||||
return this.authRequest<ReqRes.GetAppInstalledRes>({ method: Method.GET, url: `/apps/${appId}/installed` })
|
return this.authRequest<ReqRes.GetAppInstalledRes>({ method: Method.GET, url: `/apps/${appId}/installed` })
|
||||||
.then(app => ({ ...app, hasFetchedFull: true }))
|
.then(app => ({ ...app, hasFetchedFull: true }))
|
||||||
}
|
}
|
||||||
|
|
||||||
async getInstalledApps (): Promise<AppInstalledPreview[]> {
|
async getInstalledApps(): Promise<AppInstalledPreview[]> {
|
||||||
return this.authRequest<ReqRes.GetAppsInstalledRes>({ method: Method.GET, url: `/apps/installed` })
|
return this.authRequest<ReqRes.GetAppsInstalledRes>({ method: Method.GET, url: `/apps/installed` })
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAppConfig ( appId: string): Promise<ReqRes.GetAppConfigRes> {
|
async getAppConfig(appId: string): Promise<ReqRes.GetAppConfigRes> {
|
||||||
return this.authRequest<ReqRes.GetAppConfigRes>({ method: Method.GET, url: `/apps/${appId}/config` })
|
return this.authRequest<ReqRes.GetAppConfigRes>({ method: Method.GET, url: `/apps/${appId}/config` })
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAppLogs (appId: string, params: ReqRes.GetAppLogsReq = { }): Promise<string[]> {
|
async getAppLogs(appId: string, params: ReqRes.GetAppLogsReq = {}): Promise<string[]> {
|
||||||
return this.authRequest<ReqRes.GetAppLogsRes>( { method: Method.GET, url: `/apps/${appId}/logs`, params: params as any })
|
return this.authRequest<ReqRes.GetAppLogsRes>({ method: Method.GET, url: `/apps/${appId}/logs`, params: params as any })
|
||||||
}
|
}
|
||||||
|
|
||||||
async getServerLogs (): Promise<string> {
|
async getServerLogs(): Promise<string> {
|
||||||
return this.authRequest<ReqRes.GetServerLogsRes>( { method: Method.GET, url: `/logs` })
|
return this.authRequest<ReqRes.GetServerLogsRes>({ method: Method.GET, url: `/logs` })
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAppMetrics (appId: string): Promise<AppMetrics> {
|
async getAppMetrics(appId: string): Promise<AppMetrics> {
|
||||||
return this.authRequest<ReqRes.GetAppMetricsRes | string>( { method: Method.GET, url: `/apps/${appId}/metrics` })
|
return this.authRequest<ReqRes.GetAppMetricsRes | string>({ method: Method.GET, url: `/apps/${appId}/metrics` })
|
||||||
.then(parseMetricsPermissive)
|
.then(parseMetricsPermissive)
|
||||||
}
|
}
|
||||||
|
|
||||||
async installApp (appId: string, version: string, dryRun: boolean = false): Promise<AppInstalledFull & { breakages: DependentBreakage[] }> {
|
async installApp(appId: string, version: string, dryRun: boolean = false): Promise<AppInstalledFull & { breakages: DependentBreakage[] }> {
|
||||||
const data: ReqRes.PostInstallAppReq = {
|
const data: ReqRes.PostInstallAppReq = {
|
||||||
version,
|
version,
|
||||||
}
|
}
|
||||||
@@ -148,94 +148,94 @@ export class LiveApiService extends ApiService {
|
|||||||
.then(res => ({ ...res, hasFetchedFull: false }))
|
.then(res => ({ ...res, hasFetchedFull: false }))
|
||||||
}
|
}
|
||||||
|
|
||||||
async uninstallApp (appId: string, dryRun: boolean = false): Promise<{ breakages: DependentBreakage[] }> {
|
async uninstallApp(appId: string, dryRun: boolean = false): Promise<{ breakages: DependentBreakage[] }> {
|
||||||
return this.authRequest({ method: Method.POST, url: `/apps/${appId}/uninstall${dryRunParam(dryRun, true)}`, readTimeout: 60000 })
|
return this.authRequest({ method: Method.POST, url: `/apps/${appId}/uninstall${dryRunParam(dryRun, true)}`, readTimeout: 60000 })
|
||||||
}
|
}
|
||||||
|
|
||||||
async startApp (appId: string): Promise<Unit> {
|
async startApp(appId: string): Promise<Unit> {
|
||||||
return this.authRequest({ method: Method.POST, url: `/apps/${appId}/start`, readTimeout: 60000 })
|
return this.authRequest({ method: Method.POST, url: `/apps/${appId}/start`, readTimeout: 60000 })
|
||||||
.then(() => this.appModel.update({ id: appId, status: AppStatus.RUNNING }))
|
.then(() => this.appModel.update({ id: appId, status: AppStatus.RUNNING }))
|
||||||
.then(() => ({ }))
|
.then(() => ({}))
|
||||||
}
|
}
|
||||||
|
|
||||||
async stopApp (appId: string, dryRun: boolean = false): Promise<{ breakages: DependentBreakage[] }> {
|
async stopApp(appId: string, dryRun: boolean = false): Promise<{ breakages: DependentBreakage[] }> {
|
||||||
const res = await this.authRequest<{ breakages: DependentBreakage[] }>({ method: Method.POST, url: `/apps/${appId}/stop${dryRunParam(dryRun, true)}`, readTimeout: 60000 })
|
const res = await this.authRequest<{ breakages: DependentBreakage[] }>({ method: Method.POST, url: `/apps/${appId}/stop${dryRunParam(dryRun, true)}`, readTimeout: 60000 })
|
||||||
if (!dryRun) this.appModel.update({ id: appId, status: AppStatus.STOPPING }, modulateTime(new Date(), 5, 'seconds'))
|
if (!dryRun) this.appModel.update({ id: appId, status: AppStatus.STOPPING }, modulateTime(new Date(), 5, 'seconds'))
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
async restartApp (appId: string): Promise<Unit> {
|
async restartApp(appId: string): Promise<Unit> {
|
||||||
return this.authRequest({ method: Method.POST, url: `/apps/${appId}/restart`, readTimeout: 60000 })
|
return this.authRequest({ method: Method.POST, url: `/apps/${appId}/restart`, readTimeout: 60000 })
|
||||||
.then(() => ({ } as any))
|
.then(() => ({} as any))
|
||||||
}
|
}
|
||||||
|
|
||||||
async createAppBackup (appId: string, logicalname: string, password?: string): Promise<Unit> {
|
async createAppBackup(appId: string, logicalname: string, password?: string): Promise<Unit> {
|
||||||
const data: ReqRes.PostAppBackupCreateReq = {
|
const data: ReqRes.PostAppBackupCreateReq = {
|
||||||
password: password || undefined,
|
password: password || undefined,
|
||||||
logicalname,
|
logicalname,
|
||||||
}
|
}
|
||||||
return this.authRequest<ReqRes.PostAppBackupCreateRes>({ method: Method.POST, url: `/apps/${appId}/backup`, data, readTimeout: 60000 })
|
return this.authRequest<ReqRes.PostAppBackupCreateRes>({ method: Method.POST, url: `/apps/${appId}/backup`, data, readTimeout: 60000 })
|
||||||
.then(() => this.appModel.update({ id: appId, status: AppStatus.CREATING_BACKUP }))
|
.then(() => this.appModel.update({ id: appId, status: AppStatus.CREATING_BACKUP }))
|
||||||
.then(() => ({ }))
|
.then(() => ({}))
|
||||||
}
|
}
|
||||||
|
|
||||||
async stopAppBackup (appId: string): Promise<Unit> {
|
async stopAppBackup(appId: string): Promise<Unit> {
|
||||||
return this.authRequest<ReqRes.PostAppBackupStopRes>({ method: Method.POST, url: `/apps/${appId}/backup/stop`, readTimeout: 60000 })
|
return this.authRequest<ReqRes.PostAppBackupStopRes>({ method: Method.POST, url: `/apps/${appId}/backup/stop`, readTimeout: 60000 })
|
||||||
.then(() => this.appModel.update({ id: appId, status: AppStatus.STOPPED }))
|
.then(() => this.appModel.update({ id: appId, status: AppStatus.STOPPED }))
|
||||||
.then(() => ({ }))
|
.then(() => ({}))
|
||||||
}
|
}
|
||||||
|
|
||||||
async restoreAppBackup (appId: string, logicalname: string, password?: string): Promise<Unit> {
|
async restoreAppBackup(appId: string, logicalname: string, password?: string): Promise<Unit> {
|
||||||
const data: ReqRes.PostAppBackupRestoreReq = {
|
const data: ReqRes.PostAppBackupRestoreReq = {
|
||||||
password: password || undefined,
|
password: password || undefined,
|
||||||
logicalname,
|
logicalname,
|
||||||
}
|
}
|
||||||
return this.authRequest<ReqRes.PostAppBackupRestoreRes>({ method: Method.POST, url: `/apps/${appId}/backup/restore`, data, readTimeout: 60000 })
|
return this.authRequest<ReqRes.PostAppBackupRestoreRes>({ method: Method.POST, url: `/apps/${appId}/backup/restore`, data, readTimeout: 60000 })
|
||||||
.then(() => this.appModel.update({ id: appId, status: AppStatus.RESTORING_BACKUP }))
|
.then(() => this.appModel.update({ id: appId, status: AppStatus.RESTORING_BACKUP }))
|
||||||
.then(() => ({ }))
|
.then(() => ({}))
|
||||||
}
|
}
|
||||||
|
|
||||||
async patchAppConfig (app: AppInstalledPreview, config: object, dryRun = false): Promise<{ breakages: DependentBreakage[] }> {
|
async patchAppConfig(app: AppInstalledPreview, config: object, dryRun = false): Promise<{ breakages: DependentBreakage[] }> {
|
||||||
const data: ReqRes.PatchAppConfigReq = {
|
const data: ReqRes.PatchAppConfigReq = {
|
||||||
config,
|
config,
|
||||||
}
|
}
|
||||||
return this.authRequest({ method: Method.PATCH, url: `/apps/${app.id}/config${dryRunParam(dryRun, true)}`, data, readTimeout: 60000 })
|
return this.authRequest({ method: Method.PATCH, url: `/apps/${app.id}/config${dryRunParam(dryRun, true)}`, data, readTimeout: 60000 })
|
||||||
}
|
}
|
||||||
|
|
||||||
async postConfigureDependency (dependencyId: string, dependentId: string, dryRun?: boolean): Promise<{ config: object, breakages: DependentBreakage[] }> {
|
async postConfigureDependency(dependencyId: string, dependentId: string, dryRun?: boolean): Promise<{ config: object, breakages: DependentBreakage[] }> {
|
||||||
return this.authRequest({ method: Method.POST, url: `/apps/${dependencyId}/autoconfig/${dependentId}${dryRunParam(dryRun, true)}`, readTimeout: 60000 })
|
return this.authRequest({ method: Method.POST, url: `/apps/${dependencyId}/autoconfig/${dependentId}${dryRunParam(dryRun, true)}`, readTimeout: 60000 })
|
||||||
}
|
}
|
||||||
|
|
||||||
async patchServerConfig (attr: string, value: any): Promise<Unit> {
|
async patchServerConfig(attr: string, value: any): Promise<Unit> {
|
||||||
const data: ReqRes.PatchServerConfigReq = {
|
const data: ReqRes.PatchServerConfigReq = {
|
||||||
value,
|
value,
|
||||||
}
|
}
|
||||||
return this.authRequest({ method: Method.PATCH, url: `/${attr}`, data, readTimeout: 60000 })
|
return this.authRequest({ method: Method.PATCH, url: `/${attr}`, data, readTimeout: 60000 })
|
||||||
.then(() => this.serverModel.update({ [attr]: value }))
|
.then(() => this.serverModel.update({ [attr]: value }))
|
||||||
.then(() => ({ }))
|
.then(() => ({}))
|
||||||
}
|
}
|
||||||
|
|
||||||
async wipeAppData (app: AppInstalledPreview): Promise<Unit> {
|
async wipeAppData(app: AppInstalledPreview): Promise<Unit> {
|
||||||
return this.authRequest({ method: Method.POST, url: `/apps/${app.id}/wipe`, readTimeout: 60000 }).then((res) => {
|
return this.authRequest({ method: Method.POST, url: `/apps/${app.id}/wipe`, readTimeout: 60000 }).then((res) => {
|
||||||
this.appModel.update({ id: app.id, status: AppStatus.NEEDS_CONFIG })
|
this.appModel.update({ id: app.id, status: AppStatus.NEEDS_CONFIG })
|
||||||
return res
|
return res
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async toggleAppLAN (appId: string, toggle: 'enable' | 'disable'): Promise<Unit> {
|
async toggleAppLAN(appId: string, toggle: 'enable' | 'disable'): Promise<Unit> {
|
||||||
return this.authRequest({ method: Method.POST, url: `/apps/${appId}/lan/${toggle}` })
|
return this.authRequest({ method: Method.POST, url: `/apps/${appId}/lan/${toggle}` })
|
||||||
}
|
}
|
||||||
|
|
||||||
async addSSHKey (sshKey: string): Promise<Unit> {
|
async addSSHKey(sshKey: string): Promise<Unit> {
|
||||||
const data: ReqRes.PostAddSSHKeyReq = {
|
const data: ReqRes.PostAddSSHKeyReq = {
|
||||||
sshKey,
|
sshKey,
|
||||||
}
|
}
|
||||||
const fingerprint = await this.authRequest<ReqRes.PostAddSSHKeyRes>({ method: Method.POST, url: `/sshKeys`, data })
|
const fingerprint = await this.authRequest<ReqRes.PostAddSSHKeyRes>({ method: Method.POST, url: `/sshKeys`, data })
|
||||||
this.serverModel.update({ ssh: [...this.serverModel.peek().ssh, fingerprint] })
|
this.serverModel.update({ ssh: [...this.serverModel.peek().ssh, fingerprint] })
|
||||||
return { }
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
async addWifi (ssid: string, password: string, country: string, connect: boolean): Promise<Unit> {
|
async addWifi(ssid: string, password: string, country: string, connect: boolean): Promise<Unit> {
|
||||||
const data: ReqRes.PostAddWifiReq = {
|
const data: ReqRes.PostAddWifiReq = {
|
||||||
ssid,
|
ssid,
|
||||||
password,
|
password,
|
||||||
@@ -245,43 +245,43 @@ export class LiveApiService extends ApiService {
|
|||||||
return this.authRequest({ method: Method.POST, url: `/wifi`, data })
|
return this.authRequest({ method: Method.POST, url: `/wifi`, data })
|
||||||
}
|
}
|
||||||
|
|
||||||
async connectWifi (ssid: string): Promise<Unit> {
|
async connectWifi(ssid: string): Promise<Unit> {
|
||||||
return this.authRequest({ method: Method.POST, url: encodeURI(`/wifi/${ssid}`) })
|
return this.authRequest({ method: Method.POST, url: encodeURI(`/wifi/${ssid}`) })
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteWifi (ssid: string): Promise<Unit> {
|
async deleteWifi(ssid: string): Promise<Unit> {
|
||||||
return this.authRequest({ method: Method.DELETE, url: encodeURI(`/wifi/${ssid}`) })
|
return this.authRequest({ method: Method.DELETE, url: encodeURI(`/wifi/${ssid}`) })
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteSSHKey (fingerprint: SSHFingerprint): Promise<Unit> {
|
async deleteSSHKey(fingerprint: SSHFingerprint): Promise<Unit> {
|
||||||
await this.authRequest({ method: Method.DELETE, url: `/sshKeys/${fingerprint.hash}` })
|
await this.authRequest({ method: Method.DELETE, url: `/sshKeys/${fingerprint.hash}` })
|
||||||
const ssh = this.serverModel.peek().ssh
|
const ssh = this.serverModel.peek().ssh
|
||||||
this.serverModel.update({ ssh: ssh.filter(s => s !== fingerprint) })
|
this.serverModel.update({ ssh: ssh.filter(s => s !== fingerprint) })
|
||||||
return { }
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
async restartServer (): Promise<Unit> {
|
async restartServer(): Promise<Unit> {
|
||||||
return this.authRequest({ method: Method.POST, url: '/restart', readTimeout: 60000 })
|
return this.authRequest({ method: Method.POST, url: '/restart', readTimeout: 60000 })
|
||||||
}
|
}
|
||||||
|
|
||||||
async shutdownServer (): Promise<Unit> {
|
async shutdownServer(): Promise<Unit> {
|
||||||
return this.authRequest({ method: Method.POST, url: '/shutdown', readTimeout: 60000 })
|
return this.authRequest({ method: Method.POST, url: '/shutdown', readTimeout: 60000 })
|
||||||
}
|
}
|
||||||
|
|
||||||
async serviceAction (appId: string, s: ServiceAction): Promise<ReqRes.ServiceActionResponse> {
|
async serviceAction(appId: string, s: ServiceAction): Promise<ReqRes.ServiceActionResponse> {
|
||||||
const data: ReqRes.ServiceActionRequest = {
|
const data: ReqRes.ServiceActionRequest = {
|
||||||
jsonrpc: '2.0',
|
jsonrpc: '2.0',
|
||||||
id: uuid.v4(),
|
id: uuid.v4(),
|
||||||
method: s.id,
|
method: s.id,
|
||||||
}
|
}
|
||||||
return this.authRequest({ method: Method.POST, url: `apps/${appId}/actions`, data })
|
return this.authRequest({ method: Method.POST, url: `/apps/${appId}/actions`, data })
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshLAN (): Promise<Unit> {
|
async refreshLAN(): Promise<Unit> {
|
||||||
return this.authRequest({ method: Method.POST, url: '/network/lan/reset' })
|
return this.authRequest({ method: Method.POST, url: '/network/lan/reset' })
|
||||||
}
|
}
|
||||||
|
|
||||||
private async authRequest<T> (opts: HttpOptions, overrides: Partial<{ version: string }> = { }): Promise<T> {
|
private async authRequest<T>(opts: HttpOptions, overrides: Partial<{ version: string }> = {}): Promise<T> {
|
||||||
if (!this.authenticatedRequestsEnabled) throw new Error(`Authenticated requests are not enabled. Do you need to login?`)
|
if (!this.authenticatedRequestsEnabled) throw new Error(`Authenticated requests are not enabled. Do you need to login?`)
|
||||||
|
|
||||||
opts.withCredentials = true
|
opts.withCredentials = true
|
||||||
@@ -300,7 +300,7 @@ const dryRunParam = (dryRun: boolean, first: boolean) => {
|
|||||||
return first ? `?dryrun` : `&dryrun`
|
return first ? `?dryrun` : `&dryrun`
|
||||||
}
|
}
|
||||||
|
|
||||||
function catchHttpStatusError (error: HttpErrorResponse): Observable<true> {
|
function catchHttpStatusError(error: HttpErrorResponse): Observable<true> {
|
||||||
if (error.error instanceof ErrorEvent) {
|
if (error.error instanceof ErrorEvent) {
|
||||||
// A client-side or network error occurred. Handle it accordingly.
|
// A client-side or network error occurred. Handle it accordingly.
|
||||||
return throwError('Not Connected')
|
return throwError('Not Connected')
|
||||||
|
|||||||
Reference in New Issue
Block a user