From 2e9c292bb989ffff2c99aa2a6062962c913b3586 Mon Sep 17 00:00:00 2001 From: Vika Date: Tue, 9 Jul 2024 22:43:21 +0300 Subject: database: use Url to represent user authorities This makes the interface more consistent and resistant to misuse. --- src/database/memory.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'src/database/memory.rs') 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>>, - pub channels: Arc>>>, + pub channels: Arc>>>, } #[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> { + async fn get_channels(&self, user: &url::Url) -> Result> { 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, + after: Option<&str>, limit: usize, - user: &'_ Option, + user: Option<&url::Url>, ) -> Result> { todo!() } @@ -210,7 +205,7 @@ impl Storage for MemoryStorage { url: &'_ str, cursor: Option<&'_ str>, limit: usize, - user: Option<&'_ str> + user: Option<&url::Url> ) -> Result)>> { todo!() } @@ -221,12 +216,12 @@ impl Storage for MemoryStorage { } #[allow(unused_variables)] - async fn get_setting, 'a>(&'_ self, user: &'_ str) -> Result { + async fn get_setting, 'a>(&'_ self, user: &url::Url) -> Result { todo!() } #[allow(unused_variables)] - async fn set_setting + 'a, 'a>(&self, user: &'a str, value: S::Data) -> Result<()> { + async fn set_setting + 'a, 'a>(&self, user: &'a url::Url, value: S::Data) -> Result<()> { todo!() } -- cgit 1.4.1