mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 22:39:46 +00:00
handle new content-types from marketplace.get
This commit is contained in:
committed by
Aiden McClelland
parent
c640749c7c
commit
8b286431e6
1
backend/Cargo.lock
generated
1
backend/Cargo.lock
generated
@@ -865,6 +865,7 @@ dependencies = [
|
|||||||
"async-trait",
|
"async-trait",
|
||||||
"avahi-sys",
|
"avahi-sys",
|
||||||
"base32",
|
"base32",
|
||||||
|
"base64",
|
||||||
"basic-cookies",
|
"basic-cookies",
|
||||||
"bollard",
|
"bollard",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ avahi-sys = { git = "https://github.com/Start9Labs/avahi-sys", version = "0.10.0
|
|||||||
"dynamic",
|
"dynamic",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
base32 = "0.4.0"
|
base32 = "0.4.0"
|
||||||
|
base64 = "0.13.0"
|
||||||
basic-cookies = "0.1.4"
|
basic-cookies = "0.1.4"
|
||||||
bollard = "0.11.0"
|
bollard = "0.11.0"
|
||||||
chrono = { version = "0.4.19", features = ["serde"] }
|
chrono = { version = "0.4.19", features = ["serde"] }
|
||||||
|
|||||||
@@ -12,15 +12,43 @@ pub fn marketplace() -> Result<(), Error> {
|
|||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
pub async fn get(#[arg] url: Url) -> Result<Value, Error> {
|
pub async fn get(#[arg] url: Url) -> Result<Value, Error> {
|
||||||
let response = reqwest::get(url)
|
let mut response = reqwest::get(url)
|
||||||
.await
|
.await
|
||||||
.with_kind(crate::ErrorKind::Network)?;
|
.with_kind(crate::ErrorKind::Network)?;
|
||||||
let status = response.status();
|
let status = response.status();
|
||||||
if status.is_success() {
|
if status.is_success() {
|
||||||
response
|
match response
|
||||||
.json()
|
.headers_mut()
|
||||||
.await
|
.remove("Content-Type")
|
||||||
.with_kind(crate::ErrorKind::Deserialization)
|
.as_ref()
|
||||||
|
.and_then(|h| h.to_str().ok())
|
||||||
|
{
|
||||||
|
Some("application/json") => response
|
||||||
|
.json()
|
||||||
|
.await
|
||||||
|
.with_kind(crate::ErrorKind::Deserialization),
|
||||||
|
Some("text/plain") => Ok(Value::String(
|
||||||
|
response
|
||||||
|
.text()
|
||||||
|
.await
|
||||||
|
.with_kind(crate::ErrorKind::Registry)?,
|
||||||
|
)),
|
||||||
|
Some(ctype) => Ok(Value::String(format!(
|
||||||
|
"data:{};base64,{}",
|
||||||
|
ctype,
|
||||||
|
base64::encode_config(
|
||||||
|
&response
|
||||||
|
.bytes()
|
||||||
|
.await
|
||||||
|
.with_kind(crate::ErrorKind::Registry)?,
|
||||||
|
base64::URL_SAFE
|
||||||
|
)
|
||||||
|
))),
|
||||||
|
_ => Err(Error::new(
|
||||||
|
eyre!("missing Content-Type"),
|
||||||
|
crate::ErrorKind::Registry,
|
||||||
|
)),
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let message = response.text().await.with_kind(crate::ErrorKind::Network)?;
|
let message = response.text().await.with_kind(crate::ErrorKind::Network)?;
|
||||||
Err(Error::new(
|
Err(Error::new(
|
||||||
|
|||||||
Reference in New Issue
Block a user