mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 04:01:58 +00:00
dont watch patch.data directly in TS (#371)
* dont watch patch.data directly in TS * installs and uninstalls working * minor repairs
This commit is contained in:
committed by
Aiden McClelland
parent
65c4db09f3
commit
d1b8f51b78
@@ -1,4 +1,4 @@
|
||||
import { DockerIoFormat, Manifest, PackageDataEntry, PackageMainStatus, PackageState } from 'src/app/services/patch-db/data-model'
|
||||
import { DependencyErrorType, DockerIoFormat, Manifest, PackageDataEntry, PackageMainStatus, PackageState } from 'src/app/services/patch-db/data-model'
|
||||
import { MarketplacePkg, Metric, NotificationLevel, RR, ServerNotifications } from './api.types'
|
||||
|
||||
export module Mock {
|
||||
@@ -1347,56 +1347,56 @@ export module Mock {
|
||||
// 'install-progress': undefined,
|
||||
// }
|
||||
|
||||
// export const lnd: PackageDataEntry = {
|
||||
// state: PackageState.Installed,
|
||||
// 'static-files': {
|
||||
// license: 'licenseUrl', // /public/package-data/lnd/0.21.1/LICENSE.md,
|
||||
// icon: 'assets/img/service-icons/lnd.png',
|
||||
// instructions: 'instructionsUrl', // /public/package-data/lnd/0.21.1/INSTRUCTIONS.md
|
||||
// },
|
||||
// manifest: MockManifestLnd,
|
||||
// installed: {
|
||||
// status: {
|
||||
// configured: true,
|
||||
// main: {
|
||||
// status: PackageMainStatus.Stopped,
|
||||
// },
|
||||
// 'dependency-errors': {
|
||||
// 'bitcoin-proxy': {
|
||||
// type: DependencyErrorType.NotInstalled,
|
||||
// title: Mock.MockManifestBitcoinProxy.title,
|
||||
// icon: 'assets/img/service-icons/bitcoin-proxy.png',
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// 'interface-info': {
|
||||
// ip: '10.0.0.1',
|
||||
// addresses: {
|
||||
// rpc: {
|
||||
// 'tor-address': 'lnd-rpc-address.onion',
|
||||
// 'lan-address': 'lnd-rpc-address.local',
|
||||
// },
|
||||
// grpc: {
|
||||
// 'tor-address': 'lnd-grpc-address.onion',
|
||||
// 'lan-address': 'lnd-grpc-address.local',
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// 'system-pointers': [],
|
||||
// 'current-dependents': { },
|
||||
// 'current-dependencies': {
|
||||
// 'bitcoind': {
|
||||
// pointers: [],
|
||||
// 'health-checks': [],
|
||||
// },
|
||||
// 'bitcoin-proxy': {
|
||||
// pointers: [],
|
||||
// 'health-checks': [],
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// 'install-progress': undefined,
|
||||
// }
|
||||
export const lnd: PackageDataEntry = {
|
||||
state: PackageState.Installed,
|
||||
'static-files': {
|
||||
license: 'licenseUrl', // /public/package-data/lnd/0.21.1/LICENSE.md,
|
||||
icon: 'assets/img/service-icons/lnd.png',
|
||||
instructions: 'instructionsUrl', // /public/package-data/lnd/0.21.1/INSTRUCTIONS.md
|
||||
},
|
||||
manifest: MockManifestLnd,
|
||||
installed: {
|
||||
status: {
|
||||
configured: true,
|
||||
main: {
|
||||
status: PackageMainStatus.Stopped,
|
||||
},
|
||||
'dependency-errors': {
|
||||
'bitcoin-proxy': {
|
||||
type: DependencyErrorType.NotInstalled,
|
||||
title: Mock.MockManifestBitcoinProxy.title,
|
||||
icon: 'assets/img/service-icons/bitcoin-proxy.png',
|
||||
},
|
||||
},
|
||||
},
|
||||
'interface-info': {
|
||||
ip: '10.0.0.1',
|
||||
addresses: {
|
||||
rpc: {
|
||||
'tor-address': 'lnd-rpc-address.onion',
|
||||
'lan-address': 'lnd-rpc-address.local',
|
||||
},
|
||||
grpc: {
|
||||
'tor-address': 'lnd-grpc-address.onion',
|
||||
'lan-address': 'lnd-grpc-address.local',
|
||||
},
|
||||
},
|
||||
},
|
||||
'system-pointers': [],
|
||||
'current-dependents': { },
|
||||
'current-dependencies': {
|
||||
'bitcoind': {
|
||||
pointers: [],
|
||||
'health-checks': [],
|
||||
},
|
||||
'bitcoin-proxy': {
|
||||
pointers: [],
|
||||
'health-checks': [],
|
||||
},
|
||||
},
|
||||
},
|
||||
'install-progress': undefined,
|
||||
}
|
||||
|
||||
// export const DbDump: RR.GetDumpRes = {
|
||||
// id: 1,
|
||||
|
||||
@@ -2,7 +2,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 { PackageDataEntry, PackageMainStatus, PackageState, ServerStatus } from 'src/app/services/patch-db/data-model'
|
||||
import { DataModel, 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'
|
||||
import { Mock } from '../api.fixures'
|
||||
@@ -325,18 +325,19 @@ export class MockApiService extends ApiService {
|
||||
|
||||
async installPackageRaw (params: RR.InstallPackageReq): Promise<RR.InstallPackageRes> {
|
||||
await pauseFor(2000)
|
||||
const initialProgress: InstallProgress = {
|
||||
size: 120,
|
||||
downloaded: 0,
|
||||
'download-complete': false,
|
||||
validated: 0,
|
||||
'validation-complete': false,
|
||||
unpacked: 0,
|
||||
'unpack-complete': false,
|
||||
}
|
||||
const pkg: PackageDataEntry = {
|
||||
...Mock.bitcoinproxy,
|
||||
...Mock[params.id],
|
||||
state: PackageState.Installing,
|
||||
'install-progress': {
|
||||
size: 100,
|
||||
downloaded: 10,
|
||||
'download-complete': false,
|
||||
validated: 1,
|
||||
'validation-complete': true,
|
||||
read: 50,
|
||||
'read-complete': false,
|
||||
},
|
||||
'install-progress': initialProgress,
|
||||
}
|
||||
const patch = [
|
||||
{
|
||||
@@ -345,7 +346,11 @@ export class MockApiService extends ApiService {
|
||||
value: pkg,
|
||||
},
|
||||
]
|
||||
return this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
|
||||
const res = await this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
|
||||
setTimeout(async () => {
|
||||
this.updateProgress(params.id, initialProgress)
|
||||
}, 1000)
|
||||
return res
|
||||
}
|
||||
|
||||
async dryUpdatePackage (params: RR.DryUpdatePackageReq): Promise<RR.DryUpdatePackageRes> {
|
||||
@@ -483,4 +488,45 @@ export class MockApiService extends ApiService {
|
||||
await pauseFor(2000)
|
||||
return { }
|
||||
}
|
||||
|
||||
private async updateProgress (id: string, initialProgress: InstallProgress) {
|
||||
const phases = [
|
||||
{ progress: 'downloaded', completion: 'download-complete'},
|
||||
{ progress: 'validated', completion: 'validation-complete'},
|
||||
{ progress: 'unpacked', completion: 'unpack-complete'},
|
||||
]
|
||||
for (let phase of phases) {
|
||||
let i = initialProgress[phase.progress]
|
||||
console.log('PHASE', phase)
|
||||
console.log('Initial i', i)
|
||||
while (i < initialProgress.size) {
|
||||
console.log(i)
|
||||
await pauseFor(1000)
|
||||
i = Math.min(i + 40, initialProgress.size)
|
||||
initialProgress[phase.progress] = i
|
||||
if (i === initialProgress.size) {
|
||||
initialProgress[phase.completion] = true
|
||||
}
|
||||
const patch = [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: `/package-data/${id}/install-progress`,
|
||||
value: initialProgress,
|
||||
},
|
||||
]
|
||||
await this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
const patch = [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: `/package-data/${id}/state`,
|
||||
value: PackageState.Installed,
|
||||
},
|
||||
]
|
||||
this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
|
||||
}, 1000)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,28 @@
|
||||
import { RR } from '../api.types'
|
||||
import { ConfigService } from '../../config.service'
|
||||
import { PatchDbService } from '../../patch-db/patch-db.service'
|
||||
import { ServerInfo } from '../../patch-db/data-model'
|
||||
import { AuthState } from '../../auth.service'
|
||||
import { takeWhile } from 'rxjs/operators'
|
||||
|
||||
export abstract class MarketplaceApiService {
|
||||
private server: ServerInfo
|
||||
|
||||
constructor (
|
||||
readonly config: ConfigService,
|
||||
readonly patch: PatchDbService,
|
||||
) { }
|
||||
|
||||
init (auth: AuthState) {
|
||||
this.patch.watch$('server-info')
|
||||
.pipe(
|
||||
takeWhile(() => auth === AuthState.VERIFIED),
|
||||
)
|
||||
.subscribe(server => {
|
||||
this.server = server
|
||||
})
|
||||
}
|
||||
|
||||
abstract getEos (params: RR.GetMarketplaceEOSReq): Promise<RR.GetMarketplaceEOSRes>
|
||||
|
||||
abstract getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise<RR.GetMarketplaceDataRes>
|
||||
@@ -20,11 +34,11 @@ export abstract class MarketplaceApiService {
|
||||
abstract getLatestVersion (params: RR.GetLatestVersionReq): Promise<RR.GetLatestVersionRes>
|
||||
|
||||
getMarketplaceURL (type: 'eos' | 'package', defaultToTor = false): string {
|
||||
const packageMarketplace = this.patch.data['server-info']['package-marketplace']
|
||||
const packageMarketplace = this.server['package-marketplace']
|
||||
if (defaultToTor && !packageMarketplace) {
|
||||
return this.config.start9Marketplace.tor
|
||||
}
|
||||
const eosMarketplace = this.patch.data['server-info']['eos-marketplace'] || this.config.start9Marketplace.clearnet
|
||||
const eosMarketplace = this.server['eos-marketplace'] || this.config.start9Marketplace.clearnet
|
||||
if (type === 'eos') {
|
||||
return eosMarketplace
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user