aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-03-29 02:02:00 -0700
committerFuwn <[email protected]>2023-03-29 02:02:00 -0700
commitb8b8987dd35f7c006072af1aa3d8f7f44f351319 (patch)
treebaa29342400d0355a03ff2cc5f35c93468b1f539 /src
parentfix(stocks): 0.10.10 <- 0.11.10 to fix tokio thread panic (diff)
downloadlocus-b8b8987dd35f7c006072af1aa3d8f7f44f351319.tar.xz
locus-b8b8987dd35f7c006072af1aa3d8f7f44f351319.zip
feat(router): add uwufy demo
Diffstat (limited to 'src')
-rw-r--r--src/modules/router.rs43
1 files changed, 38 insertions, 5 deletions
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");
+ }
+ }
+ }));
}