mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 14:29:45 +00:00
add version-priority to installs
This commit is contained in:
committed by
Aiden McClelland
parent
64e38393df
commit
6789ff5a8c
@@ -78,6 +78,39 @@ pub async fn list(#[context] ctx: RpcContext) -> Result<Vec<(PackageId, Version)
|
|||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, serde::Deserialize, serde::Serialize)]
|
||||||
|
#[serde(rename = "kebab-case")]
|
||||||
|
pub enum MinMax {
|
||||||
|
Min,
|
||||||
|
Max,
|
||||||
|
}
|
||||||
|
impl Default for MinMax {
|
||||||
|
fn default() -> Self {
|
||||||
|
MinMax::Max
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl std::str::FromStr for MinMax {
|
||||||
|
type Err = Error;
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
match s {
|
||||||
|
"min" => Ok(MinMax::Min),
|
||||||
|
"max" => Ok(MinMax::Max),
|
||||||
|
_ => Err(Error::new(
|
||||||
|
eyre!("Must be one of \"min\", \"max\"."),
|
||||||
|
crate::ErrorKind::ParseVersion,
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl std::fmt::Display for MinMax {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
MinMax::Min => write!(f, "min"),
|
||||||
|
MinMax::Max => write!(f, "max"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[command(
|
#[command(
|
||||||
custom_cli(cli_install(async, context(CliContext))),
|
custom_cli(cli_install(async, context(CliContext))),
|
||||||
display(display_none)
|
display(display_none)
|
||||||
@@ -91,6 +124,7 @@ pub async fn install(
|
|||||||
#[arg(short = "v", long = "version-spec", rename = "version-spec")] version_spec: Option<
|
#[arg(short = "v", long = "version-spec", rename = "version-spec")] version_spec: Option<
|
||||||
String,
|
String,
|
||||||
>,
|
>,
|
||||||
|
#[arg(long = "version-priority", rename = "version-priority")] version_priority: Option<MinMax>,
|
||||||
) -> Result<WithRevision<()>, Error> {
|
) -> Result<WithRevision<()>, Error> {
|
||||||
let version_str = match &version_spec {
|
let version_str = match &version_spec {
|
||||||
None => "*",
|
None => "*",
|
||||||
@@ -99,35 +133,36 @@ pub async fn install(
|
|||||||
let version: VersionRange = version_str.parse()?;
|
let version: VersionRange = version_str.parse()?;
|
||||||
let marketplace_url =
|
let marketplace_url =
|
||||||
marketplace_url.unwrap_or_else(|| crate::DEFAULT_MARKETPLACE.parse().unwrap());
|
marketplace_url.unwrap_or_else(|| crate::DEFAULT_MARKETPLACE.parse().unwrap());
|
||||||
let (man_res, s9pk) = tokio::try_join!(
|
let version_priority = version_priority.unwrap_or_default();
|
||||||
reqwest::get(format!(
|
let man: Manifest = reqwest::get(format!(
|
||||||
"{}/package/v0/manifest/{}?spec={}&eos-version-compat={}&arch={}",
|
"{}/package/v0/manifest/{}?spec={}&version-priority={}&eos-version-compat={}&arch={}",
|
||||||
marketplace_url,
|
marketplace_url,
|
||||||
id,
|
id,
|
||||||
version,
|
version,
|
||||||
Current::new().compat(),
|
version_priority,
|
||||||
platforms::TARGET_ARCH,
|
Current::new().compat(),
|
||||||
)),
|
platforms::TARGET_ARCH,
|
||||||
reqwest::get(format!(
|
))
|
||||||
"{}/package/v0/{}.s9pk?spec={}&eos-version-compat={}&arch={}",
|
.await
|
||||||
marketplace_url,
|
.with_kind(crate::ErrorKind::Registry)?
|
||||||
id,
|
.error_for_status()
|
||||||
version,
|
.with_kind(crate::ErrorKind::Registry)?
|
||||||
Current::new().compat(),
|
.json()
|
||||||
platforms::TARGET_ARCH,
|
.await
|
||||||
))
|
.with_kind(crate::ErrorKind::Registry)?;
|
||||||
)
|
let s9pk = reqwest::get(format!(
|
||||||
|
"{}/package/v0/{}.s9pk?spec={}&version-priority={}&eos-version-compat={}&arch={}",
|
||||||
|
marketplace_url,
|
||||||
|
id,
|
||||||
|
version,
|
||||||
|
version_priority,
|
||||||
|
Current::new().compat(),
|
||||||
|
platforms::TARGET_ARCH,
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
.with_kind(crate::ErrorKind::Registry)?
|
||||||
|
.error_for_status()
|
||||||
.with_kind(crate::ErrorKind::Registry)?;
|
.with_kind(crate::ErrorKind::Registry)?;
|
||||||
let man: Manifest = man_res
|
|
||||||
.error_for_status()
|
|
||||||
.with_kind(crate::ErrorKind::Registry)?
|
|
||||||
.json()
|
|
||||||
.await
|
|
||||||
.with_kind(crate::ErrorKind::Registry)?;
|
|
||||||
|
|
||||||
let s9pk = s9pk
|
|
||||||
.error_for_status()
|
|
||||||
.with_kind(crate::ErrorKind::Registry)?;
|
|
||||||
|
|
||||||
if man.id.as_str() != id || !man.version.satisfies(&version) {
|
if man.id.as_str() != id || !man.version.satisfies(&version) {
|
||||||
return Err(Error::new(
|
return Err(Error::new(
|
||||||
@@ -149,10 +184,10 @@ pub async fn install(
|
|||||||
tokio::io::copy(
|
tokio::io::copy(
|
||||||
&mut response_to_reader(
|
&mut response_to_reader(
|
||||||
reqwest::get(format!(
|
reqwest::get(format!(
|
||||||
"{}/package/v0/license/{}?spec={}&eos-version-compat={}&arch={}",
|
"{}/package/v0/license/{}?spec=={}&eos-version-compat={}&arch={}",
|
||||||
marketplace_url,
|
marketplace_url,
|
||||||
id,
|
id,
|
||||||
version,
|
man.version,
|
||||||
Current::new().compat(),
|
Current::new().compat(),
|
||||||
platforms::TARGET_ARCH,
|
platforms::TARGET_ARCH,
|
||||||
))
|
))
|
||||||
@@ -167,10 +202,10 @@ pub async fn install(
|
|||||||
tokio::io::copy(
|
tokio::io::copy(
|
||||||
&mut response_to_reader(
|
&mut response_to_reader(
|
||||||
reqwest::get(format!(
|
reqwest::get(format!(
|
||||||
"{}/package/v0/instructions/{}?spec={}&eos-version-compat={}&arch={}",
|
"{}/package/v0/instructions/{}?spec=={}&eos-version-compat={}&arch={}",
|
||||||
marketplace_url,
|
marketplace_url,
|
||||||
id,
|
id,
|
||||||
version,
|
man.version,
|
||||||
Current::new().compat(),
|
Current::new().compat(),
|
||||||
platforms::TARGET_ARCH,
|
platforms::TARGET_ARCH,
|
||||||
))
|
))
|
||||||
@@ -185,10 +220,10 @@ pub async fn install(
|
|||||||
tokio::io::copy(
|
tokio::io::copy(
|
||||||
&mut response_to_reader(
|
&mut response_to_reader(
|
||||||
reqwest::get(format!(
|
reqwest::get(format!(
|
||||||
"{}/package/v0/icon/{}?spec={}&eos-version-compat={}&arch={}",
|
"{}/package/v0/icon/{}?spec=={}&eos-version-compat={}&arch={}",
|
||||||
marketplace_url,
|
marketplace_url,
|
||||||
id,
|
id,
|
||||||
version,
|
man.version,
|
||||||
Current::new().compat(),
|
Current::new().compat(),
|
||||||
platforms::TARGET_ARCH,
|
platforms::TARGET_ARCH,
|
||||||
))
|
))
|
||||||
@@ -436,6 +471,7 @@ async fn cli_install(
|
|||||||
target: String,
|
target: String,
|
||||||
marketplace_url: Option<Url>,
|
marketplace_url: Option<Url>,
|
||||||
version_spec: Option<String>,
|
version_spec: Option<String>,
|
||||||
|
version_priority: Option<MinMax>,
|
||||||
) -> Result<(), RpcError> {
|
) -> Result<(), RpcError> {
|
||||||
if target.ends_with(".s9pk") {
|
if target.ends_with(".s9pk") {
|
||||||
let path = PathBuf::from(target);
|
let path = PathBuf::from(target);
|
||||||
@@ -479,7 +515,7 @@ async fn cli_install(
|
|||||||
} else {
|
} else {
|
||||||
let params = match (target.split_once("@"), version_spec) {
|
let params = match (target.split_once("@"), version_spec) {
|
||||||
(Some((pkg, v)), None) => {
|
(Some((pkg, v)), None) => {
|
||||||
serde_json::json!({ "id": pkg, "marketplace-url": marketplace_url, "version-spec": v })
|
serde_json::json!({ "id": pkg, "marketplace-url": marketplace_url, "version-spec": v, "version-priority": version_priority })
|
||||||
}
|
}
|
||||||
(Some(_), Some(_)) => {
|
(Some(_), Some(_)) => {
|
||||||
return Err(crate::Error::new(
|
return Err(crate::Error::new(
|
||||||
@@ -489,9 +525,11 @@ async fn cli_install(
|
|||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
(None, Some(v)) => {
|
(None, Some(v)) => {
|
||||||
serde_json::json!({ "id": target, "marketplace-url": marketplace_url, "version-spec": v })
|
serde_json::json!({ "id": target, "marketplace-url": marketplace_url, "version-spec": v, "version-priority": version_priority })
|
||||||
|
}
|
||||||
|
(None, None) => {
|
||||||
|
serde_json::json!({ "id": target, "marketplace-url": marketplace_url, "version-priority": version_priority })
|
||||||
}
|
}
|
||||||
(None, None) => serde_json::json!({ "id": target, "marketplace-url": marketplace_url }),
|
|
||||||
};
|
};
|
||||||
tracing::debug!("calling package.install");
|
tracing::debug!("calling package.install");
|
||||||
rpc_toolkit::command_helpers::call_remote(
|
rpc_toolkit::command_helpers::call_remote(
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export class AppListRecComponent {
|
|||||||
readonly installing$ = this.install$.pipe(
|
readonly installing$ = this.install$.pipe(
|
||||||
switchMap(({ id, version }) =>
|
switchMap(({ id, version }) =>
|
||||||
// Mapping each installation to API request
|
// Mapping each installation to API request
|
||||||
from(this.api.installPackage({ id, 'version-spec': `=${version}` })).pipe(
|
from(this.api.installPackage({ id, 'version-spec': `>=${version}`, 'version-priority': 'min' })).pipe(
|
||||||
// Mapping operation to true/false loading indication
|
// Mapping operation to true/false loading indication
|
||||||
loading(this.errToast),
|
loading(this.errToast),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -179,6 +179,7 @@ export module RR {
|
|||||||
export type InstallPackageReq = WithExpire<{
|
export type InstallPackageReq = WithExpire<{
|
||||||
id: string
|
id: string
|
||||||
'version-spec'?: string
|
'version-spec'?: string
|
||||||
|
'version-priority'?: 'min' | 'max'
|
||||||
}> // package.install
|
}> // package.install
|
||||||
export type InstallPackageRes = WithRevision<null>
|
export type InstallPackageRes = WithRevision<null>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user