1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-25 23:09:22 +00:00

Add new configuration

This commit is contained in:
Pierre HUBERT 2021-04-11 17:08:30 +02:00
parent f7554d44f5
commit e5f9de0507
4 changed files with 46 additions and 2 deletions

View File

@ -28,6 +28,16 @@ android-direct-download-url: https://files.communiquons.org/comunic/mobile/lates
# Print more information to the console
verbose-mode: true
# Independent push notification service information
independent-push-service:
# Server access (to create clients and push notifications)
control-url: http://localhost:4500/
control-token: BADTOKENTOCHANGE
# Public access URL pattern (for clients access) {TOKEN_URL} will be replaced by client token
public-url: http://localhost:4500/ws/{TOKEN_URL}
# Database configuration
database:
host: localhost

View File

@ -6,6 +6,13 @@ use serde::Serialize;
use crate::constants::{conservation_policy, MIN_SUPPORTED_MOBILE_VERSION, password_policy};
use crate::constants::conversations::{ALLOWED_CONVERSATION_FILES_TYPES, CONVERSATION_FILES_MAX_SIZE, CONVERSATION_WRITING_EVENT_INTERVAL, CONVERSATION_WRITING_EVENT_LIFETIME, MAX_CONV_IMAGE_MESSAGE_WIDTH, MAX_CONV_LOGO_HEIGHT, MAX_CONV_LOGO_WIDTH, MAX_CONV_MESSAGE_THUMBNAIL_HEIGHT, MAX_CONV_MESSAGE_THUMBNAIL_WIDTH, MAX_CONVERSATION_MESSAGE_LENGTH, MAX_CONVERSATION_NAME_LENGTH, MIN_CONVERSATION_MESSAGE_LENGTH};
use crate::data::config::conf;
use crate::data::api_client::APIClient;
#[derive(Serialize)]
struct NotificationsConfig {
has_firebase: bool,
has_independent: bool,
}
#[derive(Serialize)]
struct PasswordPolicy {
@ -53,13 +60,15 @@ pub struct ServerConfig {
privacy_policy_url: &'static str,
play_store_url: &'static str,
android_direct_download_url: String,
notifications: NotificationsConfig,
password_policy: PasswordPolicy,
data_conservation_policy: DataConservationPolicy,
conversations_policy: ConversationsPolicy,
}
impl ServerConfig {
pub fn new() -> Self {
pub fn new(c: &APIClient) -> Self {
ServerConfig {
min_supported_mobile_version: MIN_SUPPORTED_MOBILE_VERSION,
terms_url: &conf().terms_url,
@ -67,6 +76,11 @@ impl ServerConfig {
play_store_url: &conf().play_store_url,
android_direct_download_url: conf().android_direct_download_url.clone(),
notifications: NotificationsConfig {
has_firebase: c.firebase_token.is_some(),
has_independent: conf().independent_push_service.is_some(),
},
password_policy: PasswordPolicy {
allow_email_in_password: password_policy::ALLOW_EMAIL_IN_PASSWORD,
allow_name_in_password: password_policy::ALLOW_NAME_IN_PASSWORD,

View File

@ -14,5 +14,5 @@ pub fn main_index(request: &mut HttpRequestHandler) -> RequestResult {
/// Get server configuration
pub fn get_config(request: &mut HttpRequestHandler) -> RequestResult {
request.set_response(ServerConfig::new())
request.set_response(ServerConfig::new(request.api_client()))
}

View File

@ -24,6 +24,13 @@ pub struct RtcRelayConfig {
pub max_users_per_video_calls: u64,
}
#[derive(Debug)]
pub struct IndependentPushService {
pub control_url: String,
pub control_token: String,
pub public_url: String,
}
#[derive(Debug)]
pub struct Config {
pub port: i32,
@ -36,6 +43,7 @@ pub struct Config {
pub android_direct_download_url: String,
pub proxy: Option<String>,
pub verbose_mode: bool,
pub independent_push_service: Option<IndependentPushService>,
pub database: DatabaseConfig,
pub rtc_relay: Option<RtcRelayConfig>,
}
@ -97,6 +105,16 @@ impl Config {
let proxy = Config::yaml_str(parsed, "proxy");
let parsed_independent_push_service = &parsed["independent-push-service"];
let independent_push_service = match parsed_independent_push_service.is_badvalue() {
true => None,
false => Some(IndependentPushService {
control_url: Config::yaml_str(parsed_independent_push_service, "control-url"),
control_token: Config::yaml_str(parsed_independent_push_service, "control-token"),
public_url: Config::yaml_str(parsed_independent_push_service, "public-url"),
})
};
let conf = Config {
port: Config::yaml_i32(parsed, "server-port") as i32,
listen_address: Config::yaml_str(parsed, "server-address"),
@ -117,6 +135,8 @@ impl Config {
verbose_mode: Config::yaml_bool(parsed, "verbose-mode"),
independent_push_service,
database: database_conf,
rtc_relay: rtc_config,