mirror of
https://github.com/YGGverse/btracker.git
synced 2026-03-31 17:15:31 +00:00
parse canonical url once per feed init
This commit is contained in:
parent
1d4022f618
commit
04f4387534
2 changed files with 33 additions and 12 deletions
22
src/feed.rs
22
src/feed.rs
|
|
@ -1,10 +1,13 @@
|
||||||
|
mod link;
|
||||||
|
|
||||||
use crate::Torrent;
|
use crate::Torrent;
|
||||||
|
use link::Link;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
/// Export crawl index to the RSS file
|
/// Export crawl index to the RSS file
|
||||||
pub struct Feed {
|
pub struct Feed {
|
||||||
buffer: String,
|
buffer: String,
|
||||||
canonical: Option<Url>,
|
canonical: Link,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Feed {
|
impl Feed {
|
||||||
|
|
@ -43,7 +46,11 @@ impl Feed {
|
||||||
buffer.push_str(c.as_str());
|
buffer.push_str(c.as_str());
|
||||||
buffer.push_str("</link>")
|
buffer.push_str("</link>")
|
||||||
}
|
}
|
||||||
Self { buffer, canonical }
|
|
||||||
|
Self {
|
||||||
|
buffer,
|
||||||
|
canonical: Link::from_url(canonical),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Append `item` to the feed `channel`
|
/// Append `item` to the feed `channel`
|
||||||
|
|
@ -58,16 +65,7 @@ impl Feed {
|
||||||
.map(|b| b.to_string())
|
.map(|b| b.to_string())
|
||||||
.unwrap_or("?".into()) // @TODO
|
.unwrap_or("?".into()) // @TODO
|
||||||
),
|
),
|
||||||
self.canonical
|
self.canonical.link(&torrent.info_hash)
|
||||||
.clone()
|
|
||||||
.map(|mut c| escape({
|
|
||||||
c.set_path(&torrent.info_hash);
|
|
||||||
c.set_fragment(None);
|
|
||||||
c.set_query(None);
|
|
||||||
c.as_str()
|
|
||||||
}))
|
|
||||||
.unwrap_or(escape(&torrent.info_hash)) // should be non-optional absolute URL
|
|
||||||
// by the RSS specification @TODO
|
|
||||||
));
|
));
|
||||||
|
|
||||||
self.buffer.push_str("<description>");
|
self.buffer.push_str("<description>");
|
||||||
|
|
|
||||||
23
src/feed/link.rs
Normal file
23
src/feed/link.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
|
/// Valid link prefix donor for the RSS channel item
|
||||||
|
pub struct Link(String);
|
||||||
|
|
||||||
|
impl Link {
|
||||||
|
pub fn from_url(canonical: Option<Url>) -> Self {
|
||||||
|
Self(
|
||||||
|
canonical
|
||||||
|
.map(|mut c| {
|
||||||
|
c.set_path("/");
|
||||||
|
c.set_fragment(None);
|
||||||
|
c.set_query(None);
|
||||||
|
super::escape(c.as_str()) // filter once
|
||||||
|
})
|
||||||
|
.unwrap_or_default(), // should be non-optional absolute URL
|
||||||
|
// by the RSS specification @TODO
|
||||||
|
)
|
||||||
|
}
|
||||||
|
pub fn link(&self, info_hash: &str) -> String {
|
||||||
|
format!("{}{info_hash}", self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue