diff options
| author | Fuwn <[email protected]> | 2023-04-06 00:02:11 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-04-06 00:02:11 -0700 |
| commit | 039acf58ac5a4b16fdb896634affb637b1bdeaad (patch) | |
| tree | 46caa813e140c5baae75a48268f6a997a5e9951c /src/modules | |
| parent | fix(docker): copy syntax warning (diff) | |
| download | locus-039acf58ac5a4b16fdb896634affb637b1bdeaad.tar.xz locus-039acf58ac5a4b16fdb896634affb637b1bdeaad.zip | |
deps(windmark): bump 0.2.5 -> 0.3.1
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/api/sydney.rs | 4 | ||||
| -rw-r--r-- | src/modules/blog/module.rs | 82 | ||||
| -rw-r--r-- | src/modules/contact.rs | 4 | ||||
| -rw-r--r-- | src/modules/cryptocurrency.rs | 8 | ||||
| -rw-r--r-- | src/modules/interests.rs | 4 | ||||
| -rw-r--r-- | src/modules/remarks.rs | 4 | ||||
| -rw-r--r-- | src/modules/router/module.rs | 12 | ||||
| -rw-r--r-- | src/modules/router/ticker.rs | 2 | ||||
| -rw-r--r-- | src/modules/router/translate/module.rs | 7 | ||||
| -rw-r--r-- | src/modules/search.rs | 4 | ||||
| -rw-r--r-- | src/modules/sitemap.rs | 4 | ||||
| -rw-r--r-- | src/modules/skills.rs | 4 | ||||
| -rw-r--r-- | src/modules/stocks.rs | 12 | ||||
| -rw-r--r-- | src/modules/uptime.rs | 4 |
14 files changed, 75 insertions, 80 deletions
diff --git a/src/modules/api/sydney.rs b/src/modules/api/sydney.rs index 1adc07d..20f8faa 100644 --- a/src/modules/api/sydney.rs +++ b/src/modules/api/sydney.rs @@ -26,7 +26,7 @@ pub fn module(router: &mut windmark::Router) { router, "/api/sydney/version", "Sydney's version", - Box::new(move |context| { + move |context| { let mut content = "0.0.0".to_string(); if let Ok(response) = reqwest::blocking::Client::new() @@ -55,6 +55,6 @@ pub fn module(router: &mut windmark::Router) { windmark::Response::success(content) .with_mime("text/plain") .clone() - }), + }, ); } diff --git a/src/modules/blog/module.rs b/src/modules/blog/module.rs index dbdf7ed..41fcf86 100644 --- a/src/modules/blog/module.rs +++ b/src/modules/blog/module.rs @@ -105,29 +105,25 @@ pub fn module(router: &mut windmark::Router) { let blog_clone = blogs.clone(); - track_mount( - router, - "/blog", - "Fuwn's blogs", - Box::new(move |context| { - success!( - &format!( - "# Blogs ({})\n\n{}", - blog_clone.len(), - blog_clone - .iter() - .map(|(title, entries)| (title.clone(), entries.clone())) - .collect::<Vec<(_, _)>>() - .into_iter() - .map(|(title, entries)| { - let config: Option<Blog> = - entries.get("blog.json").and_then(|content| { - if let Ok(config) = Blog::from_string(content) { - Some(config) - } else { - None - } - }); + track_mount(router, "/blog", "Fuwn's blogs", move |context| { + success!( + &format!( + "# Blogs ({})\n\n{}", + blog_clone.len(), + blog_clone + .iter() + .map(|(title, entries)| (title.clone(), entries.clone())) + .collect::<Vec<(_, _)>>() + .into_iter() + .map(|(title, entries)| { + let config: Option<Blog> = + entries.get("blog.json").and_then(|content| { + if let Ok(config) = Blog::from_string(content) { + Some(config) + } else { + None + } + }); let name = config .clone() .unwrap_or_default() @@ -140,23 +136,19 @@ pub fn module(router: &mut windmark::Router) { .clone() .unwrap_or_else(|| "One of Fuwn's blogs".to_string()); - format!( - "=> {} {} ― {}", - format_args!( - "/blog/{}", - name.replace(' ', "_").to_lowercase(), - ), - name, + format!( + "=> {} {} ― {}", + format_args!("/blog/{}", name.replace(' ', "_").to_lowercase(),), + name, description - ) - }) - .collect::<Vec<_>>() - .join("\n") - ), - context - ) - }), - ); + ) + }) + .collect::<Vec<_>>() + .join("\n") + ), + context + ) + }); for (blog, mut entries) in blogs { let fixed_blog_name = blog.replace(' ', "_").to_lowercase(); @@ -200,7 +192,7 @@ pub fn module(router: &mut windmark::Router) { router, &format!("/blog/{}", fixed_blog_name), &format!("{} ― {}", name, description), - Box::new(move |context| { + move |context| { let fixed_blog_name = fixed_blog_name_clone.clone(); success!( @@ -252,7 +244,7 @@ pub fn module(router: &mut windmark::Router) { ), context ) - }), + }, ); for (title, contents) in entries { @@ -311,9 +303,9 @@ pub fn module(router: &mut windmark::Router) { header.1 } ), - Box::new(move |context| { + move |context| { success!(format!("{}\n{}", header.0, contents,), context) - }), + }, ); } @@ -321,11 +313,11 @@ pub fn module(router: &mut windmark::Router) { router, &format!("/blog/{}.xml", fixed_blog_name), &format!("Really Simple Syndication for the {} blog", name), - Box::new(move |_| { + move |_| { windmark::Response::success(xml.to_string()) .with_mime("text/rss+xml") .clone() - }), + }, ); } } diff --git a/src/modules/contact.rs b/src/modules/contact.rs index c9ce993..f82922e 100644 --- a/src/modules/contact.rs +++ b/src/modules/contact.rs @@ -50,8 +50,8 @@ pub fn module(router: &mut windmark::Router) { router, "/contact", "A Few Skills of Fuwn", - Box::new(move |context| { + move |context| { crate::success!(format!("# Contact\n\n{}", contacts.join("\n")), context) - }), + }, ); } diff --git a/src/modules/cryptocurrency.rs b/src/modules/cryptocurrency.rs index bba0e58..752c251 100644 --- a/src/modules/cryptocurrency.rs +++ b/src/modules/cryptocurrency.rs @@ -41,7 +41,7 @@ pub fn module(router: &mut windmark::Router) { "/cryptocurrency/referrals", "Want to start investing in cryptocurrency? Support me by using one of my \ referral links!", - Box::new(|context| { + |context| { success!( format!( "# Referrals\n\n=> /cryptocurrency Home\n=> /stocks Stock Market \ @@ -57,14 +57,14 @@ pub fn module(router: &mut windmark::Router) { ), context ) - }), + }, ); track_mount( router, "/cryptocurrency", "Relevant information regarding cryptocurrency investing", - Box::new(|context| { + |context| { success!( format!( "# Cryptocurrency\n\n=> /stocks Stock Market Dashboard\n=> \ @@ -72,6 +72,6 @@ pub fn module(router: &mut windmark::Router) { ), context ) - }), + }, ); } diff --git a/src/modules/interests.rs b/src/modules/interests.rs index 4db805f..6762e55 100644 --- a/src/modules/interests.rs +++ b/src/modules/interests.rs @@ -50,7 +50,7 @@ pub fn module(router: &mut windmark::Router) { router, "/interests", "A Few Interests of Fuwn", - Box::new(move |context| { + move |context| { crate::success!( format!( "# Interests\n\nA collection of things that I think are pretty neat \ @@ -59,6 +59,6 @@ pub fn module(router: &mut windmark::Router) { ), context ) - }), + }, ); } diff --git a/src/modules/remarks.rs b/src/modules/remarks.rs index 8cd9d6c..e683d2a 100644 --- a/src/modules/remarks.rs +++ b/src/modules/remarks.rs @@ -36,7 +36,7 @@ pub fn module(router: &mut windmark::Router) { "/remarks", "Fuwn's thoughts which are too short to be their own blog; but just long \ enough to be a remark.", - Box::new(|context| { + |context| { crate::success!( format!( "# Remarks\n\nFuwn's thoughts which are too short to be their own \ @@ -59,6 +59,6 @@ pub fn module(router: &mut windmark::Router) { ), context ) - }), + }, ); } diff --git a/src/modules/router/module.rs b/src/modules/router/module.rs index dc9dae8..34d20db 100644 --- a/src/modules/router/module.rs +++ b/src/modules/router/module.rs @@ -16,8 +16,10 @@ // Copyright (C) 2022-2022 Fuwn <[email protected]> // SPDX-License-Identifier: GPL-3.0-only +use windmark::context::HookContext; + pub fn module(router: &mut windmark::Router) { - router.set_pre_route_callback(Box::new(|context| { + router.set_pre_route_callback(move |context: HookContext<'_>| { info!( "accepted connection from {} to {}", context.tcp.peer_addr().unwrap().ip(), @@ -25,9 +27,9 @@ pub fn module(router: &mut windmark::Router) { ); super::ticker::module(&context); - })); - router.set_post_route_callback(Box::new({ - |context, response| { + }); + router.set_post_route_callback({ + |context: HookContext<'_>, response: &mut windmark::Response| { info!( "closed connection from {} to {}", context.tcp.peer_addr().unwrap().ip(), @@ -50,5 +52,5 @@ pub fn module(router: &mut windmark::Router) { } } } - })); + }); } diff --git a/src/modules/router/ticker.rs b/src/modules/router/ticker.rs index 4297086..d193c9b 100644 --- a/src/modules/router/ticker.rs +++ b/src/modules/router/ticker.rs @@ -18,7 +18,7 @@ use crate::DATABASE; -pub fn module(context: &windmark::returnable::CallbackContext<'_>) { +pub fn module(context: &windmark::context::HookContext<'_>) { let url_path = if context.url.path().is_empty() { "/" } else { diff --git a/src/modules/router/translate/module.rs b/src/modules/router/translate/module.rs index 0c997d3..4c105e1 100644 --- a/src/modules/router/translate/module.rs +++ b/src/modules/router/translate/module.rs @@ -20,7 +20,7 @@ use super::deepl::translate; use crate::modules::router::translate::deepl::language_code_to_language_name; pub fn module<S>( - cc: &windmark::returnable::CallbackContext<'_>, + context: &windmark::context::HookContext<'_>, response: &mut windmark::Response, language: S, ) -> Result<(), serde_json::Error> @@ -90,12 +90,13 @@ where &translated.detected_source_language().to_lowercase() ), language_code_to_language_name(&language.as_ref().to_lowercase()), - cc.url + context + .url .to_string() .replace(&format!("translate={}", language.as_ref()), ""), fully_translated.join("\n") ); - response.language = Some(language.into()); + response.languages = Some(vec![language.into()]); response.character_set = Some({ let mut encoding_detector = chardetng::EncodingDetector::new(); diff --git a/src/modules/search.rs b/src/modules/search.rs index bf0b7bb..28593e0 100644 --- a/src/modules/search.rs +++ b/src/modules/search.rs @@ -56,7 +56,7 @@ pub(super) fn module(router: &mut windmark::Router) { router, "/search", "A search engine for this Gemini capsule", - Box::new(|context| { + |context| { let mut response = String::from( "# Search\n\n=> /search?action=go Search!\n=> /random I'm Feeling \ Lucky", @@ -162,7 +162,7 @@ pub(super) fn module(router: &mut windmark::Router) { } crate::success!(response, context) - }), + }, ); } diff --git a/src/modules/sitemap.rs b/src/modules/sitemap.rs index aa1a8cf..10ae569 100644 --- a/src/modules/sitemap.rs +++ b/src/modules/sitemap.rs @@ -21,7 +21,7 @@ pub fn module(router: &mut windmark::Router) { router, "/sitemap", "A map of all publicly available routes on this Gemini capsule", - Box::new(|context| { + |context| { crate::success!( format!( "# Sitemap\n\nA map of all publicly available routes on this Gemini \ @@ -34,6 +34,6 @@ pub fn module(router: &mut windmark::Router) { ), context ) - }), + }, ); } diff --git a/src/modules/skills.rs b/src/modules/skills.rs index ec2337d..182bf15 100644 --- a/src/modules/skills.rs +++ b/src/modules/skills.rs @@ -63,8 +63,8 @@ pub fn module(router: &mut windmark::Router) { router, "/skills", "A Few Skills of Fuwn", - Box::new(move |context| { + move |context| { crate::success!(format!("# Skills\n\n{}", skills.join("\n")), context) - }), + }, ); } diff --git a/src/modules/stocks.rs b/src/modules/stocks.rs index 832a1ad..108e792 100644 --- a/src/modules/stocks.rs +++ b/src/modules/stocks.rs @@ -111,7 +111,7 @@ pub fn module(router: &mut windmark::Router) { "/stocks/referrals", "Want to start investing in the stock market? Support me by using one of \ my referral links!", - Box::new(|context| { + |context| { success!( format!( "# Referrals\n\n=> /stocks Dashboard\n=> /cryptocurrency \ @@ -128,14 +128,14 @@ pub fn module(router: &mut windmark::Router) { ), context ) - }), + }, ); track_mount( router, "/stocks", "Explore and search the stock market using Gemini!", - Box::new(|context| { + |context| { success!( format!( "# The Stock Market\n\n=> /stocks/search Symbol Search\n=> /stocks/referrals Referrals\n=> /cryptocurrency Cryptocurrency Dashboard\n=> /stocks/telegram Telegram Groups\n\n## Popular \ @@ -145,14 +145,14 @@ pub fn module(router: &mut windmark::Router) { ), context ) - }), + }, ); track_mount( router, "/stocks/search", "Search for a specific symbol", - Box::new(|context| { + |context| { let mut symbol = context.url.query().unwrap_or("Symbol Search"); if symbol.is_empty() { @@ -194,6 +194,6 @@ pub fn module(router: &mut windmark::Router) { ), context ) - }), + }, ); } diff --git a/src/modules/uptime.rs b/src/modules/uptime.rs index 9a9e1b5..9b3d2b5 100644 --- a/src/modules/uptime.rs +++ b/src/modules/uptime.rs @@ -28,7 +28,7 @@ pub fn module(router: &mut windmark::Router) { router, "/uptime", "The uptime of Locus (A.K.A., The Locus Epoch). (\\?[s|ms|mu|ns]?)?", - Box::new(move |context| { + move |context| { let response = windmark::utilities::queries_from_url(context.url) .get("unit") .map_or_else( @@ -49,6 +49,6 @@ pub fn module(router: &mut windmark::Router) { crate::route::cache(&context, &response); windmark::Response::success(response) - }), + }, ); } |