mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
Update/marketplace info (#1983)
* ensure arch is calways present in config * add eos version to params when fetching marketplace info * fix build script * choose arch based on make goals * conditionally send different arch param to registry * better type for qp Co-authored-by: Matt Hill <matthewonthemoon@gmail.com> Co-authored-by: Aiden McClelland <me@drbonez.dev>
This commit is contained in:
7
Makefile
7
Makefile
@@ -1,4 +1,6 @@
|
||||
ARCH = $(shell uname -m)
|
||||
RASPI_TARGETS := embassyos-raspi.img embassyos-raspi.tar.gz gzip lite-upgrade.img
|
||||
ARCH := $(shell if echo $(RASPI_TARGETS) | grep -qw "$(MAKECMDGOALS)"; then echo aarch64; else uname -m; fi)
|
||||
OS_ARCH := $(shell if echo $(RASPI_TARGETS) | grep -qw "$(MAKECMDGOALS)"; then echo raspberrypi; else uname -m; fi)
|
||||
ENVIRONMENT_FILE = $(shell ./check-environment.sh)
|
||||
GIT_HASH_FILE = $(shell ./check-git-hash.sh)
|
||||
VERSION_FILE = $(shell ./check-version.sh)
|
||||
@@ -145,6 +147,9 @@ frontend/dist/install-wizard: $(FRONTEND_INSTALL_WIZARD_SRC) $(FRONTEND_SHARED_S
|
||||
|
||||
frontend/config.json: $(GIT_HASH_FILE) frontend/config-sample.json
|
||||
jq '.useMocks = false' frontend/config-sample.json > frontend/config.json
|
||||
jq '.packageArch = "$(ARCH)"' frontend/config.json > frontend/config.json.tmp
|
||||
jq '.osArch = "$(OS_ARCH)"' frontend/config.json.tmp > frontend/config.json
|
||||
rm frontend/config.json.tmp
|
||||
npm --prefix frontend run-script build-config
|
||||
|
||||
frontend/patchdb-ui-seed.json: frontend/package.json
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"useMocks": true,
|
||||
"targetArch": "aarch64",
|
||||
"packageArch": "aarch64",
|
||||
"osArch": "rasberrypi",
|
||||
"ui": {
|
||||
"api": {
|
||||
"url": "rpc",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export type WorkspaceConfig = {
|
||||
targetArch: 'aarch64' | 'x86_64'
|
||||
packageArch: 'aarch64' | 'x86_64'
|
||||
osArch: 'aarch64' | 'x86_64' | 'raspberrypi'
|
||||
gitHash: string
|
||||
useMocks: boolean
|
||||
// each key corresponds to a project and values adjust settings for that project, eg: ui, install-wizard, setup-wizard, diagnostic-ui
|
||||
|
||||
@@ -3,8 +3,6 @@ import { LoadingController, ModalController } from '@ionic/angular'
|
||||
import { ApiService } from '../../services/api/embassy-api.service'
|
||||
import { ErrorToastService } from '@start9labs/shared'
|
||||
import { EOSService } from 'src/app/services/eos.service'
|
||||
import { PatchDB } from 'patch-db-client'
|
||||
import { DataModel } from 'src/app/services/patch-db/data-model'
|
||||
|
||||
@Component({
|
||||
selector: 'os-update',
|
||||
@@ -21,7 +19,6 @@ export class OSUpdatePage {
|
||||
private readonly errToast: ErrorToastService,
|
||||
private readonly embassyApi: ApiService,
|
||||
private readonly eosService: EOSService,
|
||||
private readonly patch: PatchDB<DataModel>,
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
@@ -308,11 +308,11 @@ export class ServerShowPage {
|
||||
await loader.present()
|
||||
|
||||
try {
|
||||
const updateAvailable = await this.eosService.getEOS()
|
||||
await this.eosService.loadEos()
|
||||
|
||||
await loader.dismiss()
|
||||
|
||||
if (updateAvailable) {
|
||||
if (this.eosService.updateAvailable$.value) {
|
||||
this.updateEos()
|
||||
} else {
|
||||
this.presentAlertLatest()
|
||||
|
||||
@@ -19,7 +19,7 @@ export module Mock {
|
||||
'update-progress': null,
|
||||
updated: true,
|
||||
}
|
||||
export const MarketplaceEos: RR.GetMarketplaceEOSRes = {
|
||||
export const MarketplaceEos: RR.GetMarketplaceEosRes = {
|
||||
version: '0.3.3',
|
||||
headline: 'Our biggest release ever.',
|
||||
'release-notes': {
|
||||
|
||||
@@ -244,14 +244,15 @@ export module RR {
|
||||
|
||||
// marketplace
|
||||
|
||||
export type GetMarketplaceInfoReq = { 'server-id': string }
|
||||
export type GetMarketplaceInfoRes = StoreInfo
|
||||
|
||||
export type GetMarketplaceEOSReq = {
|
||||
export type EnvInfo = {
|
||||
'server-id': string
|
||||
'eos-version': string
|
||||
}
|
||||
export type GetMarketplaceEOSRes = MarketplaceEOS
|
||||
export type GetMarketplaceInfoReq = EnvInfo
|
||||
export type GetMarketplaceInfoRes = StoreInfo
|
||||
|
||||
export type GetMarketplaceEosReq = EnvInfo
|
||||
export type GetMarketplaceEosRes = MarketplaceEOS
|
||||
|
||||
export type GetMarketplacePackagesReq = {
|
||||
ids?: { id: string; version: string }[]
|
||||
|
||||
@@ -101,13 +101,12 @@ export abstract class ApiService {
|
||||
|
||||
abstract marketplaceProxy<T>(
|
||||
path: string,
|
||||
params: {},
|
||||
params: Record<string, unknown>,
|
||||
url: string,
|
||||
arch?: string,
|
||||
): Promise<T>
|
||||
|
||||
abstract getEos(
|
||||
params: RR.GetMarketplaceEOSReq,
|
||||
): Promise<RR.GetMarketplaceEOSRes>
|
||||
abstract getEos(): Promise<RR.GetMarketplaceEosRes>
|
||||
|
||||
// password
|
||||
// abstract updatePassword (params: RR.UpdatePasswordReq): Promise<RR.UpdatePasswordRes>
|
||||
|
||||
@@ -19,6 +19,7 @@ import { AuthService } from '../auth.service'
|
||||
import { DOCUMENT } from '@angular/common'
|
||||
import { DataModel } from '../patch-db/data-model'
|
||||
import { PatchDB, pathFromArray, Update } from 'patch-db-client'
|
||||
import { getServerInfo } from 'src/app/util/get-server-info'
|
||||
|
||||
@Injectable()
|
||||
export class LiveApiService extends ApiService {
|
||||
@@ -177,8 +178,14 @@ export class LiveApiService extends ApiService {
|
||||
|
||||
// marketplace URLs
|
||||
|
||||
async marketplaceProxy<T>(path: string, qp: {}, baseUrl: string): Promise<T> {
|
||||
Object.assign(qp, { arch: this.config.targetArch })
|
||||
async marketplaceProxy<T>(
|
||||
path: string,
|
||||
qp: Record<string, string>,
|
||||
baseUrl: string,
|
||||
arch: string = this.config.packageArch,
|
||||
): Promise<T> {
|
||||
// Object.assign(qp, { arch })
|
||||
qp['arch'] = arch
|
||||
const fullUrl = `${baseUrl}${path}?${new URLSearchParams(qp).toString()}`
|
||||
return this.rpcRequest({
|
||||
method: 'marketplace.get',
|
||||
@@ -186,13 +193,18 @@ export class LiveApiService extends ApiService {
|
||||
})
|
||||
}
|
||||
|
||||
async getEos(
|
||||
params: RR.GetMarketplaceEOSReq,
|
||||
): Promise<RR.GetMarketplaceEOSRes> {
|
||||
async getEos(): Promise<RR.GetMarketplaceEosRes> {
|
||||
const { id, version } = await getServerInfo(this.patch)
|
||||
const qp: RR.GetMarketplaceEosReq = {
|
||||
'server-id': id,
|
||||
'eos-version': version,
|
||||
}
|
||||
|
||||
return this.marketplaceProxy(
|
||||
'/eos/v0/latest',
|
||||
params,
|
||||
qp,
|
||||
this.config.marketplace.start9,
|
||||
this.config.osArch,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -294,7 +294,12 @@ export class MockApiService extends ApiService {
|
||||
|
||||
// marketplace URLs
|
||||
|
||||
async marketplaceProxy(path: string, params: {}, url: string): Promise<any> {
|
||||
async marketplaceProxy(
|
||||
path: string,
|
||||
params: Record<string, string>,
|
||||
url: string,
|
||||
arch = '',
|
||||
): Promise<any> {
|
||||
await pauseFor(2000)
|
||||
|
||||
if (path === '/package/v0/info') {
|
||||
@@ -320,9 +325,7 @@ export class MockApiService extends ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
async getEos(
|
||||
params: RR.GetMarketplaceEOSReq,
|
||||
): Promise<RR.GetMarketplaceEOSRes> {
|
||||
async getEos(): Promise<RR.GetMarketplaceEosRes> {
|
||||
await pauseFor(2000)
|
||||
return Mock.MarketplaceEos
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ import {
|
||||
} from 'src/app/services/patch-db/data-model'
|
||||
|
||||
const {
|
||||
targetArch,
|
||||
packageArch,
|
||||
osArch,
|
||||
gitHash,
|
||||
useMocks,
|
||||
ui: { api, marketplace, mocks },
|
||||
@@ -25,7 +26,8 @@ export class ConfigService {
|
||||
version = require('../../../../../package.json').version as string
|
||||
useMocks = useMocks
|
||||
mocks = mocks
|
||||
targetArch = targetArch
|
||||
packageArch = packageArch
|
||||
osArch = osArch
|
||||
gitHash = gitHash
|
||||
api = api
|
||||
marketplace = marketplace
|
||||
|
||||
@@ -2,7 +2,6 @@ import { Injectable } from '@angular/core'
|
||||
import { Emver } from '@start9labs/shared'
|
||||
import { BehaviorSubject, combineLatest } from 'rxjs'
|
||||
import { distinctUntilChanged, map } from 'rxjs/operators'
|
||||
|
||||
import { MarketplaceEOS } from 'src/app/services/api/api.types'
|
||||
import { ApiService } from 'src/app/services/api/embassy-api.service'
|
||||
import { PatchDB } from 'patch-db-client'
|
||||
@@ -52,14 +51,10 @@ export class EOSService {
|
||||
private readonly patch: PatchDB<DataModel>,
|
||||
) {}
|
||||
|
||||
async getEOS(): Promise<boolean> {
|
||||
const { id, version } = await getServerInfo(this.patch)
|
||||
this.eos = await this.api.getEos({
|
||||
'server-id': id,
|
||||
'eos-version': version,
|
||||
})
|
||||
async loadEos(): Promise<void> {
|
||||
const { version } = await getServerInfo(this.patch)
|
||||
this.eos = await this.api.getEos()
|
||||
const updateAvailable = this.emver.compare(this.eos.version, version) === 1
|
||||
this.updateAvailable$.next(updateAvailable)
|
||||
return updateAvailable
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,17 +169,19 @@ export class MarketplaceService implements AbstractMarketplaceService {
|
||||
}
|
||||
|
||||
fetchInfo$(url: string): Observable<StoreInfo> {
|
||||
return this.patch
|
||||
.watch$('server-info', 'id')
|
||||
.pipe(
|
||||
switchMap(id =>
|
||||
this.api.marketplaceProxy<RR.GetMarketplaceInfoRes>(
|
||||
'/package/v0/info',
|
||||
{ 'server-d': id },
|
||||
url,
|
||||
),
|
||||
),
|
||||
)
|
||||
return this.patch.watch$('server-info').pipe(
|
||||
switchMap(serverInfo => {
|
||||
const qp: RR.GetMarketplaceInfoReq = {
|
||||
'server-id': serverInfo.id,
|
||||
'eos-version': serverInfo.version,
|
||||
}
|
||||
return this.api.marketplaceProxy<RR.GetMarketplaceInfoRes>(
|
||||
'/package/v0/info',
|
||||
qp,
|
||||
url,
|
||||
)
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
private fetchStore$(url: string): Observable<StoreData | null> {
|
||||
|
||||
@@ -44,7 +44,7 @@ export class PatchDataService extends Observable<DataModel> {
|
||||
}
|
||||
|
||||
private checkForUpdates(): void {
|
||||
this.eosService.getEOS()
|
||||
this.eosService.loadEos()
|
||||
this.marketplaceService.getMarketplace$().pipe(take(1)).subscribe()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user