]> Untitled Git - lemmy.git/blob - crates/api_common/src/context.rs
42fa74964ee61698645374815d36cf33637fe066
[lemmy.git] / crates / api_common / src / context.rs
1 use lemmy_db_schema::{source::secret::Secret, utils::DbPool};
2 use lemmy_utils::{
3   rate_limit::RateLimitCell,
4   settings::{structs::Settings, SETTINGS},
5 };
6 use reqwest_middleware::ClientWithMiddleware;
7 use std::sync::Arc;
8
9 #[derive(Clone)]
10 pub struct LemmyContext {
11   pool: DbPool,
12   client: Arc<ClientWithMiddleware>,
13   secret: Arc<Secret>,
14   rate_limit_cell: RateLimitCell,
15 }
16
17 impl LemmyContext {
18   pub fn create(
19     pool: DbPool,
20     client: ClientWithMiddleware,
21     secret: Secret,
22     rate_limit_cell: RateLimitCell,
23   ) -> LemmyContext {
24     LemmyContext {
25       pool,
26       client: Arc::new(client),
27       secret: Arc::new(secret),
28       rate_limit_cell,
29     }
30   }
31   pub fn pool(&self) -> &DbPool {
32     &self.pool
33   }
34   pub fn client(&self) -> &ClientWithMiddleware {
35     &self.client
36   }
37   pub fn settings(&self) -> &'static Settings {
38     &SETTINGS
39   }
40   pub fn secret(&self) -> &Secret {
41     &self.secret
42   }
43   pub fn settings_updated_channel(&self) -> &RateLimitCell {
44     &self.rate_limit_cell
45   }
46 }