aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml2
-rw-r--r--src/modules/router.rs43
2 files changed, 39 insertions, 6 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 34bc156..923af2e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -24,7 +24,7 @@ tokio = { version = "1.26.0", features = ["full"] } # Asynchronous Runtime
chrono = "0.4.19" # Date and Time
pickledb = "0.5.1" # Database
tantivy = "0.19.2" # Full-text Search Engine
-windmark = { version = "0.2.0", features = [
+windmark = { version = "0.2.1", features = [
"logger",
"auto-deduce-mime"
] } # Gemini Server Framework
diff --git a/src/modules/router.rs b/src/modules/router.rs
index 2445365..ade7d33 100644
--- a/src/modules/router.rs
+++ b/src/modules/router.rs
@@ -19,17 +19,17 @@
use crate::DATABASE;
pub fn module(router: &mut windmark::Router) {
- router.set_pre_route_callback(Box::new(|stream, url, _| {
+ router.set_pre_route_callback(Box::new(|context| {
info!(
"accepted connection from {} to {}",
- stream.peer_addr().unwrap().ip(),
- url.to_string(),
+ context.tcp.peer_addr().unwrap().ip(),
+ context.url.to_string(),
);
- let url_path = if url.path().is_empty() {
+ let url_path = if context.url.path().is_empty() {
"/"
} else {
- url.path()
+ context.url.path()
};
let previous_database = (*DATABASE.lock().unwrap()).get::<i32>(url_path);
@@ -49,4 +49,37 @@ pub fn module(router: &mut windmark::Router) {
.set(url_path, &(new_database.unwrap() + 1))
.unwrap();
}));
+
+ router.set_post_route_callback(Box::new(|context, content| {
+ info!(
+ "closed connection from {} to {}",
+ context.tcp.peer_addr().unwrap().ip(),
+ context.url.to_string(),
+ );
+
+ // Just a simple demo for now.
+ if let Some(uwu) =
+ windmark::utilities::queries_from_url(context.url).get("uwu")
+ {
+ if uwu.to_lowercase() == "true" || uwu == "1" {
+ let mut lines = content
+ .lines()
+ .map(ToString::to_string)
+ .collect::<Vec<String>>();
+
+ for line in &mut lines {
+ if !line.starts_with("=>") {
+ *line = line
+ .replace('l', "w")
+ .replace('r', "w")
+ .replace('L', "W")
+ .replace('R', "W")
+ .replace('!', "! >w<");
+ }
+ }
+
+ *content = lines.join("\n");
+ }
+ }
+ }));
}