mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
feat: refactor updates (#2860)
This commit is contained in:
@@ -1054,11 +1054,11 @@ export class MockApiService extends ApiService {
|
||||
...Mock.LocalPkgs[params.id],
|
||||
stateInfo: {
|
||||
// if installing
|
||||
state: 'installing',
|
||||
// state: 'installing',
|
||||
|
||||
// if updating
|
||||
// state: 'updating',
|
||||
// manifest: mockPatchData.packageData[params.id].stateInfo.manifest!,
|
||||
state: 'updating',
|
||||
manifest: mockPatchData.packageData[params.id].stateInfo.manifest!,
|
||||
|
||||
// both
|
||||
installingInfo: {
|
||||
|
||||
@@ -9,14 +9,15 @@ import {
|
||||
map,
|
||||
Observable,
|
||||
pairwise,
|
||||
shareReplay,
|
||||
startWith,
|
||||
switchMap,
|
||||
} from 'rxjs'
|
||||
import { ConnectionService } from 'src/app/services/connection.service'
|
||||
import { EOSService } from 'src/app/services/eos.service'
|
||||
import { MarketplaceService } from 'src/app/services/marketplace.service'
|
||||
import { NotificationService } from 'src/app/services/notification.service'
|
||||
import { DataModel } from 'src/app/services/patch-db/data-model'
|
||||
import { MarketplaceService } from 'src/app/services/marketplace.service'
|
||||
import { ConnectionService } from 'src/app/services/connection.service'
|
||||
import { getManifest } from 'src/app/utils/get-package-data'
|
||||
|
||||
@Injectable({
|
||||
@@ -54,35 +55,35 @@ export class BadgeService {
|
||||
),
|
||||
)
|
||||
|
||||
// private readonly updates$ = combineLatest([
|
||||
// this.marketplaceService.getMarketplace$(true),
|
||||
// this.local$,
|
||||
// ]).pipe(
|
||||
// map(
|
||||
// ([marketplace, local]) =>
|
||||
// Object.entries(marketplace).reduce(
|
||||
// (list, [_, store]) =>
|
||||
// store?.packages.reduce(
|
||||
// (result, { id, version }) =>
|
||||
// local[id] &&
|
||||
// this.exver.compareExver(
|
||||
// version,
|
||||
// getManifest(local[id]).version,
|
||||
// ) === 1
|
||||
// ? result.add(id)
|
||||
// : result,
|
||||
// list,
|
||||
// ) || list,
|
||||
// new Set<string>(),
|
||||
// ).size,
|
||||
// ),
|
||||
// shareReplay(1),
|
||||
// )
|
||||
private readonly updates$ = combineLatest([
|
||||
this.marketplaceService.marketplace$,
|
||||
this.local$,
|
||||
]).pipe(
|
||||
map(
|
||||
([marketplace, local]) =>
|
||||
Object.entries(marketplace).reduce(
|
||||
(list, [_, store]) =>
|
||||
store?.packages.reduce(
|
||||
(result, { id, version }) =>
|
||||
local[id] &&
|
||||
this.exver.compareExver(
|
||||
version,
|
||||
getManifest(local[id]).version,
|
||||
) === 1
|
||||
? result.add(id)
|
||||
: result,
|
||||
list,
|
||||
) || list,
|
||||
new Set<string>(),
|
||||
).size,
|
||||
),
|
||||
shareReplay(1),
|
||||
)
|
||||
|
||||
getCount(id: string): Observable<number> {
|
||||
switch (id) {
|
||||
// case '/portal/updates':
|
||||
// return this.updates$
|
||||
case '/portal/updates':
|
||||
return this.updates$
|
||||
case '/portal/system':
|
||||
return this.system$
|
||||
case '/portal/notifications':
|
||||
|
||||
@@ -1,32 +1,39 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import {
|
||||
StoreIdentity,
|
||||
MarketplacePkg,
|
||||
GetPackageRes,
|
||||
Marketplace,
|
||||
MarketplacePkg,
|
||||
StoreData,
|
||||
StoreDataWithUrl,
|
||||
StoreIdentity,
|
||||
} from '@start9labs/marketplace'
|
||||
import { Exver, sameUrl } from '@start9labs/shared'
|
||||
import { T } from '@start9labs/start-sdk'
|
||||
import { PatchDB } from 'patch-db-client'
|
||||
import {
|
||||
BehaviorSubject,
|
||||
catchError,
|
||||
combineLatest,
|
||||
distinctUntilChanged,
|
||||
filter,
|
||||
from,
|
||||
map,
|
||||
mergeMap,
|
||||
Observable,
|
||||
of,
|
||||
shareReplay,
|
||||
switchMap,
|
||||
distinctUntilChanged,
|
||||
pairwise,
|
||||
ReplaySubject,
|
||||
scan,
|
||||
shareReplay,
|
||||
startWith,
|
||||
switchMap,
|
||||
tap,
|
||||
} from 'rxjs'
|
||||
import { RR } from 'src/app/services/api/api.types'
|
||||
import { ApiService } from 'src/app/services/api/embassy-api.service'
|
||||
import { DataModel, UIStore } from 'src/app/services/patch-db/data-model'
|
||||
import { ConfigService } from './config.service'
|
||||
import { Exver } from '@start9labs/shared'
|
||||
import { ClientStorageService } from './client-storage.service'
|
||||
import { T } from '@start9labs/start-sdk'
|
||||
import { ConfigService } from './config.service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@@ -66,7 +73,10 @@ export class MarketplaceService {
|
||||
const { start9, community } = this.config.marketplace
|
||||
let arr = [
|
||||
toStoreIdentity(start9, hosts[start9]),
|
||||
toStoreIdentity(community, hosts[community]),
|
||||
toStoreIdentity(community, {
|
||||
...hosts[community],
|
||||
name: 'Community Registry',
|
||||
}),
|
||||
]
|
||||
|
||||
return arr.concat(
|
||||
@@ -93,6 +103,32 @@ export class MarketplaceService {
|
||||
|
||||
private readonly requestErrors$ = new BehaviorSubject<string[]>([])
|
||||
|
||||
readonly marketplace$: Observable<Marketplace> = this.knownHosts$.pipe(
|
||||
startWith<StoreIdentity[]>([]),
|
||||
pairwise(),
|
||||
mergeMap(([prev, curr]) =>
|
||||
curr.filter(c => !prev.find(p => sameUrl(c.url, p.url))),
|
||||
),
|
||||
mergeMap(({ url, name }) =>
|
||||
this.fetchRegistry$(url).pipe(
|
||||
tap(data => {
|
||||
if (data?.info.name) this.updateStoreName(url, name, data.info.name)
|
||||
}),
|
||||
map<StoreData | null, [string, StoreData | null]>(data => [url, data]),
|
||||
startWith<[string, StoreData | null]>([url, null]),
|
||||
),
|
||||
),
|
||||
scan<[string, StoreData | null], Record<string, StoreData | null>>(
|
||||
(requests, [url, store]) => {
|
||||
requests[url] = store
|
||||
|
||||
return requests
|
||||
},
|
||||
{},
|
||||
),
|
||||
shareReplay({ bufferSize: 1, refCount: true }),
|
||||
)
|
||||
|
||||
constructor(
|
||||
private readonly api: ApiService,
|
||||
private readonly patch: PatchDB<DataModel>,
|
||||
@@ -230,10 +266,6 @@ export class MarketplaceService {
|
||||
}
|
||||
}
|
||||
|
||||
// UI only
|
||||
readonly updateErrors: Record<string, string> = {}
|
||||
readonly updateQueue: Record<string, boolean> = {}
|
||||
|
||||
getRequestErrors$(): Observable<string[]> {
|
||||
return this.requestErrors$
|
||||
}
|
||||
@@ -251,6 +283,19 @@ export class MarketplaceService {
|
||||
|
||||
await this.api.installPackage(params)
|
||||
}
|
||||
|
||||
private async updateStoreName(
|
||||
url: string,
|
||||
oldName: string | undefined,
|
||||
newName: string,
|
||||
): Promise<void> {
|
||||
if (oldName !== newName) {
|
||||
this.api.setDbValue<string>(
|
||||
['marketplace', 'knownHosts', url, 'name'],
|
||||
newName,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function toStoreIdentity(url: string, uiStore: UIStore): StoreIdentity {
|
||||
|
||||
Reference in New Issue
Block a user