darkwing/server/services/
mod.rspub mod browser_profile_services;
pub mod cloud_file_services;
pub mod config_encryption_services;
pub mod database_encryption_services;
pub mod local_file_services;
pub mod sqlite_services;
pub mod status_services;
pub mod user_services;
use std::sync::Arc;
use browser_profile_services::{
BrowserProfileService, DynBrowserProfileService,
};
use cloud_file_services::CloudFileService;
use config_encryption_services::{
ConfigEncryptionService, DynConfigEncryption,
};
use database_encryption_services::{
DatabaseEncryptionService, DynDatabaseEncryption,
};
use local_file_services::{DynLocalFileService, LocalFileService};
use metrics_exporter_prometheus::PrometheusHandle;
use sqlite_services::{DynSqliteService, SqliteService};
use status_services::StatusService;
use tracing::info;
use user_services::UsersService;
use crate::cache::Cache;
use crate::{
config::DarkwingConfig, database::Database,
server::utils::jwt_utils::JwtTokenUtil,
};
use self::cloud_file_services::DynCloudFileService;
use self::status_services::DynStatusService;
use self::user_services::DynUsersService;
use super::utils::jwt_utils::DynJwtUtil;
#[derive(Clone)]
pub struct Services {
#[allow(unused)]
pub recorder_handle: PrometheusHandle,
pub jwt_util: DynJwtUtil,
pub config_encryption: DynConfigEncryption,
#[allow(unused)]
pub database_encryption: DynDatabaseEncryption,
pub users: DynUsersService,
pub status: DynStatusService,
pub cloud_files: DynCloudFileService,
pub local_files: DynLocalFileService,
pub browser_profile_service: DynBrowserProfileService,
pub sqlite: DynSqliteService,
}
impl Services {
pub async fn new(
db: Database,
cache: Cache,
config: Arc<DarkwingConfig>,
recorder_handle: PrometheusHandle,
) -> Self {
info!("initializing utility services...");
let jwt_util = Arc::new(JwtTokenUtil::new(config.clone())) as DynJwtUtil;
let config_encryption =
Arc::new(ConfigEncryptionService::new(config.clone()))
as DynConfigEncryption;
let sqlite = Arc::new(SqliteService::new()) as DynSqliteService;
let local_files = Arc::new(LocalFileService::new()) as DynLocalFileService;
info!("utility services initialized, building feature services...");
let repository = Arc::new(db);
let cache = Arc::new(cache);
let database_encryption = Arc::new(DatabaseEncryptionService::new(
repository.clone(),
cache.clone(),
config.clone(),
)) as DynDatabaseEncryption;
let users =
Arc::new(UsersService::new(repository.clone(), repository.clone()))
as DynUsersService;
let cloud_files = Arc::new(CloudFileService::new(config.clone()).await)
as DynCloudFileService;
let status = Arc::new(StatusService::new(
repository.clone(),
cache.clone(),
config.clone(),
)) as DynStatusService;
let browser_profile_service = Arc::new(BrowserProfileService::new(
config.clone(),
repository.clone(),
repository.clone(),
repository.clone(),
repository.clone(),
database_encryption.clone(),
)) as DynBrowserProfileService;
Self {
recorder_handle,
jwt_util,
config_encryption,
users,
status,
cloud_files,
local_files,
browser_profile_service,
sqlite,
database_encryption,
}
}
}