From d660c0d4ba6b93ed75140479da13d298545d171a Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 11 Mar 2022 20:47:17 +0100 Subject: [PATCH] Revert "wip" This reverts commit 5abb162233367f1cbbe7eb048839844137f80c03. --- Cargo.lock | 12 ---------- Cargo.toml | 3 +-- config.yaml | 8 +++---- src/controllers/server_controller.rs | 2 +- src/routes.rs | 35 +++++++--------------------- src/server.rs | 3 +-- 6 files changed, 16 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ca3c0c2..0d148ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -370,17 +370,6 @@ version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" -[[package]] -name = "async-trait" -version = "0.1.52" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "061a7acccaa286c011ddc30970520b98fa40e00c9d644633fb26b5fc63a265e3" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "attohttpc" version = "0.15.0" @@ -711,7 +700,6 @@ dependencies = [ "actix-multipart", "actix-web", "actix-web-actors", - "async-trait", "bcrypt", "bytes", "chrono", diff --git a/Cargo.toml b/Cargo.toml index e4db542..3b020d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,5 +41,4 @@ zip = "0.5.10" webpage = "1.2.0" gouth = "0.2.0" webauthn-rs = "0.3.2" -url = "2.2.2" -async-trait = "0.1.52" \ No newline at end of file +url = "2.2.2" \ No newline at end of file diff --git a/config.yaml b/config.yaml index 165ff41..e64350b 100644 --- a/config.yaml +++ b/config.yaml @@ -14,7 +14,7 @@ server-port: 3000 proxy: "127.0.0.1" # User data storage -storage-url: http://devweb.internal/comunic/current/user_data/ +storage-url: http://devweb.local/comunic/current/user_data/ storage-path: /home/pierre/Documents/projets_web/comunic/current/user_data/ # Specify whether user data files should be made available under the user_data directory @@ -23,8 +23,8 @@ storage-path: /home/pierre/Documents/projets_web/comunic/current/user_data/ serve-storage-files: true # URL where Comunic Terms of use are available -terms-url: http://devweb.internal/comunic/current/about.php?cgu -privacy-policy-url: http://devweb.internal/comunic/current/about.php?cgu&privacy +terms-url: http://devweb.local/comunic/current/about.php?cgu +privacy-policy-url: http://devweb.local/comunic/current/about.php?cgu&privacy # Email where the Comunic staff can be contacted contact-email: contact@communiquons.org @@ -101,4 +101,4 @@ banner: # This option allows to enable some extra features for these groups # # In most cases you should not have to specify this information -forez_groups: 32 +forez_groups: 32 \ No newline at end of file diff --git a/src/controllers/server_controller.rs b/src/controllers/server_controller.rs index 9f7a275..31445e6 100644 --- a/src/controllers/server_controller.rs +++ b/src/controllers/server_controller.rs @@ -8,7 +8,7 @@ use crate::routes::RequestResult; /// @author Pierre Hubert /// Root server index -pub async fn main_index(request: &mut HttpRequestHandler) -> RequestResult { +pub fn main_index(request: &mut HttpRequestHandler) -> RequestResult { request.success("Comunic API server V3. (c) Pierre Hubert 2020") } diff --git a/src/routes.rs b/src/routes.rs index 572fae6..29c8449 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -1,11 +1,7 @@ use std::error::Error; -use std::future::Future; -use std::pin::Pin; - -use async_trait::async_trait; use crate::constants::admin::AdminRole; -use crate::controllers::*; +use crate::controllers::{account_controller, comments_controller, conversations_controller, forez_controller, friends_controller, groups_controller, likes_controller, notifications_controller, posts_controller, push_notifications_controller, search_controller, server_controller, settings_controller, surveys_controller, user_controller, user_ws_controller, virtual_directory_controller, web_app_controller}; use crate::controllers::admin::*; use crate::data::http_request_handler::HttpRequestHandler; use crate::routes::Method::{GET, POST}; @@ -64,19 +60,6 @@ impl LimitPolicy { } } -pub trait RouteTrait{ - fn call(&self, req: &mut HttpRequestHandler) -> Pin>>; -} - -impl RouteTrait for Func where Func: 'static + Fn(&mut HttpRequestHandler) -> Fut + Clone , - Fut: 'static +Future { - #[inline] - #[allow(non_snake_case)] - fn call(&self, req: &mut HttpRequestHandler) -> Pin>> { - Box::pin((self)(req)) - } -} - /// Define types pub type RequestResult = Result<(), Box>; pub type RequestProcess = Box RequestResult>; @@ -95,7 +78,7 @@ pub struct Route { pub need_login: bool, /// The function called to process a request - pub func: Pin>, + pub func: RequestProcess, /// Request rate policy pub limit_policy: LimitPolicy, @@ -105,19 +88,19 @@ pub struct Route { } impl Route { - pub fn get_without_login(uri: &'static str, func: E) -> Route where E: 'static + RouteTrait { + pub fn get_without_login(uri: &'static str, func: RequestProcess) -> Route { Route { scope: RouteScope::USER, method: GET, need_login: false, uri, - func: Box::pin(func), + func, limit_policy: LimitPolicy::NONE, admin_role: None, } } - /*pub fn post_without_login(uri: &'static str, func: RequestProcess) -> Route { + pub fn post_without_login(uri: &'static str, func: RequestProcess) -> Route { Route { scope: RouteScope::USER, method: POST, @@ -199,15 +182,15 @@ impl Route { limit_policy: LimitPolicy::NONE, admin_role: Some(role), } - }*/ + } } /// Get the list of routes available pub fn get_routes() -> Vec { vec![ // Server meta routes - Route::get_without_login("/", server_controller::main_index), - /*Route::post_without_login("/server/config", Box::new(server_controller::get_config)), + Route::get_without_login("/", Box::new(server_controller::main_index)), + Route::post_without_login("/server/config", Box::new(server_controller::get_config)), // Main user WebSocket Route::post("/ws/token", Box::new(user_ws_controller::get_token)), @@ -416,6 +399,6 @@ pub fn get_routes() -> Vec { Route::admin_post("/admin/users/search", Box::new(admin_users_controller::search)), Route::admin_post("/admin/users/info", Box::new(admin_users_controller::get_single)), Route::admin_post("/admin/users/change_email_address", Box::new(admin_users_controller::change_email_address)), - Route::admin_post("/admin/users/create_password_reset_link", Box::new(admin_users_controller::create_password_reset_link)),*/ + Route::admin_post("/admin/users/create_password_reset_link", Box::new(admin_users_controller::create_password_reset_link)), ] } \ No newline at end of file diff --git a/src/server.rs b/src/server.rs index c2f5fb7..4ac8bd2 100644 --- a/src/server.rs +++ b/src/server.rs @@ -236,8 +236,7 @@ async fn process_simple_route(route: &Route, req: &mut HttpRequestHandler) -> Re } - let res = route.func.call(req).await; - + let res: RequestResult = (route.func)(req); requests_limit_helper::trigger_after(res.is_ok(), req, route)?;