mirror of
https://github.com/YGGverse/btracker.git
synced 2026-03-31 17:15:31 +00:00
reorganize Torrent structs, implement parser, isolate system errors output, remove file listing from rss feed (will be moved to the torrent page)
This commit is contained in:
parent
dc7585311e
commit
9291328401
5 changed files with 156 additions and 155 deletions
27
src/feed.rs
27
src/feed.rs
|
|
@ -1,4 +1,4 @@
|
|||
use crate::format;
|
||||
use crate::{Torrent, format};
|
||||
use url::Url;
|
||||
|
||||
/// Export crawl index to the RSS file
|
||||
|
|
@ -57,7 +57,7 @@ impl Feed {
|
|||
}
|
||||
|
||||
/// Append `item` to the feed `channel`
|
||||
pub fn push(&self, buffer: &mut String, torrent: crate::storage::Torrent) {
|
||||
pub fn push(&self, buffer: &mut String, torrent: Torrent) {
|
||||
buffer.push_str(&format!(
|
||||
"<item><guid>{}</guid><title>{}</title><link>{}</link>",
|
||||
&torrent.info_hash,
|
||||
|
|
@ -71,11 +71,9 @@ impl Feed {
|
|||
escape(format::magnet(&torrent.info_hash, self.trackers.as_ref()))
|
||||
));
|
||||
|
||||
if let Some(d) = item_description(torrent.size, torrent.files) {
|
||||
buffer.push_str("<description>");
|
||||
buffer.push_str(&escape(d));
|
||||
buffer.push_str("</description>")
|
||||
}
|
||||
buffer.push_str("<description>");
|
||||
buffer.push_str(&escape(format::bytes(torrent.size)));
|
||||
buffer.push_str("</description>");
|
||||
|
||||
buffer.push_str("<pubDate>");
|
||||
buffer.push_str(&torrent.time.to_rfc2822());
|
||||
|
|
@ -99,18 +97,3 @@ fn escape(subject: String) -> String {
|
|||
.replace('"', """)
|
||||
.replace("'", "'")
|
||||
}
|
||||
|
||||
fn item_description(size: u64, list: Option<Vec<crate::storage::File>>) -> Option<String> {
|
||||
let mut b = Vec::with_capacity(list.as_ref().map(|l| l.len()).unwrap_or_default() + 1);
|
||||
b.push(format::bytes(size));
|
||||
if let Some(files) = list {
|
||||
for file in files {
|
||||
b.push(format!(
|
||||
"{} ({})",
|
||||
file.name.as_deref().unwrap_or("?"), // @TODO invalid encoding
|
||||
format::bytes(file.length)
|
||||
))
|
||||
}
|
||||
}
|
||||
Some(b.join("\n"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue