mirror of
https://github.com/YGGverse/btracker.git
synced 2026-03-31 17:15:31 +00:00
don't warn on invalid hash request, return default status
This commit is contained in:
parent
41e7d061f5
commit
cdca62bd79
1 changed files with 11 additions and 22 deletions
33
src/main.rs
33
src/main.rs
|
|
@ -13,12 +13,7 @@ use feed::Feed;
|
||||||
use meta::Meta;
|
use meta::Meta;
|
||||||
use plurify::Plurify;
|
use plurify::Plurify;
|
||||||
use public::{Order, Public, Sort};
|
use public::{Order, Public, Sort};
|
||||||
use rocket::{
|
use rocket::{State, http::Status, response::content::RawXml, serde::Serialize};
|
||||||
State,
|
|
||||||
http::Status,
|
|
||||||
response::{content::RawXml, status::Custom},
|
|
||||||
serde::Serialize,
|
|
||||||
};
|
|
||||||
use rocket_dyn_templates::{Template, context};
|
use rocket_dyn_templates::{Template, context};
|
||||||
use scraper::{Scrape, Scraper};
|
use scraper::{Scrape, Scraper};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
@ -30,7 +25,7 @@ fn index(
|
||||||
scraper: &State<Scraper>,
|
scraper: &State<Scraper>,
|
||||||
public: &State<Public>,
|
public: &State<Public>,
|
||||||
meta: &State<Meta>,
|
meta: &State<Meta>,
|
||||||
) -> Result<Template, Custom<String>> {
|
) -> Result<Template, Status> {
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(crate = "rocket::serde")]
|
#[serde(crate = "rocket::serde")]
|
||||||
struct R {
|
struct R {
|
||||||
|
|
@ -50,7 +45,7 @@ fn index(
|
||||||
)
|
)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
error!("Torrents public storage read error: `{e}`");
|
error!("Torrents public storage read error: `{e}`");
|
||||||
Custom(Status::InternalServerError, E.to_string())
|
Status::InternalServerError
|
||||||
})?;
|
})?;
|
||||||
Ok(Template::render(
|
Ok(Template::render(
|
||||||
"index",
|
"index",
|
||||||
|
|
@ -93,11 +88,8 @@ fn info(
|
||||||
public: &State<Public>,
|
public: &State<Public>,
|
||||||
scraper: &State<Scraper>,
|
scraper: &State<Scraper>,
|
||||||
meta: &State<Meta>,
|
meta: &State<Meta>,
|
||||||
) -> Result<Template, Custom<String>> {
|
) -> Result<Template, Status> {
|
||||||
match public.torrent(librqbit_core::Id20::from_str(info_hash).map_err(|e| {
|
match public.torrent(librqbit_core::Id20::from_str(info_hash).map_err(|_| Status::NotFound)?) {
|
||||||
warn!("Torrent info-hash parse error: `{e}`");
|
|
||||||
Custom(Status::BadRequest, Status::BadRequest.to_string())
|
|
||||||
})?) {
|
|
||||||
Some(t) => {
|
Some(t) => {
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(crate = "rocket::serde")]
|
#[serde(crate = "rocket::serde")]
|
||||||
|
|
@ -108,7 +100,7 @@ fn info(
|
||||||
}
|
}
|
||||||
let torrent = Torrent::from_public(&t.bytes, t.time).map_err(|e| {
|
let torrent = Torrent::from_public(&t.bytes, t.time).map_err(|e| {
|
||||||
error!("Torrent parse error: `{e}`");
|
error!("Torrent parse error: `{e}`");
|
||||||
Custom(Status::InternalServerError, E.to_string())
|
Status::InternalServerError
|
||||||
})?;
|
})?;
|
||||||
Ok(Template::render(
|
Ok(Template::render(
|
||||||
"info",
|
"info",
|
||||||
|
|
@ -136,12 +128,12 @@ fn info(
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
None => Err(Custom(Status::NotFound, E.to_string())),
|
None => Err(Status::NotFound),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/rss")]
|
#[get("/rss")]
|
||||||
fn rss(meta: &State<Meta>, public: &State<Public>) -> Result<RawXml<String>, Custom<String>> {
|
fn rss(meta: &State<Meta>, public: &State<Public>) -> 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(),
|
||||||
|
|
@ -156,13 +148,13 @@ fn rss(meta: &State<Meta>, public: &State<Public>) -> Result<RawXml<String>, Cus
|
||||||
)
|
)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
error!("Torrent public storage read error: `{e}`");
|
error!("Torrent public storage read error: `{e}`");
|
||||||
Custom(Status::InternalServerError, E.to_string())
|
Status::InternalServerError
|
||||||
})?
|
})?
|
||||||
.1
|
.1
|
||||||
{
|
{
|
||||||
f.push(Torrent::from_public(&t.bytes, t.time).map_err(|e| {
|
f.push(Torrent::from_public(&t.bytes, t.time).map_err(|e| {
|
||||||
error!("Torrent parse error: `{e}`");
|
error!("Torrent parse error: `{e}`");
|
||||||
Custom(Status::InternalServerError, E.to_string())
|
Status::InternalServerError
|
||||||
})?)
|
})?)
|
||||||
}
|
}
|
||||||
Ok(RawXml(f.commit()))
|
Ok(RawXml(f.commit()))
|
||||||
|
|
@ -225,8 +217,5 @@ fn rocket() -> _ {
|
||||||
version: env!("CARGO_PKG_VERSION").into(),
|
version: env!("CARGO_PKG_VERSION").into(),
|
||||||
})
|
})
|
||||||
.mount("/", rocket::fs::FileServer::from(config.public))
|
.mount("/", rocket::fs::FileServer::from(config.public))
|
||||||
.mount("/", routes![index, rss, info]) // keep the order!
|
.mount("/", routes![index, rss, info])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Public placeholder text for the `Status::InternalServerError`
|
|
||||||
const E: &str = "Oops!";
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue