mirror of
https://github.com/YGGverse/btracker.git
synced 2026-03-31 09:05:30 +00:00
update btracker-fs api
This commit is contained in:
parent
c3762b64ca
commit
ad5b2d6897
1 changed files with 15 additions and 15 deletions
30
src/main.rs
30
src/main.rs
|
|
@ -7,7 +7,7 @@ mod meta;
|
||||||
mod scrape;
|
mod scrape;
|
||||||
mod torrent;
|
mod torrent;
|
||||||
|
|
||||||
use btracker_fs::public::{Order, Public, Sort};
|
use btracker_fs::public::{Order, Sort, Storage};
|
||||||
use btracker_scrape::Scrape;
|
use btracker_scrape::Scrape;
|
||||||
use config::Config;
|
use config::Config;
|
||||||
use feed::Feed;
|
use feed::Feed;
|
||||||
|
|
@ -22,7 +22,7 @@ fn index(
|
||||||
search: Option<&str>,
|
search: Option<&str>,
|
||||||
page: Option<usize>,
|
page: Option<usize>,
|
||||||
scrape: &State<Scrape>,
|
scrape: &State<Scrape>,
|
||||||
public: &State<Public>,
|
storage: &State<Storage>,
|
||||||
meta: &State<Meta>,
|
meta: &State<Meta>,
|
||||||
) -> Result<Template, Status> {
|
) -> Result<Template, Status> {
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
|
@ -36,12 +36,12 @@ fn index(
|
||||||
size: String,
|
size: String,
|
||||||
torrent: Torrent,
|
torrent: Torrent,
|
||||||
}
|
}
|
||||||
let (total, torrents) = public
|
let (total, torrents) = storage
|
||||||
.torrents(
|
.torrents(
|
||||||
search,
|
search,
|
||||||
Some((Sort::Modified, Order::Desc)),
|
Some((Sort::Modified, Order::Desc)),
|
||||||
page.map(|p| if p > 0 { p - 1 } else { p } * public.default_limit),
|
page.map(|p| if p > 0 { p - 1 } else { p } * storage.default_limit),
|
||||||
Some(public.default_limit),
|
Some(storage.default_limit),
|
||||||
)
|
)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
error!("Torrents public storage read error: `{e}`");
|
error!("Torrents public storage read error: `{e}`");
|
||||||
|
|
@ -72,7 +72,7 @@ fn index(
|
||||||
},
|
},
|
||||||
meta: meta.inner(),
|
meta: meta.inner(),
|
||||||
back: page.map(|p| uri!(index(search, if p > 2 { Some(p - 1) } else { None }))),
|
back: page.map(|p| uri!(index(search, if p > 2 { Some(p - 1) } else { None }))),
|
||||||
next: if page.unwrap_or(1) * public.default_limit >= total { None }
|
next: if page.unwrap_or(1) * storage.default_limit >= total { None }
|
||||||
else { Some(uri!(index(search, Some(page.map_or(2, |p| p + 1))))) },
|
else { Some(uri!(index(search, Some(page.map_or(2, |p| p + 1))))) },
|
||||||
rows: torrents
|
rows: torrents
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
@ -93,7 +93,7 @@ fn index(
|
||||||
})
|
})
|
||||||
.collect::<Vec<R>>(),
|
.collect::<Vec<R>>(),
|
||||||
page: page.unwrap_or(1),
|
page: page.unwrap_or(1),
|
||||||
pages: (total as f64 / public.default_limit as f64).ceil(),
|
pages: (total as f64 / storage.default_limit as f64).ceil(),
|
||||||
total,
|
total,
|
||||||
search
|
search
|
||||||
},
|
},
|
||||||
|
|
@ -103,12 +103,12 @@ fn index(
|
||||||
#[get("/<info_hash>")]
|
#[get("/<info_hash>")]
|
||||||
fn info(
|
fn info(
|
||||||
info_hash: &str,
|
info_hash: &str,
|
||||||
public: &State<Public>,
|
storage: &State<Storage>,
|
||||||
scrape: &State<Scrape>,
|
scrape: &State<Scrape>,
|
||||||
meta: &State<Meta>,
|
meta: &State<Meta>,
|
||||||
) -> Result<Template, Status> {
|
) -> Result<Template, Status> {
|
||||||
let i = librqbit_core::Id20::from_str(info_hash).map_err(|_| Status::NotFound)?;
|
let i = librqbit_core::Id20::from_str(info_hash).map_err(|_| Status::NotFound)?;
|
||||||
match public.torrent(i) {
|
match storage.torrent(i) {
|
||||||
Some(t) => {
|
Some(t) => {
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(crate = "rocket::serde")]
|
#[serde(crate = "rocket::serde")]
|
||||||
|
|
@ -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, &p),
|
href: storage.href(&torrent.info_hash, &p),
|
||||||
path: p,
|
path: p,
|
||||||
size: f.size(),
|
size: f.size(),
|
||||||
}
|
}
|
||||||
|
|
@ -161,22 +161,22 @@ fn info(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/rss")]
|
#[get("/rss")]
|
||||||
fn rss(meta: &State<Meta>, public: &State<Public>) -> Result<RawXml<String>, Status> {
|
fn rss(meta: &State<Meta>, storage: &State<Storage>) -> Result<RawXml<String>, Status> {
|
||||||
let mut f = Feed::new(
|
let mut f = Feed::new(
|
||||||
&meta.title,
|
&meta.title,
|
||||||
meta.description.as_deref(),
|
meta.description.as_deref(),
|
||||||
meta.canonical.clone(),
|
meta.canonical.clone(),
|
||||||
1024, // @TODO
|
1024, // @TODO
|
||||||
);
|
);
|
||||||
for t in public
|
for t in storage
|
||||||
.torrents(
|
.torrents(
|
||||||
None,
|
None,
|
||||||
Some((Sort::Modified, Order::Desc)),
|
Some((Sort::Modified, Order::Desc)),
|
||||||
None,
|
None,
|
||||||
Some(public.default_limit),
|
Some(storage.default_limit),
|
||||||
)
|
)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
error!("Torrent public storage read error: `{e}`");
|
error!("Torrent storage read error: `{e}`");
|
||||||
Status::InternalServerError
|
Status::InternalServerError
|
||||||
})?
|
})?
|
||||||
.1
|
.1
|
||||||
|
|
@ -236,7 +236,7 @@ fn rocket() -> _ {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.manage(scrape)
|
.manage(scrape)
|
||||||
.manage(Public::init(&config.public, config.list_limit, config.capacity).unwrap())
|
.manage(Storage::init(&config.public, config.list_limit, config.capacity).unwrap())
|
||||||
.manage(Meta {
|
.manage(Meta {
|
||||||
canonical: config.canonical_url,
|
canonical: config.canonical_url,
|
||||||
description: config.description,
|
description: config.description,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue