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/file | |
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/file')
-rw-r--r-- | src/database/file/mod.rs | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/database/file/mod.rs b/src/database/file/mod.rs index 46660ab..f6715e1 100644 --- a/src/database/file/mod.rs +++ b/src/database/file/mod.rs @@ -210,7 +210,8 @@ impl FileStorage { async fn hydrate_author<S: Storage>( feed: &mut serde_json::Value, - user: &'_ Option<String>, + // Unused? + user: Option<&url::Url>, storage: &S, ) { let url = feed["properties"]["uid"][0] @@ -226,6 +227,7 @@ async fn hydrate_author<S: Storage>( let author_list: Vec<serde_json::Value> = stream::iter(author.iter()) .then(|i| async move { if let Some(i) = i.as_str() { + // BUG: Use `user` to sanitize? match storage.get_post(i).await { Ok(post) => match post { Some(post) => post, @@ -319,7 +321,7 @@ impl Storage for FileStorage { } #[tracing::instrument(skip(self))] - 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 key = post["properties"]["uid"][0] .as_str() .expect("Tried to save a post without UID"); @@ -358,7 +360,7 @@ impl Storage for FileStorage { .unwrap_or_default() ) }; - if url != key && url_domain == user { + if url != key && url_domain == user.authority() { let link = url_to_path(&self.root_dir, url); debug!("Creating a symlink at {:?}", link); let orig = path.clone(); @@ -386,7 +388,7 @@ impl Storage for FileStorage { // Add the h-feed to the channel list let path = { let mut path = relative_path::RelativePathBuf::new(); - path.push(user); + path.push(user.authority()); path.push("channels"); path.to_path(&self.root_dir) @@ -487,9 +489,9 @@ impl Storage for FileStorage { } #[tracing::instrument(skip(self))] - async fn get_channels(&self, user: &'_ str) -> Result<Vec<super::MicropubChannel>> { + async fn get_channels(&self, user: &url::Url) -> Result<Vec<super::MicropubChannel>> { let mut path = relative_path::RelativePathBuf::new(); - path.push(user); + path.push(user.authority()); path.push("channels"); let path = path.to_path(&self.root_dir); @@ -521,13 +523,13 @@ impl Storage for FileStorage { url: &'_ str, cursor: Option<&'_ str>, limit: usize, - user: Option<&'_ str> + user: Option<&url::Url> ) -> Result<Option<(serde_json::Value, Option<String>)>> { Ok(self.read_feed_with_limit( url, - &cursor.map(|v| v.to_owned()), + cursor, limit, - &user.map(|v| v.to_owned()) + user ).await? .map(|feed| { tracing::debug!("Feed: {:#}", serde_json::Value::Array( @@ -555,9 +557,9 @@ impl Storage for FileStorage { 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>> { if let Some(mut feed) = self.get_post(url).await? { if feed["children"].is_array() { @@ -627,10 +629,10 @@ impl Storage for FileStorage { } #[tracing::instrument(skip(self))] - 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> { debug!("User for getting settings: {}", user); let mut path = relative_path::RelativePathBuf::new(); - path.push(user); + path.push(user.authority()); path.push("settings"); let path = path.to_path(&self.root_dir); @@ -648,9 +650,9 @@ impl Storage for FileStorage { } #[tracing::instrument(skip(self))] - 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<()> { let mut path = relative_path::RelativePathBuf::new(); - path.push(user); + path.push(user.authority()); path.push("settings"); let path = path.to_path(&self.root_dir); |