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