this repo has no description
at main 1.2 kB view raw
1use axum::extract::FromRef; 2use std::{ 3 collections::{HashMap, HashSet}, 4 ops::Deref, 5 sync::Arc, 6}; 7 8use crate::{cache::Cache, storage::StoragePool}; 9 10#[derive(Clone, Debug)] 11pub(crate) struct FeedControl { 12 pub(crate) deny: Option<String>, 13 pub(crate) allowed: HashSet<String>, 14} 15 16pub struct InnerWebContext { 17 pub(crate) pool: StoragePool, 18 pub(crate) external_base: String, 19 pub(crate) feeds: HashMap<String, FeedControl>, 20 pub(crate) cache: Cache, 21} 22 23#[derive(Clone, FromRef)] 24pub struct WebContext(pub(crate) Arc<InnerWebContext>); 25 26impl Deref for WebContext { 27 type Target = InnerWebContext; 28 29 fn deref(&self) -> &Self::Target { 30 &self.0 31 } 32} 33 34impl WebContext { 35 pub fn new( 36 pool: StoragePool, 37 external_base: &str, 38 feeds: HashMap<String, (Option<String>, HashSet<String>)>, 39 cache: Cache, 40 ) -> Self { 41 let feeds = feeds 42 .into_iter() 43 .map(|(uri, (deny, allowed))| (uri, FeedControl { deny, allowed })) 44 .collect(); 45 Self(Arc::new(InnerWebContext { 46 pool, 47 external_base: external_base.to_string(), 48 feeds, 49 cache, 50 })) 51 } 52}