revamp wifi, fix error messaging in forms

This commit is contained in:
Matt Hill
2021-08-17 19:01:35 -06:00
parent 0f43414e25
commit 70a9bc96e8
46 changed files with 899 additions and 781 deletions

View File

@@ -854,6 +854,14 @@ export module Mock {
},
}
export const Wifi: RR.GetWifiRes = {
ethernet: true,
ssids: ['Goosers', 'Goosers5G'],
connected: 'Goosers',
country: 'US',
'signal-strength': 50,
}
export const Disks: RR.GetDisksRes = {
'/dev/sda': {
size: '32GB',
@@ -1516,7 +1524,6 @@ export module Mock {
// 'tor-address': 'myveryownspecialtoraddress.onion',
// wifi: {
// ssids: ['Goosers', 'Goosers5G'],
// selected: 'Goosers5G',
// connected: 'Goosers5G',
// },
// 'eos-marketplace': 'https://registry.start9.com',

View File

@@ -19,7 +19,7 @@ export module RR {
export type LoginReq = { password: string, metadata: SessionMetadata } // auth.login - unauthed
export type loginRes = null
export type LogoutReq = {} // auth.logout
export type LogoutReq = { } // auth.logout
export type LogoutRes = null
// server
@@ -30,26 +30,26 @@ export module RR {
export type GetServerLogsReq = { before?: string } // server.logs
export type GetServerLogsRes = Log[]
export type GetServerMetricsReq = {} // server.metrics
export type GetServerMetricsReq = { } // server.metrics
export type GetServerMetricsRes = Metrics
export type UpdateServerReq = WithExpire<{}> // server.update
export type UpdateServerReq = WithExpire<{ }> // server.update
export type UpdateServerRes = WithRevision<null>
export type RestartServerReq = {} // server.restart
export type RestartServerReq = { } // server.restart
export type RestartServerRes = null
export type ShutdownServerReq = {} // server.shutdown
export type ShutdownServerReq = { } // server.shutdown
export type ShutdownServerRes = null
// network
export type RefreshLanReq = {} // network.lan.refresh
export type RefreshLanReq = { } // network.lan.refresh
export type RefreshLanRes = null
// sessions
export type GetSessionsReq = {} // sessions.list
export type GetSessionsReq = { } // sessions.list
export type GetSessionsRes = {
current: string,
sessions: { [hash: string]: Session }
@@ -67,6 +67,7 @@ export module RR {
export type SetPackageMarketplaceRes = WithRevision<null>
// password
export type UpdatePasswordReq = { password: string } // password.set
export type UpdatePasswordRes = null
@@ -78,29 +79,40 @@ export module RR {
export type DeleteNotificationReq = { id: string } // notification.delete
export type DeleteNotificationRes = null
export type DeleteAllNotificationsReq = {} // notification.delete.all
export type DeleteAllNotificationsReq = { } // notification.delete.all
export type DeleteAllNotificationsRes = null
// wifi
export type SetWifiCountryReq = { country: string }
export type SetWifiCountryRes = null
export type GetWifiReq = { }
export type GetWifiRes = { // wifi.get
ethernet: boolean
ssids: string[]
connected: string | null
country: string | null
'signal-strength': number
}
export type AddWifiReq = { // wifi.add
ssid: string
password: string
country: string
priority: number
connect: boolean
}
export type AddWifiRes = null
export type ConnectWifiReq = WithExpire<{ ssid: string }> // wifi.connect
export type ConnectWifiRes = WithRevision<null>
export type ConnectWifiReq = { ssid: string } // wifi.connect
export type ConnectWifiRes = null
export type DeleteWifiReq = WithExpire<{ ssid: string }> // wifi.delete
export type DeleteWifiRes = WithRevision<null>
export type DeleteWifiReq = { ssid: string } // wifi.delete
export type DeleteWifiRes = null
// ssh
export type GetSSHKeysReq = {} // ssh.get
export type GetSSHKeysReq = { } // ssh.get
export type GetSSHKeysRes = SSHKeys
export type AddSSHKeyReq = { pubkey: string } // ssh.add
@@ -119,7 +131,7 @@ export module RR {
// disk
export type GetDisksReq = {} // disk.list
export type GetDisksReq = { } // disk.list
export type GetDisksRes = DiskInfo
export type EjectDisksReq = { logicalname: string } // disk.eject
@@ -178,10 +190,10 @@ export module RR {
// marketplace
export type GetMarketplaceDataReq = {}
export type GetMarketplaceDataReq = { }
export type GetMarketplaceDataRes = MarketplaceData
export type GetMarketplaceEOSReq = {}
export type GetMarketplaceEOSReq = { }
export type GetMarketplaceEOSRes = MarketplaceEOS
export type GetMarketplacePackagesReq = {

View File

@@ -96,17 +96,15 @@ export abstract class ApiService implements Source<DataModel>, Http<DataModel> {
// wifi
abstract getWifi (params: RR.GetWifiReq, timeout: number): Promise<RR.GetWifiRes>
abstract setWifiCountry (params: RR.SetWifiCountryReq): Promise<RR.SetWifiCountryRes>
abstract addWifi (params: RR.AddWifiReq): Promise<RR.AddWifiRes>
protected abstract connectWifiRaw (params: RR.ConnectWifiReq): Promise<RR.ConnectWifiRes>
connectWifi = (params: RR.ConnectWifiReq) => this.syncResponse(
() => this.connectWifiRaw(params),
)()
abstract connectWifi (params: RR.ConnectWifiReq): Promise<RR.ConnectWifiRes>
protected abstract deleteWifiRaw (params: RR.DeleteWifiReq): Promise<RR.ConnectWifiRes>
deleteWifi = (params: RR.DeleteWifiReq) => this.syncResponse(
() => this.deleteWifiRaw(params),
)()
abstract deleteWifi (params: RR.DeleteWifiReq): Promise<RR.ConnectWifiRes>
// ssh

View File

@@ -139,130 +139,138 @@ export class LiveApiService extends ApiService {
// notification
async getNotificationsRaw (params: RR.GetNotificationsReq): Promise < RR.GetNotificationsRes > {
async getNotificationsRaw (params: RR.GetNotificationsReq): Promise <RR.GetNotificationsRes> {
return this.http.rpcRequest({ method: 'notification.list', params })
}
async deleteNotification (params: RR.DeleteNotificationReq): Promise < RR.DeleteNotificationRes > {
async deleteNotification (params: RR.DeleteNotificationReq): Promise <RR.DeleteNotificationRes> {
return this.http.rpcRequest({ method: 'notification.delete', params })
}
async deleteAllNotifications (params: RR.DeleteAllNotificationsReq): Promise < RR.DeleteAllNotificationsRes > {
async deleteAllNotifications (params: RR.DeleteAllNotificationsReq): Promise <RR.DeleteAllNotificationsRes> {
return this.http.rpcRequest({ method: 'notification.delete.all', params })
}
// wifi
async addWifi (params: RR.AddWifiReq): Promise < RR.AddWifiRes > {
async getWifi (params: RR.GetWifiReq, timeout?: number): Promise <RR.GetWifiRes> {
return this.http.rpcRequest({ method: 'wifi.get', params, timeout })
}
async setWifiCountry (params: RR.SetWifiCountryReq): Promise <RR.SetWifiCountryRes> {
return this.http.rpcRequest({ method: 'wifi.country.set', params })
}
async addWifi (params: RR.AddWifiReq): Promise <RR.AddWifiRes> {
return this.http.rpcRequest({ method: 'wifi.add', params })
}
async connectWifiRaw (params: RR.ConnectWifiReq): Promise < RR.ConnectWifiRes > {
async connectWifi (params: RR.ConnectWifiReq): Promise <RR.ConnectWifiRes> {
return this.http.rpcRequest({ method: 'wifi.connect', params })
}
async deleteWifiRaw (params: RR.DeleteWifiReq): Promise < RR.DeleteWifiRes > {
async deleteWifi (params: RR.DeleteWifiReq): Promise <RR.DeleteWifiRes> {
return this.http.rpcRequest({ method: 'wifi.delete', params })
}
// ssh
async getSshKeys (params: RR.GetSSHKeysReq): Promise < RR.GetSSHKeysRes > {
async getSshKeys (params: RR.GetSSHKeysReq): Promise <RR.GetSSHKeysRes> {
return this.http.rpcRequest({ method: 'ssh.get', params })
}
async addSshKey (params: RR.AddSSHKeyReq): Promise < RR.AddSSHKeyRes > {
async addSshKey (params: RR.AddSSHKeyReq): Promise <RR.AddSSHKeyRes> {
return this.http.rpcRequest({ method: 'ssh.add', params })
}
async deleteSshKey (params: RR.DeleteSSHKeyReq): Promise < RR.DeleteSSHKeyRes > {
async deleteSshKey (params: RR.DeleteSSHKeyReq): Promise <RR.DeleteSSHKeyRes> {
return this.http.rpcRequest({ method: 'ssh.delete', params })
}
// backup
async createBackupRaw (params: RR.CreateBackupReq): Promise < RR.CreateBackupRes > {
async createBackupRaw (params: RR.CreateBackupReq): Promise <RR.CreateBackupRes> {
return this.http.rpcRequest({ method: 'backup.create', params })
}
async restoreBackupRaw (params: RR.RestoreBackupReq): Promise < RR.RestoreBackupRes > {
async restoreBackupRaw (params: RR.RestoreBackupReq): Promise <RR.RestoreBackupRes> {
return this.http.rpcRequest({ method: 'backup.restore', params })
}
// disk
getDisks (params: RR.GetDisksReq): Promise < RR.GetDisksRes > {
getDisks (params: RR.GetDisksReq): Promise <RR.GetDisksRes> {
return this.http.rpcRequest({ method: 'disk.list', params })
}
ejectDisk (params: RR.EjectDisksReq): Promise < RR.EjectDisksRes > {
ejectDisk (params: RR.EjectDisksReq): Promise <RR.EjectDisksRes> {
return this.http.rpcRequest({ method: 'disk.eject', params })
}
// package
async getPackageProperties (params: RR.GetPackagePropertiesReq): Promise < RR.GetPackagePropertiesRes < any > ['data'] > {
async getPackageProperties (params: RR.GetPackagePropertiesReq): Promise <RR.GetPackagePropertiesRes < any > ['data'] > {
return this.http.rpcRequest({ method: 'package.properties', params })
.then(parsePropertiesPermissive)
}
async getPackageLogs (params: RR.GetPackageLogsReq): Promise < RR.GetPackageLogsRes > {
async getPackageLogs (params: RR.GetPackageLogsReq): Promise <RR.GetPackageLogsRes> {
return this.http.rpcRequest( { method: 'package.logs', params })
}
async getPkgMetrics (params: RR.GetPackageMetricsReq): Promise < RR.GetPackageMetricsRes > {
async getPkgMetrics (params: RR.GetPackageMetricsReq): Promise <RR.GetPackageMetricsRes> {
return this.http.rpcRequest({ method: 'package.metrics', params })
}
async installPackageRaw (params: RR.InstallPackageReq): Promise < RR.InstallPackageRes > {
async installPackageRaw (params: RR.InstallPackageReq): Promise <RR.InstallPackageRes> {
return this.http.rpcRequest({ method: 'package.install', params })
}
async dryUpdatePackage (params: RR.DryUpdatePackageReq): Promise < RR.DryUpdatePackageRes > {
async dryUpdatePackage (params: RR.DryUpdatePackageReq): Promise <RR.DryUpdatePackageRes> {
return this.http.rpcRequest({ method: 'package.update.dry', params })
}
async getPackageConfig (params: RR.GetPackageConfigReq): Promise < RR.GetPackageConfigRes > {
async getPackageConfig (params: RR.GetPackageConfigReq): Promise <RR.GetPackageConfigRes> {
return this.http.rpcRequest({ method: 'package.config.get', params })
}
async drySetPackageConfig (params: RR.DrySetPackageConfigReq): Promise < RR.DrySetPackageConfigRes > {
async drySetPackageConfig (params: RR.DrySetPackageConfigReq): Promise <RR.DrySetPackageConfigRes> {
return this.http.rpcRequest({ method: 'package.config.set.dry', params })
}
async setPackageConfigRaw (params: RR.SetPackageConfigReq): Promise < RR.SetPackageConfigRes > {
async setPackageConfigRaw (params: RR.SetPackageConfigReq): Promise <RR.SetPackageConfigRes> {
return this.http.rpcRequest({ method: 'package.config.set', params })
}
async restorePackageRaw (params: RR.RestorePackageReq): Promise < RR.RestorePackageRes > {
async restorePackageRaw (params: RR.RestorePackageReq): Promise <RR.RestorePackageRes> {
return this.http.rpcRequest({ method: 'package.restore', params })
}
async executePackageAction (params: RR.ExecutePackageActionReq): Promise < RR.ExecutePackageActionRes > {
async executePackageAction (params: RR.ExecutePackageActionReq): Promise <RR.ExecutePackageActionRes> {
return this.http.rpcRequest({ method: 'package.action', params })
}
async startPackageRaw (params: RR.StartPackageReq): Promise < RR.StartPackageRes > {
async startPackageRaw (params: RR.StartPackageReq): Promise <RR.StartPackageRes> {
return this.http.rpcRequest({ method: 'package.start', params })
}
async dryStopPackage (params: RR.DryStopPackageReq): Promise < RR.DryStopPackageRes > {
async dryStopPackage (params: RR.DryStopPackageReq): Promise <RR.DryStopPackageRes> {
return this.http.rpcRequest({ method: 'package.stop.dry', params })
}
async stopPackageRaw (params: RR.StopPackageReq): Promise < RR.StopPackageRes > {
async stopPackageRaw (params: RR.StopPackageReq): Promise <RR.StopPackageRes> {
return this.http.rpcRequest({ method: 'package.stop', params })
}
async dryRemovePackage (params: RR.DryRemovePackageReq): Promise < RR.DryRemovePackageRes > {
async dryRemovePackage (params: RR.DryRemovePackageReq): Promise <RR.DryRemovePackageRes> {
return this.http.rpcRequest({ method: 'package.remove.dry', params })
}
async removePackageRaw (params: RR.RemovePackageReq): Promise < RR.RemovePackageRes > {
async removePackageRaw (params: RR.RemovePackageReq): Promise <RR.RemovePackageRes> {
return this.http.rpcRequest({ method: 'package.remove', params })
}
async dryConfigureDependency (params: RR.DryConfigureDependencyReq): Promise < RR.DryConfigureDependencyRes > {
async dryConfigureDependency (params: RR.DryConfigureDependencyReq): Promise <RR.DryConfigureDependencyRes> {
return this.http.rpcRequest({ method: 'package.dependency.configure.dry', params })
}
}

View File

@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core'
import { pauseFor } from '../../util/misc.util'
import { ApiService } from './embassy-api.service'
import { Operation, PatchOp } from 'patch-db-client'
import { PatchOp } from 'patch-db-client'
import { InstallProgress, PackageDataEntry, PackageMainStatus, PackageState, ServerStatus } from 'src/app/services/patch-db/data-model'
import { RR, WithRevision } from './api.types'
import { parsePropertiesPermissive } from 'src/app/util/properties.util'
@@ -223,47 +223,29 @@ export class MockApiService extends ApiService {
// wifi
async getWifi (params: RR.GetWifiReq): Promise < RR.GetWifiRes > {
await pauseFor(2000)
return Mock.Wifi
}
async setWifiCountry (params: RR.SetWifiCountryReq): Promise <RR.SetWifiCountryRes> {
await pauseFor(2000)
return null
}
async addWifi (params: RR.AddWifiReq): Promise<RR.AddWifiRes> {
await pauseFor(2000)
return null
}
async connectWifiRaw (params: RR.ConnectWifiReq): Promise<RR.ConnectWifiRes> {
async connectWifi (params: RR.ConnectWifiReq): Promise<RR.ConnectWifiRes> {
await pauseFor(2000)
const patch = [
{
op: PatchOp.REPLACE,
path: '/server-info/wifi/selected',
value: params.ssid,
},
{
op: PatchOp.REPLACE,
path: '/server-info/wifi/connected',
value: params.ssid,
},
]
return this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
return null
}
async deleteWifiRaw (params: RR.DeleteWifiReq): Promise<RR.DeleteWifiRes> {
async deleteWifi (params: RR.DeleteWifiReq): Promise<RR.DeleteWifiRes> {
await pauseFor(2000)
const patch: Operation[] = [
{
op: PatchOp.REMOVE,
path: `/server-info/wifi/ssids/${params.ssid}`,
},
// {
// op: PatchOp.REPLACE,
// path: '/server-info/wifi/selected',
// value: null,
// },
// {
// op: PatchOp.REPLACE,
// path: '/server-info/wifi/connected',
// value: null,
// },
]
return this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
return null
}
// ssh