update headers to new type from reqwasm

master
Ninja3047 2022-07-10 23:31:04 -04:00 committed by Edward Shen
parent 711f79a255
commit c934b36b35
3 changed files with 43 additions and 41 deletions

View File

@ -9,24 +9,24 @@ license = "MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
base64 = "0.13"
bytes = { version = "1", features = ["serde"] }
chacha20poly1305 = { version = "0.9", features = ["stream", "std"] }
chrono = { version = "0.4", features = ["serde"] }
headers = "0.3"
lazy_static = "1"
rand = "0.8"
secrecy = "0.8"
serde = { version = "1", features = ["derive"] }
thiserror = "1"
typenum = "1"
url = "2"
argon2 = "0.3.1"
base64 = "0.13.0"
bytes = { version = "1.1.0", features = ["serde"] }
chacha20poly1305 = { version = "0.9.1", features = ["stream", "std"] }
chrono = { version = "0.4.19", features = ["serde"] }
headers = "0.3.7"
lazy_static = "1.4.0"
rand = "0.8.5"
secrecy = "0.8.0"
serde = { version = "1.0.138", features = ["derive"] }
thiserror = "1.0.31"
typenum = "1.15.0"
url = "2.2.2"
argon2 = "0.4.1"
# Wasm features
gloo-console = { version = "0.2", optional = true }
http = { version = "0.2", optional = true }
web-sys = { version = "0.3", features = ["Headers"], optional = true }
gloo-console = { version = "0.2.1", optional = true }
reqwasm = { version = "0.5.0", optional = true }
http = { version = "0.2.8", optional = true }
[features]
wasm = ["gloo-console", "http", "web-sys"]
wasm = ["gloo-console", "reqwasm", "http"]

View File

@ -1,4 +1,6 @@
#![warn(clippy::nursery, clippy::pedantic)]
// False positive: https://github.com/rust-lang/rust-clippy/issues/6902
#![allow(clippy::use_self)]
//! Contains common functions and structures used by multiple projects
@ -230,10 +232,10 @@ expiration_from_str! {
impl Display for Expiration {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Expiration::BurnAfterReading | Expiration::BurnAfterReadingWithDeadline(_) => {
Self::BurnAfterReading | Self::BurnAfterReadingWithDeadline(_) => {
write!(f, "This item has been burned. You now have the only copy.")
}
Expiration::UnixTime(time) => write!(
Self::UnixTime(time) => write!(
f,
"{}",
time.format("This item will expire on %A, %B %-d, %Y at %T %Z.")
@ -248,7 +250,7 @@ lazy_static! {
impl Header for Expiration {
fn name() -> &'static HeaderName {
&*EXPIRATION_HEADER_NAME
&EXPIRATION_HEADER_NAME
}
fn decode<'i, I>(values: &mut I) -> Result<Self, headers::Error>
@ -282,6 +284,8 @@ impl From<&Expiration> for HeaderValue {
}
impl From<Expiration> for HeaderValue {
// False positive: https://github.com/rust-lang/rust-clippy/issues/9095
#[allow(clippy::needless_borrow)]
fn from(expiration: Expiration) -> Self {
(&expiration).into()
}
@ -290,14 +294,12 @@ impl From<Expiration> for HeaderValue {
pub struct ParseHeaderValueError;
#[cfg(feature = "wasm")]
impl TryFrom<web_sys::Headers> for Expiration {
impl TryFrom<reqwasm::http::Headers> for Expiration {
type Error = ParseHeaderValueError;
fn try_from(headers: web_sys::Headers) -> Result<Self, Self::Error> {
fn try_from(headers: reqwasm::http::Headers) -> Result<Self, Self::Error> {
headers
.get(http::header::EXPIRES.as_str())
.ok()
.flatten()
.as_deref()
.and_then(|v| Self::try_from(v).ok())
.ok_or(ParseHeaderValueError)

View File

@ -9,27 +9,27 @@ crate-type = ["cdylib"]
[dependencies]
omegaupload-common = { path = "../common", features = ["wasm"] }
# Enables wasm support
getrandom = { version = "*", features = ["js"] }
getrandom = { version = "0.2.7", features = ["js"] }
anyhow = "1"
bytes = "1"
byte-unit = "4"
console_error_panic_hook = "0.1"
gloo-console = "0.2"
http = "0.2"
js-sys = "0.3"
mime_guess = "2"
reqwasm = "0.4"
tree_magic_mini = { version = "3", features = ["with-gpl-data"] }
serde = { version = "1.0", features = ["derive"] }
wasm-bindgen = { version = "0.2", features = ["serde-serialize"]}
wasm-bindgen-futures = "0.4"
zip = { version = "0.5", default-features = false, features = ["deflate"] }
flate2 = "1.0.22"
anyhow = "1.0.58"
bytes = "1.1.0"
byte-unit = "4.0.14"
console_error_panic_hook = "0.1.7"
gloo-console = "0.2.1"
http = "0.2.8"
js-sys = "0.3.58"
mime_guess = "2.0.4"
reqwasm = "0.5.0"
tree_magic_mini = { version = "3.0.3", features = ["with-gpl-data"] }
serde = { version = "1.0.138", features = ["derive"] }
wasm-bindgen = { version = "0.2.81", features = ["serde-serialize"] }
wasm-bindgen-futures = "0.4.31"
zip = { version = "0.6.2", default-features = false, features = ["deflate"] }
flate2 = "1.0.24"
tar = "0.4.38"
[dependencies.web-sys]
version = "0.3"
version = "0.3.58"
features = [
"BlobPropertyBag",
"TextDecoder",