mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 04:01:58 +00:00
pre-download static files, and add api versioning
This commit is contained in:
committed by
Aiden McClelland
parent
01d766fce9
commit
d3c5648608
@@ -23,14 +23,14 @@ export class MarketplaceService {
|
||||
} = {}
|
||||
marketplaceUrl: string
|
||||
|
||||
constructor(
|
||||
constructor (
|
||||
private readonly api: ApiService,
|
||||
private readonly emver: Emver,
|
||||
private readonly patch: PatchDbService,
|
||||
private readonly config: ConfigService,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async init() {
|
||||
async init () {
|
||||
this.patch.watch$('ui', 'marketplace').subscribe(marketplace => {
|
||||
if (!marketplace || !marketplace['selected-id']) {
|
||||
this.marketplaceUrl = this.config.marketplace.url
|
||||
@@ -41,7 +41,7 @@ export class MarketplaceService {
|
||||
})
|
||||
}
|
||||
|
||||
async load(): Promise<void> {
|
||||
async load (): Promise<void> {
|
||||
try {
|
||||
const [data, pkgs] = await Promise.all([
|
||||
this.getMarketplaceData({}),
|
||||
@@ -66,7 +66,7 @@ export class MarketplaceService {
|
||||
}
|
||||
}
|
||||
|
||||
async getUpdates(localPkgs: {
|
||||
async getUpdates (localPkgs: {
|
||||
[id: string]: PackageDataEntry
|
||||
}): Promise<MarketplacePkg[]> {
|
||||
const id = this.patch.getData().ui.marketplace?.['selected-id']
|
||||
@@ -96,7 +96,7 @@ export class MarketplaceService {
|
||||
})
|
||||
}
|
||||
|
||||
async getPkg(id: string, version = '*'): Promise<MarketplacePkg> {
|
||||
async getPkg (id: string, version = '*'): Promise<MarketplacePkg> {
|
||||
const pkgs = await this.getMarketplacePkgs({
|
||||
ids: [{ id, version }],
|
||||
'eos-version-compat':
|
||||
@@ -111,11 +111,11 @@ export class MarketplaceService {
|
||||
}
|
||||
}
|
||||
|
||||
async cacheReleaseNotes(id: string): Promise<void> {
|
||||
async cacheReleaseNotes (id: string): Promise<void> {
|
||||
this.releaseNotes[id] = await this.getReleaseNotes({ id })
|
||||
}
|
||||
|
||||
private async getPkgs(
|
||||
private async getPkgs (
|
||||
page: number,
|
||||
perPage: number,
|
||||
): Promise<MarketplacePkg[]> {
|
||||
@@ -129,20 +129,20 @@ export class MarketplaceService {
|
||||
return pkgs
|
||||
}
|
||||
|
||||
async getMarketplaceData(
|
||||
async getMarketplaceData (
|
||||
params: RR.GetMarketplaceDataReq,
|
||||
url?: string,
|
||||
): Promise<RR.GetMarketplaceDataRes> {
|
||||
url = url || this.marketplaceUrl
|
||||
return this.api.marketplaceProxy('/package/data', params, url)
|
||||
return this.api.marketplaceProxy('/package/v0/data', params, url)
|
||||
}
|
||||
|
||||
async getMarketplacePkgs(
|
||||
async getMarketplacePkgs (
|
||||
params: RR.GetMarketplacePackagesReq,
|
||||
): Promise<RR.GetMarketplacePackagesRes> {
|
||||
if (params.query) params.category = undefined
|
||||
return this.api.marketplaceProxy(
|
||||
'/package/index',
|
||||
'/package/v0/index',
|
||||
{
|
||||
...params,
|
||||
ids: JSON.stringify(params.ids),
|
||||
@@ -151,11 +151,11 @@ export class MarketplaceService {
|
||||
)
|
||||
}
|
||||
|
||||
async getReleaseNotes(
|
||||
async getReleaseNotes (
|
||||
params: RR.GetReleaseNotesReq,
|
||||
): Promise<RR.GetReleaseNotesRes> {
|
||||
return this.api.marketplaceProxy(
|
||||
'/package/release-notes',
|
||||
'/package/v0/release-notes',
|
||||
params,
|
||||
this.marketplaceUrl,
|
||||
)
|
||||
|
||||
@@ -9,15 +9,15 @@ import { ConfigService } from '../config.service'
|
||||
export class LiveApiService extends ApiService {
|
||||
private marketplaceUrl: string
|
||||
|
||||
constructor(
|
||||
constructor (
|
||||
private readonly http: HttpService,
|
||||
private readonly config: ConfigService,
|
||||
) {
|
||||
super()
|
||||
;(window as any).rpcClient = this
|
||||
; (window as any).rpcClient = this
|
||||
}
|
||||
|
||||
async getStatic(url: string): Promise<string> {
|
||||
async getStatic (url: string): Promise<string> {
|
||||
return this.http.httpRequest({
|
||||
method: Method.GET,
|
||||
url,
|
||||
@@ -27,75 +27,75 @@ export class LiveApiService extends ApiService {
|
||||
|
||||
// db
|
||||
|
||||
async getRevisions(since: number): Promise<RR.GetRevisionsRes> {
|
||||
async getRevisions (since: number): Promise<RR.GetRevisionsRes> {
|
||||
return this.http.rpcRequest({ method: 'db.revisions', params: { since } })
|
||||
}
|
||||
|
||||
async getDump(): Promise<RR.GetDumpRes> {
|
||||
async getDump (): Promise<RR.GetDumpRes> {
|
||||
return this.http.rpcRequest({ method: 'db.dump' })
|
||||
}
|
||||
|
||||
async setDbValueRaw(params: RR.SetDBValueReq): Promise<RR.SetDBValueRes> {
|
||||
async setDbValueRaw (params: RR.SetDBValueReq): Promise<RR.SetDBValueRes> {
|
||||
return this.http.rpcRequest({ method: 'db.put.ui', params })
|
||||
}
|
||||
|
||||
// auth
|
||||
|
||||
async login(params: RR.LoginReq): Promise<RR.loginRes> {
|
||||
async login (params: RR.LoginReq): Promise<RR.loginRes> {
|
||||
return this.http.rpcRequest({ method: 'auth.login', params })
|
||||
}
|
||||
|
||||
async logout(params: RR.LogoutReq): Promise<RR.LogoutRes> {
|
||||
async logout (params: RR.LogoutReq): Promise<RR.LogoutRes> {
|
||||
return this.http.rpcRequest({ method: 'auth.logout', params })
|
||||
}
|
||||
|
||||
async getSessions(params: RR.GetSessionsReq): Promise<RR.GetSessionsRes> {
|
||||
async getSessions (params: RR.GetSessionsReq): Promise<RR.GetSessionsRes> {
|
||||
return this.http.rpcRequest({ method: 'auth.session.list', params })
|
||||
}
|
||||
|
||||
async killSessions(params: RR.KillSessionsReq): Promise<RR.KillSessionsRes> {
|
||||
async killSessions (params: RR.KillSessionsReq): Promise<RR.KillSessionsRes> {
|
||||
return this.http.rpcRequest({ method: 'auth.session.kill', params })
|
||||
}
|
||||
|
||||
// server
|
||||
|
||||
async setShareStatsRaw(
|
||||
async setShareStatsRaw (
|
||||
params: RR.SetShareStatsReq,
|
||||
): Promise<RR.SetShareStatsRes> {
|
||||
return this.http.rpcRequest({ method: 'server.config.share-stats', params })
|
||||
}
|
||||
|
||||
async getServerLogs(
|
||||
async getServerLogs (
|
||||
params: RR.GetServerLogsReq,
|
||||
): Promise<RR.GetServerLogsRes> {
|
||||
return this.http.rpcRequest({ method: 'server.logs', params })
|
||||
}
|
||||
|
||||
async getServerMetrics(
|
||||
async getServerMetrics (
|
||||
params: RR.GetServerMetricsReq,
|
||||
): Promise<RR.GetServerMetricsRes> {
|
||||
return this.http.rpcRequest({ method: 'server.metrics', params })
|
||||
}
|
||||
|
||||
async updateServerRaw(
|
||||
async updateServerRaw (
|
||||
params: RR.UpdateServerReq,
|
||||
): Promise<RR.UpdateServerRes> {
|
||||
return this.http.rpcRequest({ method: 'server.update', params })
|
||||
}
|
||||
|
||||
async restartServer(
|
||||
async restartServer (
|
||||
params: RR.RestartServerReq,
|
||||
): Promise<RR.RestartServerRes> {
|
||||
return this.http.rpcRequest({ method: 'server.restart', params })
|
||||
}
|
||||
|
||||
async shutdownServer(
|
||||
async shutdownServer (
|
||||
params: RR.ShutdownServerReq,
|
||||
): Promise<RR.ShutdownServerRes> {
|
||||
return this.http.rpcRequest({ method: 'server.shutdown', params })
|
||||
}
|
||||
|
||||
async systemRebuild(
|
||||
async systemRebuild (
|
||||
params: RR.RestartServerReq,
|
||||
): Promise<RR.RestartServerRes> {
|
||||
return this.http.rpcRequest({ method: 'server.rebuild', params })
|
||||
@@ -103,7 +103,7 @@ export class LiveApiService extends ApiService {
|
||||
|
||||
// marketplace URLs
|
||||
|
||||
async marketplaceProxy<T>(path: string, params: {}, url: string): Promise<T> {
|
||||
async marketplaceProxy<T> (path: string, params: {}, url: string): Promise<T> {
|
||||
const fullURL = `${url}${path}?${new URLSearchParams(params).toString()}`
|
||||
return this.http.rpcRequest({
|
||||
method: 'marketplace.get',
|
||||
@@ -111,11 +111,11 @@ export class LiveApiService extends ApiService {
|
||||
})
|
||||
}
|
||||
|
||||
async getEos(
|
||||
async getEos (
|
||||
params: RR.GetMarketplaceEOSReq,
|
||||
): Promise<RR.GetMarketplaceEOSRes> {
|
||||
return this.marketplaceProxy(
|
||||
'/eos/latest',
|
||||
'/eos/v0/latest',
|
||||
params,
|
||||
this.config.marketplace.url,
|
||||
)
|
||||
@@ -128,19 +128,19 @@ export class LiveApiService extends ApiService {
|
||||
|
||||
// notification
|
||||
|
||||
async getNotificationsRaw(
|
||||
async getNotificationsRaw (
|
||||
params: RR.GetNotificationsReq,
|
||||
): Promise<RR.GetNotificationsRes> {
|
||||
return this.http.rpcRequest({ method: 'notification.list', params })
|
||||
}
|
||||
|
||||
async deleteNotification(
|
||||
async deleteNotification (
|
||||
params: RR.DeleteNotificationReq,
|
||||
): Promise<RR.DeleteNotificationRes> {
|
||||
return this.http.rpcRequest({ method: 'notification.delete', params })
|
||||
}
|
||||
|
||||
async deleteAllNotifications(
|
||||
async deleteAllNotifications (
|
||||
params: RR.DeleteAllNotificationsReq,
|
||||
): Promise<RR.DeleteAllNotificationsRes> {
|
||||
return this.http.rpcRequest({
|
||||
@@ -151,79 +151,79 @@ export class LiveApiService extends ApiService {
|
||||
|
||||
// wifi
|
||||
|
||||
async getWifi(
|
||||
async getWifi (
|
||||
params: RR.GetWifiReq,
|
||||
timeout?: number,
|
||||
): Promise<RR.GetWifiRes> {
|
||||
return this.http.rpcRequest({ method: 'wifi.get', params, timeout })
|
||||
}
|
||||
|
||||
async setWifiCountry(
|
||||
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> {
|
||||
async addWifi (params: RR.AddWifiReq): Promise<RR.AddWifiRes> {
|
||||
return this.http.rpcRequest({ method: 'wifi.add', params })
|
||||
}
|
||||
|
||||
async connectWifi(params: RR.ConnectWifiReq): Promise<RR.ConnectWifiRes> {
|
||||
async connectWifi (params: RR.ConnectWifiReq): Promise<RR.ConnectWifiRes> {
|
||||
return this.http.rpcRequest({ method: 'wifi.connect', params })
|
||||
}
|
||||
|
||||
async deleteWifi(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.list', 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 getBackupTargets(
|
||||
async getBackupTargets (
|
||||
params: RR.GetBackupTargetsReq,
|
||||
): Promise<RR.GetBackupTargetsRes> {
|
||||
return this.http.rpcRequest({ method: 'backup.target.list', params })
|
||||
}
|
||||
|
||||
async addBackupTarget(
|
||||
async addBackupTarget (
|
||||
params: RR.AddBackupTargetReq,
|
||||
): Promise<RR.AddBackupTargetRes> {
|
||||
params.path = params.path.replace('/\\/g', '/')
|
||||
return this.http.rpcRequest({ method: 'backup.target.cifs.add', params })
|
||||
}
|
||||
|
||||
async updateBackupTarget(
|
||||
async updateBackupTarget (
|
||||
params: RR.UpdateBackupTargetReq,
|
||||
): Promise<RR.UpdateBackupTargetRes> {
|
||||
return this.http.rpcRequest({ method: 'backup.target.cifs.update', params })
|
||||
}
|
||||
|
||||
async removeBackupTarget(
|
||||
async removeBackupTarget (
|
||||
params: RR.RemoveBackupTargetReq,
|
||||
): Promise<RR.RemoveBackupTargetRes> {
|
||||
return this.http.rpcRequest({ method: 'backup.target.cifs.remove', params })
|
||||
}
|
||||
|
||||
async getBackupInfo(
|
||||
async getBackupInfo (
|
||||
params: RR.GetBackupInfoReq,
|
||||
): Promise<RR.GetBackupInfoRes> {
|
||||
return this.http.rpcRequest({ method: 'backup.target.info', params })
|
||||
}
|
||||
|
||||
async createBackupRaw(
|
||||
async createBackupRaw (
|
||||
params: RR.CreateBackupReq,
|
||||
): Promise<RR.CreateBackupRes> {
|
||||
return this.http.rpcRequest({ method: 'backup.create', params })
|
||||
@@ -231,7 +231,7 @@ export class LiveApiService extends ApiService {
|
||||
|
||||
// package
|
||||
|
||||
async getPackageProperties(
|
||||
async getPackageProperties (
|
||||
params: RR.GetPackagePropertiesReq,
|
||||
): Promise<RR.GetPackagePropertiesRes<2>['data']> {
|
||||
return this.http
|
||||
@@ -239,95 +239,95 @@ export class LiveApiService extends ApiService {
|
||||
.then(parsePropertiesPermissive)
|
||||
}
|
||||
|
||||
async getPackageLogs(
|
||||
async getPackageLogs (
|
||||
params: RR.GetPackageLogsReq,
|
||||
): Promise<RR.GetPackageLogsRes> {
|
||||
return this.http.rpcRequest({ method: 'package.logs', params })
|
||||
}
|
||||
|
||||
async getPkgMetrics(
|
||||
async getPkgMetrics (
|
||||
params: RR.GetPackageMetricsReq,
|
||||
): Promise<RR.GetPackageMetricsRes> {
|
||||
return this.http.rpcRequest({ method: 'package.metrics', params })
|
||||
}
|
||||
|
||||
async installPackageRaw(
|
||||
async installPackageRaw (
|
||||
params: RR.InstallPackageReq,
|
||||
): Promise<RR.InstallPackageRes> {
|
||||
return this.http.rpcRequest({ method: 'package.install', params })
|
||||
}
|
||||
|
||||
async dryUpdatePackage(
|
||||
async dryUpdatePackage (
|
||||
params: RR.DryUpdatePackageReq,
|
||||
): Promise<RR.DryUpdatePackageRes> {
|
||||
return this.http.rpcRequest({ method: 'package.update.dry', params })
|
||||
}
|
||||
|
||||
async getPackageConfig(
|
||||
async getPackageConfig (
|
||||
params: RR.GetPackageConfigReq,
|
||||
): Promise<RR.GetPackageConfigRes> {
|
||||
return this.http.rpcRequest({ method: 'package.config.get', params })
|
||||
}
|
||||
|
||||
async drySetPackageConfig(
|
||||
async drySetPackageConfig (
|
||||
params: RR.DrySetPackageConfigReq,
|
||||
): Promise<RR.DrySetPackageConfigRes> {
|
||||
return this.http.rpcRequest({ method: 'package.config.set.dry', params })
|
||||
}
|
||||
|
||||
async setPackageConfigRaw(
|
||||
async setPackageConfigRaw (
|
||||
params: RR.SetPackageConfigReq,
|
||||
): Promise<RR.SetPackageConfigRes> {
|
||||
return this.http.rpcRequest({ method: 'package.config.set', params })
|
||||
}
|
||||
|
||||
async restorePackagesRaw(
|
||||
async restorePackagesRaw (
|
||||
params: RR.RestorePackagesReq,
|
||||
): Promise<RR.RestorePackagesRes> {
|
||||
return this.http.rpcRequest({ method: 'package.backup.restore', params })
|
||||
}
|
||||
|
||||
async executePackageAction(
|
||||
async executePackageAction (
|
||||
params: RR.ExecutePackageActionReq,
|
||||
): Promise<RR.ExecutePackageActionRes> {
|
||||
return this.http.rpcRequest({ method: 'package.action', params })
|
||||
}
|
||||
|
||||
async startPackageRaw(
|
||||
async startPackageRaw (
|
||||
params: RR.StartPackageReq,
|
||||
): Promise<RR.StartPackageRes> {
|
||||
return this.http.rpcRequest({ method: 'package.start', params })
|
||||
}
|
||||
|
||||
async dryStopPackage(
|
||||
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 dryUninstallPackage(
|
||||
async dryUninstallPackage (
|
||||
params: RR.DryUninstallPackageReq,
|
||||
): Promise<RR.DryUninstallPackageRes> {
|
||||
return this.http.rpcRequest({ method: 'package.uninstall.dry', params })
|
||||
}
|
||||
|
||||
async deleteRecoveredPackageRaw(
|
||||
async deleteRecoveredPackageRaw (
|
||||
params: RR.DeleteRecoveredPackageReq,
|
||||
): Promise<RR.DeleteRecoveredPackageRes> {
|
||||
return this.http.rpcRequest({ method: 'package.delete-recovered', params })
|
||||
}
|
||||
|
||||
async uninstallPackageRaw(
|
||||
async uninstallPackageRaw (
|
||||
params: RR.UninstallPackageReq,
|
||||
): Promise<RR.UninstallPackageRes> {
|
||||
return this.http.rpcRequest({ method: 'package.uninstall', params })
|
||||
}
|
||||
|
||||
async dryConfigureDependency(
|
||||
async dryConfigureDependency (
|
||||
params: RR.DryConfigureDependencyReq,
|
||||
): Promise<RR.DryConfigureDependencyRes> {
|
||||
return this.http.rpcRequest({
|
||||
|
||||
@@ -191,7 +191,7 @@ export class MockApiService extends ApiService {
|
||||
async marketplaceProxy (path: string, params: {}, url: string): Promise<any> {
|
||||
await pauseFor(2000)
|
||||
|
||||
if (path === '/package/data') {
|
||||
if (path === '/package/v0/data') {
|
||||
return {
|
||||
name: 'Dark9',
|
||||
categories: [
|
||||
@@ -204,9 +204,9 @@ export class MockApiService extends ApiService {
|
||||
'alt coin',
|
||||
],
|
||||
}
|
||||
} else if (path === '/package/index') {
|
||||
} else if (path === '/package/v0/index') {
|
||||
return Mock.MarketplacePkgsList
|
||||
} else if (path === '/package/release-notes') {
|
||||
} else if (path === '/package/v0/release-notes') {
|
||||
return Mock.ReleaseNotes
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user