mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-02 05:23:14 +00:00
feat: support data URLs, http(s) URLs, and file:// URLs in registry set-icon CLI
This commit is contained in:
@@ -2959,6 +2959,13 @@ help.arg.icon-path:
|
||||
fr_FR: "Chemin vers le fichier d'icône du service"
|
||||
pl_PL: "Ścieżka do pliku ikony usługi"
|
||||
|
||||
help.arg.icon-source:
|
||||
en_US: "Icon source: file path, file:// URL, http(s):// URL, or data: URL"
|
||||
de_DE: "Icon-Quelle: Dateipfad, file://-URL, http(s)://-URL oder data:-URL"
|
||||
es_ES: "Fuente del icono: ruta de archivo, URL file://, URL http(s):// o URL data:"
|
||||
fr_FR: "Source de l'icône : chemin de fichier, URL file://, URL http(s):// ou URL data:"
|
||||
pl_PL: "Źródło ikony: ścieżka pliku, URL file://, URL http(s):// lub URL data:"
|
||||
|
||||
help.arg.image-id:
|
||||
en_US: "Docker image identifier"
|
||||
de_DE: "Docker-Image-Kennung"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::Parser;
|
||||
use imbl_value::InternedString;
|
||||
@@ -107,8 +106,8 @@ pub async fn set_icon(
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export)]
|
||||
pub struct CliSetIconParams {
|
||||
#[arg(help = "help.arg.icon-path")]
|
||||
pub icon: PathBuf,
|
||||
#[arg(help = "help.arg.icon-source")]
|
||||
pub icon: String,
|
||||
}
|
||||
|
||||
pub async fn cli_set_icon(
|
||||
@@ -120,7 +119,23 @@ pub async fn cli_set_icon(
|
||||
..
|
||||
}: HandlerArgs<CliContext, CliSetIconParams>,
|
||||
) -> Result<(), Error> {
|
||||
let data_url = DataUrl::from_path(icon).await?;
|
||||
let data_url = if icon.starts_with("data:") {
|
||||
icon.parse::<DataUrl<'static>>()
|
||||
.with_kind(ErrorKind::ParseUrl)?
|
||||
} else if icon.starts_with("https://") || icon.starts_with("http://") {
|
||||
let res = ctx
|
||||
.client
|
||||
.get(&icon)
|
||||
.send()
|
||||
.await
|
||||
.with_kind(ErrorKind::Network)?;
|
||||
DataUrl::from_response(res).await?
|
||||
} else {
|
||||
let path = icon
|
||||
.strip_prefix("file://")
|
||||
.unwrap_or(&icon);
|
||||
DataUrl::from_path(path).await?
|
||||
};
|
||||
ctx.call_remote::<RegistryContext>(
|
||||
&parent_method.into_iter().chain(method).join("."),
|
||||
imbl_value::json!({
|
||||
|
||||
Reference in New Issue
Block a user