diff options
author | Vika <vika@fireburn.ru> | 2024-07-09 22:43:21 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2024-07-09 22:44:01 +0300 |
commit | 2e9c292bb989ffff2c99aa2a6062962c913b3586 (patch) | |
tree | 9c148d9e8fcbd7756ab8d27ae110075beea8e615 /src/database/memory.rs | |
parent | 644e19aa08b2629d4b69281e14d702f0b9673687 (diff) | |
download | kittybox-2e9c292bb989ffff2c99aa2a6062962c913b3586.tar.zst |
database: use Url to represent user authorities
This makes the interface more consistent and resistant to misuse.
Diffstat (limited to 'src/database/memory.rs')
-rw-r--r-- | src/database/memory.rs | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/database/memory.rs b/src/database/memory.rs index 564f451..56caeec 100644 --- a/src/database/memory.rs +++ b/src/database/memory.rs @@ -11,7 +11,7 @@ use crate::database::{ErrorKind, MicropubChannel, Result, settings, Storage, Sto #[derive(Clone, Debug)] pub struct MemoryStorage { pub mapping: Arc<RwLock<HashMap<String, serde_json::Value>>>, - pub channels: Arc<RwLock<HashMap<String, Vec<String>>>>, + pub channels: Arc<RwLock<HashMap<url::Url, Vec<String>>>>, } #[async_trait] @@ -45,7 +45,7 @@ impl Storage for MemoryStorage { } } - async fn put_post(&self, post: &'_ serde_json::Value, _user: &'_ str) -> Result<()> { + async fn put_post(&self, post: &'_ serde_json::Value, user: &url::Url) -> Result<()> { let mapping = &mut self.mapping.write().await; let key: &str = match post["properties"]["uid"][0].as_str() { Some(uid) => uid, @@ -80,12 +80,7 @@ impl Storage for MemoryStorage { self.channels .write() .await - .entry( - post["properties"]["author"][0] - .as_str() - .unwrap() - .to_string(), - ) + .entry(user.clone()) .or_insert_with(Vec::new) .push(key.to_string()) } @@ -165,7 +160,7 @@ impl Storage for MemoryStorage { Ok(()) } - async fn get_channels(&self, user: &'_ str) -> Result<Vec<MicropubChannel>> { + async fn get_channels(&self, user: &url::Url) -> Result<Vec<MicropubChannel>> { match self.channels.read().await.get(user) { Some(channels) => Ok(futures_util::future::join_all( channels @@ -197,9 +192,9 @@ impl Storage for MemoryStorage { async fn read_feed_with_limit( &self, url: &'_ str, - after: &'_ Option<String>, + after: Option<&str>, limit: usize, - user: &'_ Option<String>, + user: Option<&url::Url>, ) -> Result<Option<serde_json::Value>> { todo!() } @@ -210,7 +205,7 @@ impl Storage for MemoryStorage { url: &'_ str, cursor: Option<&'_ str>, limit: usize, - user: Option<&'_ str> + user: Option<&url::Url> ) -> Result<Option<(serde_json::Value, Option<String>)>> { todo!() } @@ -221,12 +216,12 @@ impl Storage for MemoryStorage { } #[allow(unused_variables)] - async fn get_setting<S: settings::Setting<'a>, 'a>(&'_ self, user: &'_ str) -> Result<S> { + async fn get_setting<S: settings::Setting<'a>, 'a>(&'_ self, user: &url::Url) -> Result<S> { todo!() } #[allow(unused_variables)] - async fn set_setting<S: settings::Setting<'a> + 'a, 'a>(&self, user: &'a str, value: S::Data) -> Result<()> { + async fn set_setting<S: settings::Setting<'a> + 'a, 'a>(&self, user: &'a url::Url, value: S::Data) -> Result<()> { todo!() } |