update comments, short namespaces

This commit is contained in:
yggverse 2025-09-08 22:02:35 +03:00
parent b31d28ebee
commit fd2661e174

View file

@ -18,7 +18,6 @@ use std::{
sync::Arc,
thread,
};
use titanite::*;
fn main() -> Result<()> {
if std::env::var("RUST_LOG").is_ok() {
@ -75,6 +74,7 @@ fn handle(
peer: SocketAddr,
connection: Result<TlsStream<TcpStream>, HandshakeError<TcpStream>>,
) {
use titanite::*;
debug!("Incoming connection from: `{peer}`");
match connection {
Ok(mut stream) => {
@ -153,41 +153,42 @@ fn response(
stream: &mut TlsStream<TcpStream>,
) {
use route::Route;
use titanite::response::*;
debug!("Incoming request from `{peer}` to `{}`", request.url.path());
send(
&match Route::from_url(&request.url) {
Route::List { page } => match list(config, public, request.url.query(), page) {
Ok(data) => response::success::Default {
Ok(data) => success::Default {
data: data.as_bytes(),
meta: response::success::default::Meta {
meta: success::default::Meta {
mime: "text/gemini".to_string(),
},
}
.into_bytes(),
Err(e) => {
error!("Internal server error on handle peer `{peer}` request: `{e}`");
response::failure::temporary::General {
failure::temporary::General {
message: Some("Internal server error".to_string()),
}
.into_bytes()
}
},
Route::Search => response::Input::Default(response::input::Default {
Route::Search => Input::Default(input::Default {
message: Some("Keyword, file, hash...".into()),
})
.into_bytes(),
Route::Info(id) => match public.torrent(id) {
Some(torrent) => match info(config, torrent) {
Ok(data) => response::success::Default {
Ok(data) => success::Default {
data: data.as_bytes(),
meta: response::success::default::Meta {
meta: success::default::Meta {
mime: "text/gemini".to_string(),
},
}
.into_bytes(),
Err(e) => {
error!("Internal server error on handle peer `{peer}` request: `{e}`");
response::failure::temporary::General {
failure::temporary::General {
message: Some("Internal server error".to_string()),
}
.into_bytes()
@ -195,12 +196,12 @@ fn response(
},
None => {
warn!(
"Requested resource `{}` not found by peer `{peer}`",
"Requested torrent `{}` not found by peer `{peer}`",
request.url.as_str()
);
response::Failure::Permanent(response::failure::Permanent::NotFound(
response::failure::permanent::NotFound { message: None },
))
Failure::Permanent(failure::Permanent::NotFound(failure::permanent::NotFound {
message: None,
}))
.into_bytes()
}
},
@ -209,9 +210,9 @@ fn response(
"Requested resource `{}` not found by peer `{peer}`",
request.url.as_str()
);
response::Failure::Permanent(response::failure::Permanent::NotFound(
response::failure::permanent::NotFound { message: None },
))
Failure::Permanent(failure::Permanent::NotFound(failure::permanent::NotFound {
message: None,
}))
.into_bytes()
}
},
@ -249,6 +250,7 @@ fn list(
) -> Result<String> {
use plurify::Plurify;
/// format search keyword as the pagination query
fn query(keyword: Option<&str>) -> String {
keyword.map(|k| format!("?{}", k)).unwrap_or_default()
}