jmserver/src/config.rs

39 lines
997 B
Rust
Raw Normal View History

2021-12-18 20:04:34 +01:00
use reqwest::Url;
2021-12-17 23:50:03 +01:00
use serde::Deserialize;
2022-07-19 21:11:13 +02:00
use sqlx::MySqlPool;
2022-01-16 22:43:45 +01:00
use std::{net::SocketAddr, sync::Arc};
use crate::{error::JMError, JMService, JMServiceInner};
2021-12-17 23:50:03 +01:00
#[derive(Deserialize)]
pub struct Config {
pub addr: SocketAddr,
pub database: String,
pub cdn: String,
2021-12-18 20:04:34 +01:00
pub ipfs_api: Url,
2022-01-17 21:58:33 +01:00
pub matrix_url: Url,
pub matrix_token: String,
pub matrix_domain: String,
2021-12-17 23:50:03 +01:00
}
impl Config {
2022-07-19 21:11:13 +02:00
pub fn service(&self, db_pool: MySqlPool) -> Result<JMService, JMError> {
2022-01-16 22:43:45 +01:00
let client = reqwest::ClientBuilder::new().user_agent("curl").build()?;
Ok(Arc::new(JMServiceInner {
client,
2022-07-19 21:11:13 +02:00
db_pool,
2022-01-16 22:43:45 +01:00
ipfs_url: self.ipfs_api.clone(),
cdn_url: self.cdn.clone(),
2022-01-17 21:58:33 +01:00
matrix_url: self.matrix_url.clone(),
matrix_token: self.matrix_token.clone(),
matrix_domain: self.matrix_domain.clone(),
2022-01-16 22:43:45 +01:00
}))
2021-12-17 23:50:03 +01:00
}
}
2022-01-16 22:43:45 +01:00
impl JMServiceInner {
pub fn cdn_url(&self) -> String {
self.cdn_url.clone()
2021-12-17 23:50:03 +01:00
}
2021-12-29 18:33:31 +01:00
}