re-add community marketplace and handle missing dependency (#2110)

* re-add community marketplace and handle missing dependency

* feat: Add in the community to migration

* chore: Add in the community marketplace_url update

* change var name to hidden

* chore: Add in the down

Co-authored-by: BluJ <mogulslayer@gmail.com>
This commit is contained in:
Matt Hill
2023-01-16 17:02:57 -07:00
committed by Aiden McClelland
parent 06cf83b901
commit 730a55e721
8 changed files with 142 additions and 39 deletions

View File

@@ -18,6 +18,7 @@ mod v0_3_1_2;
mod v0_3_2; mod v0_3_2;
mod v0_3_2_1; mod v0_3_2_1;
mod v0_3_3; mod v0_3_3;
mod v0_3_3_1;
pub type Current = v0_3_3::Version; pub type Current = v0_3_3::Version;
@@ -34,6 +35,7 @@ enum Version {
V0_3_2(Wrapper<v0_3_2::Version>), V0_3_2(Wrapper<v0_3_2::Version>),
V0_3_2_1(Wrapper<v0_3_2_1::Version>), V0_3_2_1(Wrapper<v0_3_2_1::Version>),
V0_3_3(Wrapper<v0_3_3::Version>), V0_3_3(Wrapper<v0_3_3::Version>),
V0_3_3_1(Wrapper<v0_3_3_1::Version>),
Other(emver::Version), Other(emver::Version),
} }
@@ -59,6 +61,7 @@ impl Version {
Version::V0_3_2(Wrapper(x)) => x.semver(), Version::V0_3_2(Wrapper(x)) => x.semver(),
Version::V0_3_2_1(Wrapper(x)) => x.semver(), Version::V0_3_2_1(Wrapper(x)) => x.semver(),
Version::V0_3_3(Wrapper(x)) => x.semver(), Version::V0_3_3(Wrapper(x)) => x.semver(),
Version::V0_3_3_1(Wrapper(x)) => x.semver(),
Version::Other(x) => x.clone(), Version::Other(x) => x.clone(),
} }
} }
@@ -195,6 +198,7 @@ pub async fn init<Db: DbHandle>(
Version::V0_3_2(v) => v.0.migrate_to(&Current::new(), db, receipts).await?, Version::V0_3_2(v) => v.0.migrate_to(&Current::new(), db, receipts).await?,
Version::V0_3_2_1(v) => v.0.migrate_to(&Current::new(), db, receipts).await?, Version::V0_3_2_1(v) => v.0.migrate_to(&Current::new(), db, receipts).await?,
Version::V0_3_3(v) => v.0.migrate_to(&Current::new(), db, receipts).await?, Version::V0_3_3(v) => v.0.migrate_to(&Current::new(), db, receipts).await?,
Version::V0_3_3_1(v) => v.0.migrate_to(&Current::new(), db, receipts).await?,
Version::Other(_) => { Version::Other(_) => {
return Err(Error::new( return Err(Error::new(
eyre!("Cannot downgrade"), eyre!("Cannot downgrade"),
@@ -237,6 +241,7 @@ mod tests {
Just(Version::V0_3_2(Wrapper(v0_3_2::Version::new()))), Just(Version::V0_3_2(Wrapper(v0_3_2::Version::new()))),
Just(Version::V0_3_2_1(Wrapper(v0_3_2_1::Version::new()))), Just(Version::V0_3_2_1(Wrapper(v0_3_2_1::Version::new()))),
Just(Version::V0_3_3(Wrapper(v0_3_3::Version::new()))), Just(Version::V0_3_3(Wrapper(v0_3_3::Version::new()))),
Just(Version::V0_3_3_1(Wrapper(v0_3_3_1::Version::new()))),
em_version().prop_map(Version::Other), em_version().prop_map(Version::Other),
] ]
} }

View File

@@ -0,0 +1,94 @@
use async_trait::async_trait;
use emver::VersionRange;
use serde_json::json;
use super::v0_3_0::V0_3_0_COMPAT;
use super::*;
const V0_3_3_1: emver::Version = emver::Version::new(0, 3, 3, 1);
const COMMUNITY_URL: &str = "https://community-registry.start9.com/";
const MAIN_REGISTRY: &str = "https://registry.start9.com/";
const COMMUNITY_SERVICES: &[&str] = &[
"ipfs",
"agora",
"lightning-jet",
"balanceofsatoshis",
"mastodon",
"lndg",
"robosats",
"thunderhub",
"syncthing",
"sphinx-relay",
];
#[derive(Clone, Debug)]
pub struct Version;
#[async_trait]
impl VersionT for Version {
type Previous = v0_3_3::Version;
fn new() -> Self {
Version
}
fn semver(&self) -> emver::Version {
V0_3_3_1
}
fn compat(&self) -> &'static VersionRange {
&*V0_3_0_COMPAT
}
async fn up<Db: DbHandle>(&self, db: &mut Db) -> Result<(), Error> {
let parsed_url = Some(COMMUNITY_URL.parse().unwrap());
let mut ui = crate::db::DatabaseModel::new().ui().get_mut(db).await?;
ui["marketplace"]["known-hosts"][COMMUNITY_URL] = json!({});
for package_id in crate::db::DatabaseModel::new()
.package_data()
.keys(db)
.await?
{
if !COMMUNITY_SERVICES.contains(&&*package_id.to_string()) {
continue;
}
crate::db::DatabaseModel::new()
.package_data()
.idx_model(&package_id)
.expect(db)
.await?
.installed()
.expect(db)
.await?
.marketplace_url()
.put(db, &parsed_url)
.await?;
}
Ok(())
}
async fn down<Db: DbHandle>(&self, db: &mut Db) -> Result<(), Error> {
let mut ui = crate::db::DatabaseModel::new().ui().get_mut(db).await?;
let parsed_url = Some(MAIN_REGISTRY.parse().unwrap());
for package_id in crate::db::DatabaseModel::new()
.package_data()
.keys(db)
.await?
{
if !COMMUNITY_SERVICES.contains(&&*package_id.to_string()) {
continue;
}
crate::db::DatabaseModel::new()
.package_data()
.idx_model(&package_id)
.expect(db)
.await?
.installed()
.expect(db)
.await?
.marketplace_url()
.put(db, &parsed_url)
.await?;
}
ui["marketplace"]["known-hosts"][COMMUNITY_URL].take();
ui.save(db).await?;
Ok(())
}
}

View File

@@ -4,7 +4,8 @@
"marketplace": { "marketplace": {
"selected-url": "https://registry.start9.com/", "selected-url": "https://registry.start9.com/",
"known-hosts": { "known-hosts": {
"https://registry.start9.com/": {} "https://registry.start9.com/": {},
"https://community-registry.start9.com/": {}
} }
}, },
"dev": {}, "dev": {},

View File

@@ -27,14 +27,17 @@ export interface MarketplacePkg {
categories: string[] categories: string[]
versions: string[] versions: string[]
'dependency-metadata': { 'dependency-metadata': {
[id: string]: { [id: string]: DependencyMetadata
title: string
icon: Url
}
} }
'published-at': string 'published-at': string
} }
export interface DependencyMetadata {
title: string
icon: Url
hidden: boolean
}
export interface MarketplaceManifest<T = unknown> { export interface MarketplaceManifest<T = unknown> {
id: string id: string
title: string title: string

View File

@@ -18,6 +18,7 @@ const ICONS = [
'chevron-up', 'chevron-up',
'chevron-forward', 'chevron-forward',
'close', 'close',
'close-circle-outline',
'cloud-outline', 'cloud-outline',
'cloud-done', 'cloud-done',
'cloud-done-outline', 'cloud-done-outline',

View File

@@ -3,12 +3,20 @@
<ion-content class="ion-padding"> <ion-content class="ion-padding">
<ng-container *ngIf="pkg$ | async as pkg else loading"> <ng-container *ngIf="pkg$ | async as pkg else loading">
<ng-container *ngIf="pkg | empty; else show"> <ng-container *ngIf="pkg | empty; else show">
<ng-container *ngIf="loadVersion$ | async as version"> <div
*ngIf="loadVersion$ | async as version"
class="ion-text-center"
style="padding-top: 64px"
>
<ion-icon
name="close-circle-outline"
style="font-size: 48px"
></ion-icon>
<h2> <h2>
{{ pkgId }} version {{ version === '*' ? 'latest' : version }} not {{ pkgId }} @{{ version === '*' ? 'latest' : version }} not found in
found in this registry this registry
</h2> </h2>
</ng-container> </div>
</ng-container> </ng-container>
<ng-template #show> <ng-template #show>

View File

@@ -10,7 +10,7 @@ import {
import { Metric, RR, NotificationLevel, ServerNotifications } from './api.types' import { Metric, RR, NotificationLevel, ServerNotifications } from './api.types'
import { BTC_ICON, LND_ICON, PROXY_ICON } from './api-icons' import { BTC_ICON, LND_ICON, PROXY_ICON } from './api-icons'
import { MarketplacePkg } from '@start9labs/marketplace' import { DependencyMetadata, MarketplacePkg } from '@start9labs/marketplace'
import { Log } from '@start9labs/shared' import { Log } from '@start9labs/shared'
export module Mock { export module Mock {
@@ -626,6 +626,18 @@ export module Mock {
}, },
} }
export const BitcoinDep: DependencyMetadata = {
title: 'Bitcoin Core',
icon: BTC_ICON,
hidden: true,
}
export const ProxyDep: DependencyMetadata = {
title: 'Bitcoin Proxy',
icon: PROXY_ICON,
hidden: false,
}
export const MarketplacePkgs: { export const MarketplacePkgs: {
[id: string]: { [id: string]: {
[version: string]: MarketplacePkg [version: string]: MarketplacePkg
@@ -701,14 +713,8 @@ export module Mock {
categories: ['bitcoin', 'lightning', 'cryptocurrency'], categories: ['bitcoin', 'lightning', 'cryptocurrency'],
versions: ['0.11.0', '0.11.1'], versions: ['0.11.0', '0.11.1'],
'dependency-metadata': { 'dependency-metadata': {
bitcoind: { bitcoind: BitcoinDep,
title: 'Bitcoin Core', 'btc-rpc-proxy': ProxyDep,
icon: BTC_ICON,
},
'btc-rpc-proxy': {
title: 'Bitcoin Proxy',
icon: PROXY_ICON,
},
}, },
'published-at': new Date().toISOString(), 'published-at': new Date().toISOString(),
}, },
@@ -724,14 +730,8 @@ export module Mock {
categories: ['bitcoin', 'lightning', 'cryptocurrency'], categories: ['bitcoin', 'lightning', 'cryptocurrency'],
versions: ['0.11.0', '0.11.1'], versions: ['0.11.0', '0.11.1'],
'dependency-metadata': { 'dependency-metadata': {
bitcoind: { bitcoind: BitcoinDep,
title: 'Bitcoin Core', 'btc-rpc-proxy': ProxyDep,
icon: BTC_ICON,
},
'btc-rpc-proxy': {
title: 'Bitcoin Proxy',
icon: PROXY_ICON,
},
}, },
'published-at': new Date().toISOString(), 'published-at': new Date().toISOString(),
}, },
@@ -743,14 +743,8 @@ export module Mock {
categories: ['bitcoin', 'lightning', 'cryptocurrency'], categories: ['bitcoin', 'lightning', 'cryptocurrency'],
versions: ['0.11.0', '0.11.1'], versions: ['0.11.0', '0.11.1'],
'dependency-metadata': { 'dependency-metadata': {
bitcoind: { bitcoind: BitcoinDep,
title: 'Bitcoin Core', 'btc-rpc-proxy': ProxyDep,
icon: BTC_ICON,
},
'btc-rpc-proxy': {
title: 'Bitcoin Proxy',
icon: PROXY_ICON,
},
}, },
'published-at': new Date(new Date().valueOf() + 10).toISOString(), 'published-at': new Date(new Date().valueOf() + 10).toISOString(),
}, },
@@ -764,10 +758,7 @@ export module Mock {
categories: ['bitcoin'], categories: ['bitcoin'],
versions: ['0.2.2'], versions: ['0.2.2'],
'dependency-metadata': { 'dependency-metadata': {
bitcoind: { bitcoind: BitcoinDep,
title: 'Bitcoin Core',
icon: BTC_ICON,
},
}, },
'published-at': new Date().toISOString(), 'published-at': new Date().toISOString(),
}, },

View File

@@ -26,7 +26,7 @@ export interface UIMarketplaceData {
'selected-url': string 'selected-url': string
'known-hosts': { 'known-hosts': {
'https://registry.start9.com/': UIStore 'https://registry.start9.com/': UIStore
// 'https://community-registry.start9.com/': UIStore 'https://community-registry.start9.com/': UIStore
[url: string]: UIStore [url: string]: UIStore
} }
} }