mirror of
https://github.com/YGGverse/btracker-gemini.git
synced 2026-03-31 17:15:30 +00:00
update comments, short namespaces
This commit is contained in:
parent
b31d28ebee
commit
fd2661e174
1 changed files with 17 additions and 15 deletions
32
src/main.rs
32
src/main.rs
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue