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

Create server config route

This commit is contained in:
Pierre HUBERT 2021-02-15 17:03:25 +01:00
parent fa230bdef8
commit 376bd0477e
5 changed files with 66 additions and 0 deletions

View File

@ -7,6 +7,7 @@
//! ## Author
//! Pierre Hubert
pub mod server_config;
pub mod http_error;
pub mod login_success;
pub mod current_user_id;

View File

@ -0,0 +1,35 @@
//! # Server configuration
//!
//! @author Pierre Hubert
use serde::Serialize;
use crate::constants::conservation_policy;
#[derive(Serialize)]
struct DataConservationPolicy {
min_inactive_account_lifetime: u64,
min_notification_lifetime: u64,
min_comments_lifetime: u64,
min_posts_lifetime: u64,
min_conversation_messages_lifetime: u64,
min_likes_lifetime: u64,
}
#[derive(Serialize)]
pub struct ServerConfig {
data_conservation_policy: DataConservationPolicy,
}
impl ServerConfig {
pub fn new() -> Self {
ServerConfig {
data_conservation_policy: DataConservationPolicy {
min_inactive_account_lifetime: conservation_policy::MIN_INACTIVE_ACCOUNT_LIFETIME.as_secs(),
min_notification_lifetime: conservation_policy::MIN_NOTIFICATIONS_LIFETIME.as_secs(),
min_comments_lifetime: conservation_policy::MIN_COMMENTS_LIFETIME.as_secs(),
min_posts_lifetime: conservation_policy::MIN_POSTS_LIFETIME.as_secs(),
min_conversation_messages_lifetime: conservation_policy::MIN_CONVERSATION_MESSAGES_LIFETIME.as_secs(),
min_likes_lifetime: conservation_policy::MIN_LIKES_LIFETIME.as_secs(),
}
}
}
}

View File

@ -59,6 +59,29 @@ pub mod database_tables_names {
pub const NOTIFICATIONS_TABLE: &str = "comunic_notifications";
}
/// Minimal conversation policy
pub mod conservation_policy {
use std::time::Duration;
/// Minimum lifetime for inactive account (3 months)
pub const MIN_INACTIVE_ACCOUNT_LIFETIME: Duration = Duration::from_secs(60 * 60 * 24 * 30 * 3);
/// Minimum lifetime for notifications (7 days)
pub const MIN_NOTIFICATIONS_LIFETIME: Duration = Duration::from_secs(60 * 60 * 24 * 7);
/// Minimum lifetime for comments (1 month)
pub const MIN_COMMENTS_LIFETIME: Duration = Duration::from_secs(60 * 60 * 24 * 30);
/// Minimum lifetime for posts (1 month)
pub const MIN_POSTS_LIFETIME: Duration = Duration::from_secs(60 * 60 * 24 * 30);
/// Minimum conversation messages lifetime (15 days)
pub const MIN_CONVERSATION_MESSAGES_LIFETIME: Duration = Duration::from_secs(60 * 60 * 24 * 15);
/// Minimum likes lifetime (1 month)
pub const MIN_LIKES_LIFETIME: Duration = Duration::from_secs(60 * 60 * 24 * 30);
}
/// WebSocket access token lifetime, in seconds
pub const WS_ACCESS_TOKEN_LIFETIME: u64 = 10;

View File

@ -1,3 +1,4 @@
use crate::api_data::server_config::ServerConfig;
use crate::data::base_request_handler::BaseRequestHandler;
use crate::data::http_request_handler::HttpRequestHandler;
use crate::routes::RequestResult;
@ -9,4 +10,9 @@ use crate::routes::RequestResult;
/// Root server index
pub fn main_index(request: &mut HttpRequestHandler) -> RequestResult {
request.success("Comunic API server V3. (c) Pierre Hubert 2020")
}
/// Get server configuration
pub fn get_config(request: &mut HttpRequestHandler) -> RequestResult {
request.set_response(ServerConfig::new())
}

View File

@ -127,6 +127,7 @@ pub fn get_routes() -> Vec<Route> {
vec![
// Server meta routes
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)),