From 3372cdc0df21c0936af75542f0c89c0a0539a80c Mon Sep 17 00:00:00 2001 From: Lucy C <12953208+elvece@users.noreply.github.com> Date: Mon, 28 Nov 2022 13:40:05 -0700 Subject: [PATCH] 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 Co-authored-by: Aiden McClelland --- Makefile | 7 +++++- frontend/config-sample.json | 3 ++- .../shared/src/types/workspace-config.ts | 3 ++- .../app/modals/os-update/os-update.page.ts | 3 --- .../server-show/server-show.page.ts | 4 ++-- .../ui/src/app/services/api/api.fixures.ts | 2 +- .../ui/src/app/services/api/api.types.ts | 11 +++++---- .../app/services/api/embassy-api.service.ts | 7 +++--- .../services/api/embassy-live-api.service.ts | 24 ++++++++++++++----- .../services/api/embassy-mock-api.service.ts | 11 +++++---- .../ui/src/app/services/config.service.ts | 6 +++-- .../ui/src/app/services/eos.service.ts | 11 +++------ .../src/app/services/marketplace.service.ts | 24 ++++++++++--------- .../ui/src/app/services/patch-data.service.ts | 2 +- 14 files changed, 68 insertions(+), 50 deletions(-) diff --git a/Makefile b/Makefile index f3ee15c2b..324aee96c 100644 --- a/Makefile +++ b/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 diff --git a/frontend/config-sample.json b/frontend/config-sample.json index e937c0d1d..deee991f6 100644 --- a/frontend/config-sample.json +++ b/frontend/config-sample.json @@ -1,6 +1,7 @@ { "useMocks": true, - "targetArch": "aarch64", + "packageArch": "aarch64", + "osArch": "rasberrypi", "ui": { "api": { "url": "rpc", diff --git a/frontend/projects/shared/src/types/workspace-config.ts b/frontend/projects/shared/src/types/workspace-config.ts index c42969b07..7c5691a4c 100644 --- a/frontend/projects/shared/src/types/workspace-config.ts +++ b/frontend/projects/shared/src/types/workspace-config.ts @@ -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 diff --git a/frontend/projects/ui/src/app/modals/os-update/os-update.page.ts b/frontend/projects/ui/src/app/modals/os-update/os-update.page.ts index c60da3c32..eb9de93db 100644 --- a/frontend/projects/ui/src/app/modals/os-update/os-update.page.ts +++ b/frontend/projects/ui/src/app/modals/os-update/os-update.page.ts @@ -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, ) {} ngOnInit() { diff --git a/frontend/projects/ui/src/app/pages/server-routes/server-show/server-show.page.ts b/frontend/projects/ui/src/app/pages/server-routes/server-show/server-show.page.ts index acbf22e49..7451fc516 100644 --- a/frontend/projects/ui/src/app/pages/server-routes/server-show/server-show.page.ts +++ b/frontend/projects/ui/src/app/pages/server-routes/server-show/server-show.page.ts @@ -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() diff --git a/frontend/projects/ui/src/app/services/api/api.fixures.ts b/frontend/projects/ui/src/app/services/api/api.fixures.ts index 8f97d6d96..7f8e1add0 100644 --- a/frontend/projects/ui/src/app/services/api/api.fixures.ts +++ b/frontend/projects/ui/src/app/services/api/api.fixures.ts @@ -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': { diff --git a/frontend/projects/ui/src/app/services/api/api.types.ts b/frontend/projects/ui/src/app/services/api/api.types.ts index 207d0415c..1d53e4956 100644 --- a/frontend/projects/ui/src/app/services/api/api.types.ts +++ b/frontend/projects/ui/src/app/services/api/api.types.ts @@ -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 }[] diff --git a/frontend/projects/ui/src/app/services/api/embassy-api.service.ts b/frontend/projects/ui/src/app/services/api/embassy-api.service.ts index ded8b075b..cf872e632 100644 --- a/frontend/projects/ui/src/app/services/api/embassy-api.service.ts +++ b/frontend/projects/ui/src/app/services/api/embassy-api.service.ts @@ -101,13 +101,12 @@ export abstract class ApiService { abstract marketplaceProxy( path: string, - params: {}, + params: Record, url: string, + arch?: string, ): Promise - abstract getEos( - params: RR.GetMarketplaceEOSReq, - ): Promise + abstract getEos(): Promise // password // abstract updatePassword (params: RR.UpdatePasswordReq): Promise diff --git a/frontend/projects/ui/src/app/services/api/embassy-live-api.service.ts b/frontend/projects/ui/src/app/services/api/embassy-live-api.service.ts index f61bc1bdb..96df8acfa 100644 --- a/frontend/projects/ui/src/app/services/api/embassy-live-api.service.ts +++ b/frontend/projects/ui/src/app/services/api/embassy-live-api.service.ts @@ -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(path: string, qp: {}, baseUrl: string): Promise { - Object.assign(qp, { arch: this.config.targetArch }) + async marketplaceProxy( + path: string, + qp: Record, + baseUrl: string, + arch: string = this.config.packageArch, + ): Promise { + // 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 { + async getEos(): Promise { + 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, ) } diff --git a/frontend/projects/ui/src/app/services/api/embassy-mock-api.service.ts b/frontend/projects/ui/src/app/services/api/embassy-mock-api.service.ts index 43fd33245..5a0c55432 100644 --- a/frontend/projects/ui/src/app/services/api/embassy-mock-api.service.ts +++ b/frontend/projects/ui/src/app/services/api/embassy-mock-api.service.ts @@ -294,7 +294,12 @@ export class MockApiService extends ApiService { // marketplace URLs - async marketplaceProxy(path: string, params: {}, url: string): Promise { + async marketplaceProxy( + path: string, + params: Record, + url: string, + arch = '', + ): Promise { await pauseFor(2000) if (path === '/package/v0/info') { @@ -320,9 +325,7 @@ export class MockApiService extends ApiService { } } - async getEos( - params: RR.GetMarketplaceEOSReq, - ): Promise { + async getEos(): Promise { await pauseFor(2000) return Mock.MarketplaceEos } diff --git a/frontend/projects/ui/src/app/services/config.service.ts b/frontend/projects/ui/src/app/services/config.service.ts index 997b78c46..eb8194729 100644 --- a/frontend/projects/ui/src/app/services/config.service.ts +++ b/frontend/projects/ui/src/app/services/config.service.ts @@ -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 diff --git a/frontend/projects/ui/src/app/services/eos.service.ts b/frontend/projects/ui/src/app/services/eos.service.ts index 217257cc4..396c84223 100644 --- a/frontend/projects/ui/src/app/services/eos.service.ts +++ b/frontend/projects/ui/src/app/services/eos.service.ts @@ -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, ) {} - async getEOS(): Promise { - const { id, version } = await getServerInfo(this.patch) - this.eos = await this.api.getEos({ - 'server-id': id, - 'eos-version': version, - }) + async loadEos(): Promise { + 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 } } diff --git a/frontend/projects/ui/src/app/services/marketplace.service.ts b/frontend/projects/ui/src/app/services/marketplace.service.ts index a8049545d..fb04d05da 100644 --- a/frontend/projects/ui/src/app/services/marketplace.service.ts +++ b/frontend/projects/ui/src/app/services/marketplace.service.ts @@ -169,17 +169,19 @@ export class MarketplaceService implements AbstractMarketplaceService { } fetchInfo$(url: string): Observable { - return this.patch - .watch$('server-info', 'id') - .pipe( - switchMap(id => - this.api.marketplaceProxy( - '/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( + '/package/v0/info', + qp, + url, + ) + }), + ) } private fetchStore$(url: string): Observable { diff --git a/frontend/projects/ui/src/app/services/patch-data.service.ts b/frontend/projects/ui/src/app/services/patch-data.service.ts index 8834a8e68..23ee15925 100644 --- a/frontend/projects/ui/src/app/services/patch-data.service.ts +++ b/frontend/projects/ui/src/app/services/patch-data.service.ts @@ -44,7 +44,7 @@ export class PatchDataService extends Observable { } private checkForUpdates(): void { - this.eosService.getEOS() + this.eosService.loadEos() this.marketplaceService.getMarketplace$().pipe(take(1)).subscribe() }