Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zakstucke committed Jun 19, 2024
1 parent 6820d68 commit e67087c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
12 changes: 12 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,15 @@ opentelemetry-http = [ # In general there's no point with this currently, made f
rayon = ['dep:rayon']

# Cookie deps depending on wasm or not:
[target.'cfg(not(target_arch = "wasm32"))'.features]
cookies = [
cookies_ssr = [
'dep:http',
'dep:serde_json',
'dep:axum-extra',
'axum-extra/cookie',
'dep:leptos',
'dep:leptos_axum',
]
[target.'cfg(target_arch = "wasm32")'.features]
cookies = ['dep:http', 'dep:serde_json', 'dep:wasm-cookies']
cookies_wasm = ['dep:http', 'dep:serde_json', 'dep:wasm-cookies']

[profile.release]
strip = "debuginfo" # Note: true or "symbols" seems to break static c linking e.g. with ffmpeg.
Expand Down
19 changes: 11 additions & 8 deletions rust/bitbazaar/cookies/cookies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn set_cookie(name: &str, value: &impl serde::Serialize, options: CookieOpti
/// Get the raw value of a cookie.
/// If the cookie isn't found, returns None.
pub fn get_cookie_raw(name: &str) -> Option<String> {
#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(not(target_arch = "wasm32"), feature = "cookies_ssr"))]
{
use axum_extra::extract::cookie::CookieJar;
if let Some(req) = leptos::use_context::<http::request::Parts>() {
Expand All @@ -55,27 +55,30 @@ pub fn get_cookie_raw(name: &str) -> Option<String> {
return Some(cookie.value().to_string());
}
}
None
return None;
}

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", feature = "cookies_wasm"))]
{
if let Some(Ok(value)) = wasm_cookies::get(name) {
Some(value)
return Some(value);
} else {
None
return None;
}
}

#[allow(unreachable_code)]
None
}

/// Set a new cookie with the given name and raw value.
pub fn set_cookie_raw(name: &str, value: &str, options: CookieOptions<'_>) {
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", feature = "cookies_wasm"))]
{
wasm_cookies::set(name, value, &options.into())
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(all(not(target_arch = "wasm32"), feature = "cookies_ssr"))]
{
use axum_extra::extract::cookie::Cookie;

Expand Down Expand Up @@ -155,7 +158,7 @@ impl Default for SameSite {
}
}

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", feature = "cookies_wasm"))]
/// Conversion to the wasm_cookies which was originally created from:
impl<'a> From<CookieOptions<'a>> for wasm_cookies::CookieOptions<'a> {
fn from(options: CookieOptions<'a>) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions rust/bitbazaar/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub mod cli;
#[cfg(feature = "chrono")]
/// Chrono utilities
pub mod chrono;
#[cfg(feature = "cookies")]
/// Setting/getting cookies in frontend or ssr.
#[cfg(any(feature = "cookies_ssr", feature = "cookies_wasm"))]
/// Setting/getting cookies in wasm or ssr.
pub mod cookies;
/// Error handling utilities.
pub mod errors;
Expand Down

0 comments on commit e67087c

Please sign in to comment.