From 82d2a89aa203a4430b4f2e8ee8cb79bd8b135a10 Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 9 Jul 2025 03:28:04 +0300 Subject: [PATCH] implement item description format helper --- src/main.rs | 23 +++++++++++------------ src/rss.rs | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8aa2da6..804c25a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,6 @@ mod trackers; use anyhow::Result; use config::Config; use debug::Debug; -use format::Format; use index::Index; use librqbit::{ AddTorrent, AddTorrentOptions, AddTorrentResponse, ByteBufOwned, ConnectionOptions, @@ -250,7 +249,7 @@ async fn main() -> Result<()> { rss.push( k, v.name().unwrap_or(k), - v.size().map(|l| l.bytes()), + rss::item_description(v.size(), v.list()), Some(&v.time.to_rfc2822()), )? } @@ -317,23 +316,23 @@ fn list(info: &TorrentMetaV1Info, limit: usize) -> Option, list: Option<&Vec<(String, u64)>>) -> Option { + if size.is_none() && list.is_none() { + return None; + } + let mut b = Vec::with_capacity(list.map(|l| l.len()).unwrap_or_default() + 1); + if let Some(s) = size { + use crate::format::Format; + b.push(s.bytes()) + } + if let Some(l) = list { + for (path, size) in l { + b.push(format!("* {path}: {size}")) + } + } + Some(b.join("
\n")) +} + fn escape(subject: &str) -> String { subject .replace('&', "&")