mirror of
https://github.com/YGGverse/btracker.git
synced 2026-03-31 09:05:30 +00:00
fix id conversion, hold parsed hex inf-hash as the String
This commit is contained in:
parent
b69973bdd5
commit
e7fe57a861
3 changed files with 10 additions and 8 deletions
|
|
@ -55,9 +55,9 @@ impl Feed {
|
||||||
|
|
||||||
/// Append `item` to the feed `channel`
|
/// Append `item` to the feed `channel`
|
||||||
pub fn push(&mut self, torrent: Torrent) {
|
pub fn push(&mut self, torrent: Torrent) {
|
||||||
let info_hash = torrent.info_hash.as_string();
|
|
||||||
self.buffer.push_str(&format!(
|
self.buffer.push_str(&format!(
|
||||||
"<item><guid>{info_hash}</guid><title>{}</title><link>{}</link>",
|
"<item><guid>{}</guid><title>{}</title><link>{}</link>",
|
||||||
|
&torrent.info_hash,
|
||||||
escape(
|
escape(
|
||||||
&torrent
|
&torrent
|
||||||
.name
|
.name
|
||||||
|
|
@ -65,7 +65,7 @@ impl Feed {
|
||||||
.map(|b| b.to_string())
|
.map(|b| b.to_string())
|
||||||
.unwrap_or("?".into()) // @TODO
|
.unwrap_or("?".into()) // @TODO
|
||||||
),
|
),
|
||||||
self.canonical.link(&info_hash)
|
self.canonical.link(&torrent.info_hash)
|
||||||
));
|
));
|
||||||
|
|
||||||
self.buffer.push_str("<description>");
|
self.buffer.push_str("<description>");
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ fn index(
|
||||||
files: torrent.files(),
|
files: torrent.files(),
|
||||||
indexed: torrent.time.format(&meta.format_time).to_string(),
|
indexed: torrent.time.format(&meta.format_time).to_string(),
|
||||||
magnet: torrent.magnet(meta.trackers.as_ref()),
|
magnet: torrent.magnet(meta.trackers.as_ref()),
|
||||||
scrape: scrape::get(scrape, torrent.info_hash.0),
|
scrape: scrape::get(scrape, torrent.id.0),
|
||||||
size: torrent.size as usize, // required by `filesizeformat` impl
|
size: torrent.size as usize, // required by `filesizeformat` impl
|
||||||
torrent
|
torrent
|
||||||
}),
|
}),
|
||||||
|
|
@ -141,7 +141,7 @@ fn info(
|
||||||
.map(|f| {
|
.map(|f| {
|
||||||
let p = f.path();
|
let p = f.path();
|
||||||
F {
|
F {
|
||||||
href: public.href(&torrent.info_hash.as_string(), &p),
|
href: public.href(&torrent.info_hash, &p),
|
||||||
path: p,
|
path: p,
|
||||||
size: f.length as usize, // required by `filesizeformat` impl
|
size: f.length as usize, // required by `filesizeformat` impl
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,8 @@ pub struct Torrent {
|
||||||
pub created_by: Option<String>,
|
pub created_by: Option<String>,
|
||||||
pub creation_date: Option<DateTime<Utc>>,
|
pub creation_date: Option<DateTime<Utc>>,
|
||||||
pub files: Option<Vec<File>>,
|
pub files: Option<Vec<File>>,
|
||||||
pub info_hash: Id20,
|
pub id: Id20,
|
||||||
|
pub info_hash: String,
|
||||||
pub is_private: bool,
|
pub is_private: bool,
|
||||||
pub length: Option<u64>,
|
pub length: Option<u64>,
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
|
|
@ -32,7 +33,8 @@ impl Torrent {
|
||||||
let i: TorrentMetaV1Owned =
|
let i: TorrentMetaV1Owned =
|
||||||
torrent_metainfo::torrent_from_bytes(bytes).map_err(|e| e.to_string())?;
|
torrent_metainfo::torrent_from_bytes(bytes).map_err(|e| e.to_string())?;
|
||||||
Ok(Torrent {
|
Ok(Torrent {
|
||||||
info_hash: i.info_hash,
|
id: i.info_hash,
|
||||||
|
info_hash: i.info_hash.as_string(),
|
||||||
announce: i.announce.map(|a| a.to_string()),
|
announce: i.announce.map(|a| a.to_string()),
|
||||||
comment: i.comment.map(|c| c.to_string()),
|
comment: i.comment.map(|c| c.to_string()),
|
||||||
created_by: i.created_by.map(|c| c.to_string()),
|
created_by: i.created_by.map(|c| c.to_string()),
|
||||||
|
|
@ -79,7 +81,7 @@ impl Torrent {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn magnet(&self, trackers: Option<&Vec<url::Url>>) -> String {
|
pub fn magnet(&self, trackers: Option<&Vec<url::Url>>) -> String {
|
||||||
let mut b = format!("magnet:?xt=urn:btih:{}", self.info_hash.as_string());
|
let mut b = format!("magnet:?xt=urn:btih:{}", self.info_hash);
|
||||||
if let Some(ref n) = self.name {
|
if let Some(ref n) = self.name {
|
||||||
b.push_str("&dn=");
|
b.push_str("&dn=");
|
||||||
b.push_str(&urlencoding::encode(n))
|
b.push_str(&urlencoding::encode(n))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue