From b258b8e2426232368912468e90130ca73e7130b3 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 3 Aug 2025 23:50:56 +0300 Subject: [PATCH] use `c5cc9113e2da0a5be272b0392691d6ab6e037224` api revision --- Cargo.toml | 2 +- src/main.rs | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3b4de5e..4eaa142 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,5 +23,5 @@ libyggtracker-redb = "0.1" [patch.crates-io] librqbit = { git = "https://github.com/ikatson/rqbit.git", rev="b580a9610ae7c6eaacd305a3905f7e2d3202ca69" } -libyggtracker-redb = { git = "https://github.com/YGGverse/libyggtracker-redb.git", rev="5a9dc9d858e86668f7c10ced5d88f8368090e720" } +libyggtracker-redb = { git = "https://github.com/YGGverse/libyggtracker-redb.git", rev="c5cc9113e2da0a5be272b0392691d6ab6e037224" } # libyggtracker-redb = { path = "../libyggtracker-redb" } diff --git a/src/main.rs b/src/main.rs index cfbf3a7..989e380 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ use librqbit::{ }; use libyggtracker_redb::{ Database, - torrent::{Image, Torrent}, + torrent::{Image, Torrent, image}, }; use peers::Peers; use preload::Preload; @@ -191,9 +191,12 @@ async fn main() -> Result<()> { Some( images .into_iter() - .map(|p| Image { - alt: p.to_str().map(|s| s.to_string()), - bytes: preload.bytes(&p).unwrap(), + .filter_map(|p| { + extension(&p).map(|extension| Image { + alt: p.to_str().map(|s| s.to_string()), + bytes: preload.bytes(&p).unwrap(), + extension, + }) }) .collect(), ) @@ -257,3 +260,24 @@ fn magnet(infohash: &str, trackers: Option<&HashSet>) -> String { } m } + +use image::Extension; +fn extension(path: &std::path::Path) -> Option { + match path.extension() { + Some(p) => { + let e = p.to_string_lossy().to_lowercase(); + if e == "png" { + Some(Extension::Png) + } else if e == "jpeg" || e == "jpg" { + Some(Extension::Jpeg) + } else if e == "webp" { + Some(Extension::Webp) + } else if e == "gif" { + Some(Extension::Gif) + } else { + return None; + } + } + None => None, + } +}