Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ jobs:
target/
key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }}

# - name: Install WASM toolchain
# run: rustup target add wasm32-unknown-unknown
- name: Install WASM toolchain
run: rustup target add wasm32-unknown-unknown

- name: Check project
run: cargo clippy --workspace --all-targets --all-features -- -D warnings

# - name: Check project (WASM)
# # Note lack of --all-targets here because tests and examples are not wasm compatible
# run: cargo clippy --workspace --all-features --target wasm32-unknown-unknown -- -D warnings
- name: Check project (WASM)
# Note lack of --all-targets here because tests and examples are not wasm compatible
# (the CLI binary compiles as an empty stub). getrandom 0.3 requires selecting its
# JS backend explicitly on wasm32-unknown-unknown.
run: RUSTFLAGS='--cfg getrandom_backend="wasm_js"' cargo clippy --workspace --all-features --target wasm32-unknown-unknown -- -D warnings

test:
runs-on: ubuntu-latest
Expand Down
8 changes: 8 additions & 0 deletions Cargo.lock

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

20 changes: 16 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@ edition = "2024"

[dependencies]
chrono = { version = "0.4", features = ["serde"] }
glob = "0.3"
log = "0.4"
mime = "0.3"
rand = "0.8"
regex = "1"
sha2 = "0.10"
uuid = { version = "1", features = ["v4"] }

reqwest = { version = "0.12", features = ["json"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1", features = ["full"] }

fontdb = "0.16"
resvg = "0.41"
Expand All @@ -43,7 +40,22 @@ xml5ever = "0.18"

image = { version = "0.25", default-features = false, features = ["bmp", "gif", "jpeg", "png", "webp"] }

slug = "0.1"

# Native-only dependencies: networking, async runtime, filesystem cache, and the CLI.
# The library builds for wasm32 without them (see src/lib.rs cfg gates); the
# `Thread::to_epub_remote_images` path is fully available on wasm.
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
glob = "0.3"
reqwest = { version = "0.12", features = ["json"] }
tokio = { version = "1", features = ["full"] }
clap = { version = "4", features = ["derive"] }
simple_logger = "4"
slug = "0.1"
rpassword = "7.3.1"

# On wasm32-unknown-unknown, getrandom needs its JS backends enabled
# (pulled in transitively via `rand` and `uuid`).
[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom02 = { package = "getrandom", version = "0.2", features = ["js"] }
getrandom03 = { package = "getrandom", version = "0.3", features = ["wasm_js"] }
uuid = { version = "1", features = ["js"] }
55 changes: 27 additions & 28 deletions src/cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,13 @@ impl Replies {
) -> Result<Result<Vec<Reply>, Vec<GlowficError>>, Box<dyn Error>> {
let cache_path = Self::cache_key(id);

if !invalidate_cache {
if let Ok(data) = std::fs::read(&cache_path) {
let parsed: Result<Self, Vec<GlowficError>> =
serde_json::from_slice(&data).unwrap();
if !invalidate_cache
&& let Ok(data) = std::fs::read(&cache_path)
{
let parsed: Result<Self, Vec<GlowficError>> = serde_json::from_slice(&data).unwrap();

if let Ok(replies) = parsed {
return Ok(Ok(replies.0));
}
if let Ok(replies) = parsed {
return Ok(Ok(replies.0));
}
}

Expand All @@ -88,14 +87,14 @@ impl BoardPosts {
) -> Result<Result<Vec<PostInBoard>, Vec<GlowficError>>, Box<dyn Error>> {
let cache_path = Self::cache_key(id);

if !invalidate_cache {
if let Ok(data) = std::fs::read(&cache_path) {
let parsed: Result<Vec<PostInBoard>, Vec<GlowficError>> =
serde_json::from_slice(&data).unwrap();
if !invalidate_cache
&& let Ok(data) = std::fs::read(&cache_path)
{
let parsed: Result<Vec<PostInBoard>, Vec<GlowficError>> =
serde_json::from_slice(&data).unwrap();

if let Ok(posts) = parsed {
return Ok(Ok(posts));
}
if let Ok(posts) = parsed {
return Ok(Ok(posts));
}
}

Expand Down Expand Up @@ -124,10 +123,10 @@ impl Icon {
return Err("No url provided for this icon".into());
};

if !invalidate_cache {
if let Ok((mime, data)) = read_image_file(Self::cache_key(*id, "*")) {
return Ok((mime, data));
}
if !invalidate_cache
&& let Ok((mime, data)) = read_image_file(Self::cache_key(*id, "*"))
{
return Ok((mime, data));
}

log::info!("Downloading icon {id} from {url}");
Expand Down Expand Up @@ -232,10 +231,10 @@ pub async fn download_cached_image(

let hash = url_hash(url);

if !invalidate_cache {
if let Ok((mime, data)) = read_image_file(image_cache_key(&hash, "*")) {
return Ok((mime, data));
}
if !invalidate_cache
&& let Ok((mime, data)) = read_image_file(image_cache_key(&hash, "*"))
{
return Ok((mime, data));
}

log::info!("Downloading image {hash} from {url}");
Expand All @@ -261,12 +260,12 @@ async fn get_cached_glowfic<T>(
where
T: DeserializeOwned + Serialize,
{
if !invalidate_cache {
if let Ok(data) = std::fs::read(cache_path) {
let parsed: Result<T, Vec<GlowficError>> = serde_json::from_slice(&data).unwrap();
if parsed.is_ok() {
return Ok(parsed);
}
if !invalidate_cache
&& let Ok(data) = std::fs::read(cache_path)
{
let parsed: Result<T, Vec<GlowficError>> = serde_json::from_slice(&data).unwrap();
if parsed.is_ok() {
return Ok(parsed);
}
}
let response = crate::api::get_glowfic(url).await?;
Expand Down
Loading