1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 13:29:21 +00:00

Revert "wip"

This reverts commit 5abb162233.
This commit is contained in:
Pierre HUBERT 2022-03-11 20:47:17 +01:00
parent 5abb162233
commit d660c0d4ba
6 changed files with 16 additions and 47 deletions

12
Cargo.lock generated
View File

@ -370,17 +370,6 @@ version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" 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]] [[package]]
name = "attohttpc" name = "attohttpc"
version = "0.15.0" version = "0.15.0"
@ -711,7 +700,6 @@ dependencies = [
"actix-multipart", "actix-multipart",
"actix-web", "actix-web",
"actix-web-actors", "actix-web-actors",
"async-trait",
"bcrypt", "bcrypt",
"bytes", "bytes",
"chrono", "chrono",

View File

@ -42,4 +42,3 @@ webpage = "1.2.0"
gouth = "0.2.0" gouth = "0.2.0"
webauthn-rs = "0.3.2" webauthn-rs = "0.3.2"
url = "2.2.2" url = "2.2.2"
async-trait = "0.1.52"

View File

@ -14,7 +14,7 @@ server-port: 3000
proxy: "127.0.0.1" proxy: "127.0.0.1"
# User data storage # 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/ 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 # 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 serve-storage-files: true
# URL where Comunic Terms of use are available # URL where Comunic Terms of use are available
terms-url: http://devweb.internal/comunic/current/about.php?cgu terms-url: http://devweb.local/comunic/current/about.php?cgu
privacy-policy-url: http://devweb.internal/comunic/current/about.php?cgu&privacy privacy-policy-url: http://devweb.local/comunic/current/about.php?cgu&privacy
# Email where the Comunic staff can be contacted # Email where the Comunic staff can be contacted
contact-email: contact@communiquons.org contact-email: contact@communiquons.org

View File

@ -8,7 +8,7 @@ use crate::routes::RequestResult;
/// @author Pierre Hubert /// @author Pierre Hubert
/// Root server index /// 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") request.success("Comunic API server V3. (c) Pierre Hubert 2020")
} }

View File

@ -1,11 +1,7 @@
use std::error::Error; use std::error::Error;
use std::future::Future;
use std::pin::Pin;
use async_trait::async_trait;
use crate::constants::admin::AdminRole; 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::controllers::admin::*;
use crate::data::http_request_handler::HttpRequestHandler; use crate::data::http_request_handler::HttpRequestHandler;
use crate::routes::Method::{GET, POST}; use crate::routes::Method::{GET, POST};
@ -64,19 +60,6 @@ impl LimitPolicy {
} }
} }
pub trait RouteTrait{
fn call(&self, req: &mut HttpRequestHandler) -> Pin<Box<dyn Future<Output=RequestResult>>>;
}
impl<Func, Fut> RouteTrait for Func where Func: 'static + Fn(&mut HttpRequestHandler) -> Fut + Clone ,
Fut: 'static +Future<Output=RequestResult> {
#[inline]
#[allow(non_snake_case)]
fn call(&self, req: &mut HttpRequestHandler) -> Pin<Box<dyn Future<Output=RequestResult>>> {
Box::pin((self)(req))
}
}
/// Define types /// Define types
pub type RequestResult = Result<(), Box<dyn Error>>; pub type RequestResult = Result<(), Box<dyn Error>>;
pub type RequestProcess = Box<dyn Fn(&mut HttpRequestHandler) -> RequestResult>; pub type RequestProcess = Box<dyn Fn(&mut HttpRequestHandler) -> RequestResult>;
@ -95,7 +78,7 @@ pub struct Route {
pub need_login: bool, pub need_login: bool,
/// The function called to process a request /// The function called to process a request
pub func: Pin<Box<dyn RouteTrait + 'static>>, pub func: RequestProcess,
/// Request rate policy /// Request rate policy
pub limit_policy: LimitPolicy, pub limit_policy: LimitPolicy,
@ -105,19 +88,19 @@ pub struct Route {
} }
impl Route { impl Route {
pub fn get_without_login<E>(uri: &'static str, func: E) -> Route where E: 'static + RouteTrait { pub fn get_without_login(uri: &'static str, func: RequestProcess) -> Route {
Route { Route {
scope: RouteScope::USER, scope: RouteScope::USER,
method: GET, method: GET,
need_login: false, need_login: false,
uri, uri,
func: Box::pin(func), func,
limit_policy: LimitPolicy::NONE, limit_policy: LimitPolicy::NONE,
admin_role: 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 { Route {
scope: RouteScope::USER, scope: RouteScope::USER,
method: POST, method: POST,
@ -199,15 +182,15 @@ impl Route {
limit_policy: LimitPolicy::NONE, limit_policy: LimitPolicy::NONE,
admin_role: Some(role), admin_role: Some(role),
} }
}*/ }
} }
/// Get the list of routes available /// Get the list of routes available
pub fn get_routes() -> Vec<Route> { pub fn get_routes() -> Vec<Route> {
vec![ vec![
// Server meta routes // Server meta routes
Route::get_without_login("/", server_controller::main_index), Route::get_without_login("/", Box::new(server_controller::main_index)),
/*Route::post_without_login("/server/config", Box::new(server_controller::get_config)), Route::post_without_login("/server/config", Box::new(server_controller::get_config)),
// Main user WebSocket // Main user WebSocket
Route::post("/ws/token", Box::new(user_ws_controller::get_token)), Route::post("/ws/token", Box::new(user_ws_controller::get_token)),
@ -416,6 +399,6 @@ pub fn get_routes() -> Vec<Route> {
Route::admin_post("/admin/users/search", Box::new(admin_users_controller::search)), 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/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/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)),
] ]
} }

View File

@ -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)?; requests_limit_helper::trigger_after(res.is_ok(), req, route)?;