mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
pluralize
This commit is contained in:
@@ -145,7 +145,7 @@ pub async fn install(
|
|||||||
let (_, asset) = package
|
let (_, asset) = package
|
||||||
.best
|
.best
|
||||||
.get(&version)
|
.get(&version)
|
||||||
.and_then(|i| i.s9pk.first())
|
.and_then(|i| i.s9pks.first())
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
Error::new(
|
Error::new(
|
||||||
eyre!("{id}@{version} not found on {registry}"),
|
eyre!("{id}@{version} not found on {registry}"),
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ pub struct RegistryAsset<Commitment> {
|
|||||||
#[ts(type = "string")]
|
#[ts(type = "string")]
|
||||||
pub published_at: DateTime<Utc>,
|
pub published_at: DateTime<Utc>,
|
||||||
#[ts(type = "string[]")]
|
#[ts(type = "string[]")]
|
||||||
pub url: Vec<Url>,
|
pub urls: Vec<Url>,
|
||||||
pub commitment: Commitment,
|
pub commitment: Commitment,
|
||||||
pub signatures: HashMap<AnyVerifyingKey, AnySignature>,
|
pub signatures: HashMap<AnyVerifyingKey, AnySignature>,
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,7 @@ impl<Commitment> RegistryAsset<Commitment> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
pub async fn load_http_source(&self, client: Client) -> Result<HttpSource, Error> {
|
pub async fn load_http_source(&self, client: Client) -> Result<HttpSource, Error> {
|
||||||
for url in &self.url {
|
for url in &self.urls {
|
||||||
if let Ok(source) = HttpSource::new(client.clone(), url.clone()).await {
|
if let Ok(source) = HttpSource::new(client.clone(), url.clone()).await {
|
||||||
return Ok(source);
|
return Ok(source);
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ impl<Commitment> RegistryAsset<Commitment> {
|
|||||||
client: Client,
|
client: Client,
|
||||||
progress: PhaseProgressTrackerHandle,
|
progress: PhaseProgressTrackerHandle,
|
||||||
) -> Result<BufferedHttpSource, Error> {
|
) -> Result<BufferedHttpSource, Error> {
|
||||||
for url in &self.url {
|
for url in &self.urls {
|
||||||
if let Ok(response) = client.get(url.clone()).send().await {
|
if let Ok(response) = client.get(url.clone()).send().await {
|
||||||
return BufferedHttpSource::from_response(response, progress).await;
|
return BufferedHttpSource::from_response(response, progress).await;
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ impl<Commitment> RegistryAsset<Commitment> {
|
|||||||
client: Client,
|
client: Client,
|
||||||
progress: PhaseProgressTrackerHandle,
|
progress: PhaseProgressTrackerHandle,
|
||||||
) -> Result<BufferedHttpSource, Error> {
|
) -> Result<BufferedHttpSource, Error> {
|
||||||
for url in &self.url {
|
for url in &self.urls {
|
||||||
if let Ok(response) = client.get(url.clone()).send().await {
|
if let Ok(response) = client.get(url.clone()).send().await {
|
||||||
return BufferedHttpSource::from_response_with_path(path, response, progress).await;
|
return BufferedHttpSource::from_response_with_path(path, response, progress).await;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ async fn add_asset(
|
|||||||
.upsert(&platform, || {
|
.upsert(&platform, || {
|
||||||
Ok(RegistryAsset {
|
Ok(RegistryAsset {
|
||||||
published_at: Utc::now(),
|
published_at: Utc::now(),
|
||||||
url: vec![url.clone()],
|
urls: vec![url.clone()],
|
||||||
commitment: commitment.clone(),
|
commitment: commitment.clone(),
|
||||||
signatures: HashMap::new(),
|
signatures: HashMap::new(),
|
||||||
})
|
})
|
||||||
@@ -146,8 +146,8 @@ async fn add_asset(
|
|||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
s.signatures.insert(signer, signature);
|
s.signatures.insert(signer, signature);
|
||||||
if !s.url.contains(&url) {
|
if !s.urls.contains(&url) {
|
||||||
s.url.push(url);
|
s.urls.push(url);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ pub async fn add_package(
|
|||||||
let manifest = s9pk.as_manifest();
|
let manifest = s9pk.as_manifest();
|
||||||
|
|
||||||
let mut info = PackageVersionInfo::from_s9pk(&s9pk, url).await?;
|
let mut info = PackageVersionInfo::from_s9pk(&s9pk, url).await?;
|
||||||
for (_, s9pk) in &mut info.s9pk {
|
for (_, s9pk) in &mut info.s9pks {
|
||||||
if !s9pk.signatures.contains_key(&uploader) && s9pk.commitment == commitment {
|
if !s9pk.signatures.contains_key(&uploader) && s9pk.commitment == commitment {
|
||||||
s9pk.signatures.insert(uploader.clone(), signature.clone());
|
s9pk.signatures.insert(uploader.clone(), signature.clone());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ fn get_matching_models<'a>(
|
|||||||
if let Some(device_info) = &device_info {
|
if let Some(device_info) = &device_info {
|
||||||
info.for_device(device_info)?
|
info.for_device(device_info)?
|
||||||
} else {
|
} else {
|
||||||
Some(info.as_s9pk().de()?)
|
Some(info.as_s9pks().de()?)
|
||||||
}
|
}
|
||||||
.map(|assets| (k.clone(), ExtendedVersion::from(v), info, assets))
|
.map(|assets| (k.clone(), ExtendedVersion::from(v), info, assets))
|
||||||
} else {
|
} else {
|
||||||
@@ -266,7 +266,7 @@ pub async fn get_package(ctx: RegistryContext, params: GetPackageParams) -> Resu
|
|||||||
PackageVersionInfo {
|
PackageVersionInfo {
|
||||||
metadata: i.as_metadata().de()?,
|
metadata: i.as_metadata().de()?,
|
||||||
source_version: i.as_source_version().de()?,
|
source_version: i.as_source_version().de()?,
|
||||||
s9pk: a,
|
s9pks: a,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
@@ -299,7 +299,7 @@ pub async fn get_package(ctx: RegistryContext, params: GetPackageParams) -> Resu
|
|||||||
PackageVersionInfo {
|
PackageVersionInfo {
|
||||||
metadata: i.as_metadata().de()?,
|
metadata: i.as_metadata().de()?,
|
||||||
source_version: i.as_source_version().de()?,
|
source_version: i.as_source_version().de()?,
|
||||||
s9pk: a,
|
s9pks: a,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
@@ -362,7 +362,7 @@ pub async fn get_package(ctx: RegistryContext, params: GetPackageParams) -> Resu
|
|||||||
PackageVersionInfo {
|
PackageVersionInfo {
|
||||||
metadata: i.as_metadata().de()?,
|
metadata: i.as_metadata().de()?,
|
||||||
source_version: i.as_source_version().de()?,
|
source_version: i.as_source_version().de()?,
|
||||||
s9pk: a,
|
s9pks: a,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
@@ -406,7 +406,7 @@ pub async fn get_package(ctx: RegistryContext, params: GetPackageParams) -> Resu
|
|||||||
PackageVersionInfo {
|
PackageVersionInfo {
|
||||||
metadata: i.as_metadata().de()?,
|
metadata: i.as_metadata().de()?,
|
||||||
source_version: i.as_source_version().de()?,
|
source_version: i.as_source_version().de()?,
|
||||||
s9pk: a,
|
s9pks: a,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
@@ -420,7 +420,7 @@ pub async fn get_package(ctx: RegistryContext, params: GetPackageParams) -> Resu
|
|||||||
PackageVersionInfo {
|
PackageVersionInfo {
|
||||||
metadata: i.as_metadata().de()?,
|
metadata: i.as_metadata().de()?,
|
||||||
source_version: i.as_source_version().de()?,
|
source_version: i.as_source_version().de()?,
|
||||||
s9pk: a,
|
s9pks: a,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
@@ -511,7 +511,9 @@ pub async fn cli_download(
|
|||||||
)
|
)
|
||||||
.await?,
|
.await?,
|
||||||
)?;
|
)?;
|
||||||
let PackageVersionInfo { mut s9pk, .. } = match res.best.len() {
|
let PackageVersionInfo {
|
||||||
|
s9pks: mut s9pk, ..
|
||||||
|
} = match res.best.len() {
|
||||||
0 => {
|
0 => {
|
||||||
return Err(Error::new(
|
return Err(Error::new(
|
||||||
eyre!(
|
eyre!(
|
||||||
|
|||||||
@@ -142,18 +142,18 @@ pub struct PackageVersionInfo {
|
|||||||
pub metadata: PackageMetadata,
|
pub metadata: PackageMetadata,
|
||||||
#[ts(type = "string | null")]
|
#[ts(type = "string | null")]
|
||||||
pub source_version: Option<VersionRange>,
|
pub source_version: Option<VersionRange>,
|
||||||
pub s9pk: Vec<(HardwareRequirements, RegistryAsset<MerkleArchiveCommitment>)>,
|
pub s9pks: Vec<(HardwareRequirements, RegistryAsset<MerkleArchiveCommitment>)>,
|
||||||
}
|
}
|
||||||
impl PackageVersionInfo {
|
impl PackageVersionInfo {
|
||||||
pub async fn from_s9pk<S: FileSource + Clone>(s9pk: &S9pk<S>, url: Url) -> Result<Self, Error> {
|
pub async fn from_s9pk<S: FileSource + Clone>(s9pk: &S9pk<S>, url: Url) -> Result<Self, Error> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
metadata: PackageMetadata::load(s9pk).await?,
|
metadata: PackageMetadata::load(s9pk).await?,
|
||||||
source_version: None, // TODO
|
source_version: None, // TODO
|
||||||
s9pk: vec![(
|
s9pks: vec![(
|
||||||
s9pk.as_manifest().hardware_requirements.clone(),
|
s9pk.as_manifest().hardware_requirements.clone(),
|
||||||
RegistryAsset {
|
RegistryAsset {
|
||||||
published_at: Utc::now(),
|
published_at: Utc::now(),
|
||||||
url: vec![url],
|
urls: vec![url],
|
||||||
commitment: s9pk.as_archive().commitment().await?,
|
commitment: s9pk.as_archive().commitment().await?,
|
||||||
signatures: [(
|
signatures: [(
|
||||||
AnyVerifyingKey::Ed25519(s9pk.as_archive().signer()),
|
AnyVerifyingKey::Ed25519(s9pk.as_archive().signer()),
|
||||||
@@ -166,28 +166,28 @@ impl PackageVersionInfo {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub fn merge_with(&mut self, other: Self) -> Result<(), Error> {
|
pub fn merge_with(&mut self, other: Self) -> Result<(), Error> {
|
||||||
for (hw_req, asset) in other.s9pk {
|
for (hw_req, asset) in other.s9pks {
|
||||||
if let Some((_, matching)) = self
|
if let Some((_, matching)) = self
|
||||||
.s9pk
|
.s9pks
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.find(|(h, s)| s.commitment == asset.commitment && *h == hw_req)
|
.find(|(h, s)| s.commitment == asset.commitment && *h == hw_req)
|
||||||
{
|
{
|
||||||
for url in asset.url {
|
for url in asset.urls {
|
||||||
if matching.url.contains(&url) {
|
if matching.urls.contains(&url) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
matching.url.push(url);
|
matching.urls.push(url);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if let Some((h, matching)) = self.s9pk.iter_mut().find(|(h, _)| *h == hw_req) {
|
if let Some((h, matching)) = self.s9pks.iter_mut().find(|(h, _)| *h == hw_req) {
|
||||||
*matching = asset;
|
*matching = asset;
|
||||||
*h = hw_req;
|
*h = hw_req;
|
||||||
} else {
|
} else {
|
||||||
self.s9pk.push((hw_req, asset));
|
self.s9pks.push((hw_req, asset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.s9pk.sort_by_key(|(h, _)| h.specificity_desc());
|
self.s9pks.sort_by_key(|(h, _)| h.specificity_desc());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn table(&self, version: &VersionString) -> prettytable::Table {
|
pub fn table(&self, version: &VersionString) -> prettytable::Table {
|
||||||
@@ -229,7 +229,7 @@ impl Model<PackageVersionInfo> {
|
|||||||
{
|
{
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
let mut s9pk = self.as_s9pk().de()?;
|
let mut s9pk = self.as_s9pks().de()?;
|
||||||
s9pk.retain(|(hw, _)| {
|
s9pk.retain(|(hw, _)| {
|
||||||
if let Some(arch) = &hw.arch {
|
if let Some(arch) = &hw.arch {
|
||||||
if !arch.contains(&device_info.hardware.arch) {
|
if !arch.contains(&device_info.hardware.arch) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import type { RegistryAsset } from "./RegistryAsset"
|
|||||||
|
|
||||||
export type PackageVersionInfo = {
|
export type PackageVersionInfo = {
|
||||||
sourceVersion: string | null
|
sourceVersion: string | null
|
||||||
s9pk: Array<[HardwareRequirements, RegistryAsset<MerkleArchiveCommitment>]>
|
s9pks: Array<[HardwareRequirements, RegistryAsset<MerkleArchiveCommitment>]>
|
||||||
title: string
|
title: string
|
||||||
icon: DataUrl
|
icon: DataUrl
|
||||||
description: Description
|
description: Description
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import type { AnyVerifyingKey } from "./AnyVerifyingKey"
|
|||||||
|
|
||||||
export type RegistryAsset<Commitment> = {
|
export type RegistryAsset<Commitment> = {
|
||||||
publishedAt: string
|
publishedAt: string
|
||||||
url: string[]
|
urls: string[]
|
||||||
commitment: Commitment
|
commitment: Commitment
|
||||||
signatures: { [key: AnyVerifyingKey]: AnySignature }
|
signatures: { [key: AnyVerifyingKey]: AnySignature }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user