From 7e8e688e2e58f9c944b941e768ab7b034a348a1f Mon Sep 17 00:00:00 2001 From: Vika Date: Thu, 1 Aug 2024 19:48:37 +0300 Subject: treewide: create a common method for state initialization Now the database objects can be uniformly created from a URI. They can also optionally do sanity checks and one-time initialization. --- src/database/file/mod.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/database/file') diff --git a/src/database/file/mod.rs b/src/database/file/mod.rs index f6715e1..ba8201f 100644 --- a/src/database/file/mod.rs +++ b/src/database/file/mod.rs @@ -197,15 +197,7 @@ fn modify_post(post: &serde_json::Value, update: MicropubUpdate) -> Result Result { - // TODO check if the dir is writable - Ok(Self { root_dir }) - } + pub(super) root_dir: PathBuf, } async fn hydrate_author( @@ -255,6 +247,10 @@ async fn hydrate_author( #[async_trait] impl Storage for FileStorage { + async fn new(url: &'_ url::Url) -> Result { + // TODO: sanity check + Ok(Self { root_dir: PathBuf::from(url.path()) }) + } #[tracing::instrument(skip(self))] async fn categories(&self, url: &str) -> Result> { // This requires an expensive scan through the entire -- cgit 1.4.1