mirror of
https://github.com/YGGverse/btracker-gemini.git
synced 2026-03-31 17:15:30 +00:00
require valid Url, implement magnet links
This commit is contained in:
parent
e8b409c4d6
commit
b2f3809656
4 changed files with 30 additions and 4 deletions
|
|
@ -3,6 +3,7 @@ use std::{
|
|||
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
|
||||
path::PathBuf,
|
||||
};
|
||||
use url::Url;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
|
|
@ -13,7 +14,7 @@ pub struct Config {
|
|||
|
||||
/// Tracker(s) to join / scrape requests
|
||||
#[arg(short, long)]
|
||||
pub tracker: Option<Vec<String>>,
|
||||
pub tracker: Option<Vec<Url>>,
|
||||
|
||||
/// Bind server `host:port` to listen incoming connections on it
|
||||
#[arg(short, long, default_value_t = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 1965)))]
|
||||
|
|
|
|||
25
src/main.rs
25
src/main.rs
|
|
@ -18,6 +18,7 @@ use std::{
|
|||
thread,
|
||||
};
|
||||
use titanite::*;
|
||||
use url::Url;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
if std::env::var("RUST_LOG").is_ok() {
|
||||
|
|
@ -225,7 +226,7 @@ fn index(config: &Config, public: &Public, page: Option<usize>) -> Result<String
|
|||
if let Some(ref trackers) = config.tracker {
|
||||
b.push("```".into());
|
||||
for tracker in trackers {
|
||||
b.push(tracker.clone());
|
||||
b.push(tracker.to_string());
|
||||
}
|
||||
b.push("```\n".into());
|
||||
}
|
||||
|
|
@ -243,12 +244,17 @@ fn index(config: &Config, public: &Public, page: Option<usize>) -> Result<String
|
|||
.unwrap_or_default()
|
||||
));
|
||||
b.push(format!(
|
||||
"=> {} {} • {} • {}\n",
|
||||
"=> {} {} • {} • {}",
|
||||
i.info_hash.as_string(),
|
||||
torrent.time.format("%Y/%m/%d"), // @TODO optional
|
||||
size(&i),
|
||||
files(&i),
|
||||
));
|
||||
|
||||
b.push(format!(
|
||||
"=> {} Magnet\n",
|
||||
magnet(&i, config.tracker.as_ref())
|
||||
))
|
||||
}
|
||||
|
||||
b.push("## Navigation\n".into());
|
||||
|
|
@ -294,3 +300,18 @@ fn size(meta: &TorrentMetaV1Owned) -> String {
|
|||
+ meta.info.length.unwrap_or_default(),
|
||||
)
|
||||
}
|
||||
|
||||
fn magnet(meta: &TorrentMetaV1Owned, trackers: Option<&Vec<Url>>) -> String {
|
||||
let mut b = format!("magnet:?xt=urn:btih:{}", meta.info_hash.as_string());
|
||||
if let Some(ref n) = meta.info.name {
|
||||
b.push_str("&dn=");
|
||||
b.push_str(&urlencoding::encode(&n.to_string()))
|
||||
}
|
||||
if let Some(t) = trackers {
|
||||
for tracker in t {
|
||||
b.push_str("&tr=");
|
||||
b.push_str(&urlencoding::encode(tracker.as_str()))
|
||||
}
|
||||
}
|
||||
b
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue