about summary refs log tree commit diff
path: root/src/database
diff options
context:
space:
mode:
Diffstat (limited to 'src/database')
-rw-r--r--src/database/file/mod.rs4
-rw-r--r--src/database/memory.rs29
2 files changed, 20 insertions, 13 deletions
diff --git a/src/database/file/mod.rs b/src/database/file/mod.rs
index a33e7c4..841f9c0 100644
--- a/src/database/file/mod.rs
+++ b/src/database/file/mod.rs
@@ -1,4 +1,4 @@
-#![warn(clippy::unwrap_used)]
+//#![warn(clippy::unwrap_used)]
 use crate::database::{filter_post, ErrorKind, Result, Storage, StorageError};
 use std::fs::{File, OpenOptions};
 use std::io::{ErrorKind as IOErrorKind, Seek, SeekFrom, Read, Write};
@@ -332,7 +332,7 @@ impl Storage for FileStorage {
         #[allow(clippy::unwrap_used)] // JoinHandle captures panics, this closure shouldn't panic
         tokio::time::timeout(Duration::from_secs(IO_TIMEOUT), spawn_blocking(move || {
             #[warn(clippy::unwrap_used)]
-            let parent = post_path.parent().unwrap().to_owned();
+            let parent = post_path.parent().expect("Parent for this directory should always exist").to_owned();
             if !parent.is_dir() {
                 std::fs::create_dir_all(post_path.parent().unwrap())?;
             }
diff --git a/src/database/memory.rs b/src/database/memory.rs
index c83bc8c..df142d3 100644
--- a/src/database/memory.rs
+++ b/src/database/memory.rs
@@ -1,3 +1,4 @@
+#![allow(clippy::todo)]
 use async_trait::async_trait;
 use std::collections::HashMap;
 use std::sync::Arc;
@@ -6,7 +7,6 @@ use futures_util::FutureExt;
 use serde_json::json;
 
 use crate::database::{Storage, Result, StorageError, ErrorKind, MicropubChannel};
-use crate::indieauth::User;
 
 #[derive(Clone, Debug)]
 pub struct MemoryStorage {
@@ -41,7 +41,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: &'_ str) -> Result<()> {
         let mapping = &mut self.mapping.write().await;
         let key: &str;
         match post["properties"]["uid"][0].as_str() {
@@ -51,7 +51,7 @@ impl Storage for MemoryStorage {
         mapping.insert(key.to_string(), post.clone());
         if post["properties"]["url"].is_array() {
             for url in post["properties"]["url"].as_array().unwrap().iter().map(|i| i.as_str().unwrap().to_string()) {
-                if &url != key {
+                if url != key {
                     mapping.insert(url, json!({"see_other": key}));
                 }
             }
@@ -59,7 +59,7 @@ impl Storage for MemoryStorage {
         if post["type"].as_array().unwrap().iter().any(|i| i == "h-feed") {
             // This is a feed. Add it to the channels array if it's not already there.
             println!("{:#}", post);
-            self.channels.write().await.entry(post["properties"]["author"][0].as_str().unwrap().to_string()).or_insert(vec![]).push(key.to_string())
+            self.channels.write().await.entry(post["properties"]["author"][0].as_str().unwrap().to_string()).or_insert_with(Vec::new).push(key.to_string())
         }
         Ok(())
     }
@@ -155,19 +155,18 @@ impl Storage for MemoryStorage {
                 .map(|channel| self.get_post(channel)
                     .map(|result| result.unwrap())
                     .map(|post: Option<serde_json::Value>| {
-                        if let Some(post) = post {
-                            Some(MicropubChannel {
-                                uid: post["properties"]["uid"][0].as_str().unwrap().to_string(),
-                                name: post["properties"]["name"][0].as_str().unwrap().to_string()
-                            })
-                        } else { None }
+                        post.map(|post| MicropubChannel {
+                            uid: post["properties"]["uid"][0].as_str().unwrap().to_string(),
+                            name: post["properties"]["name"][0].as_str().unwrap().to_string()
+                        })
                     })
-                ).collect::<Vec<_>>()).await.into_iter().filter_map(|chan| chan).collect::<Vec<_>>()),
+                ).collect::<Vec<_>>()).await.into_iter().flatten().collect::<Vec<_>>()),
             None => Ok(vec![])
         }
         
     }
 
+    #[allow(unused_variables)]
     async fn read_feed_with_limit(&self, url: &'_ str, after: &'_ Option<String>, limit: usize, user: &'_ Option<String>) -> Result<Option<serde_json::Value>> {
         todo!()
     }
@@ -177,15 +176,23 @@ impl Storage for MemoryStorage {
         Ok(())
     }
 
+    #[allow(unused_variables)]
     async fn get_setting(&self, setting: &'_ str, user: &'_ str) -> Result<String> {
         todo!()
     }
 
+    #[allow(unused_variables)]
     async fn set_setting(&self, setting: &'_ str, user: &'_ str, value: &'_ str) -> Result<()> {
         todo!()
     }
 }
 
+impl Default for MemoryStorage {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl MemoryStorage {
     pub fn new() -> Self {
         Self {