mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +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",
|
||||
"avahi-sys",
|
||||
"base32",
|
||||
"base64",
|
||||
"basic-cookies",
|
||||
"bollard",
|
||||
"chrono",
|
||||
|
||||
@@ -51,6 +51,7 @@ avahi-sys = { git = "https://github.com/Start9Labs/avahi-sys", version = "0.10.0
|
||||
"dynamic",
|
||||
], optional = true }
|
||||
base32 = "0.4.0"
|
||||
base64 = "0.13.0"
|
||||
basic-cookies = "0.1.4"
|
||||
bollard = "0.11.0"
|
||||
chrono = { version = "0.4.19", features = ["serde"] }
|
||||
|
||||
@@ -12,15 +12,43 @@ pub fn marketplace() -> Result<(), Error> {
|
||||
|
||||
#[command]
|
||||
pub async fn get(#[arg] url: Url) -> Result<Value, Error> {
|
||||
let response = reqwest::get(url)
|
||||
let mut response = reqwest::get(url)
|
||||
.await
|
||||
.with_kind(crate::ErrorKind::Network)?;
|
||||
let status = response.status();
|
||||
if status.is_success() {
|
||||
response
|
||||
match response
|
||||
.headers_mut()
|
||||
.remove("Content-Type")
|
||||
.as_ref()
|
||||
.and_then(|h| h.to_str().ok())
|
||||
{
|
||||
Some("application/json") => response
|
||||
.json()
|
||||
.await
|
||||
.with_kind(crate::ErrorKind::Deserialization)
|
||||
.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 {
|
||||
let message = response.text().await.with_kind(crate::ErrorKind::Network)?;
|
||||
Err(Error::new(
|
||||
|
||||
Reference in New Issue
Block a user