about summary refs log tree commit diff stats
path: root/src/storage/video_database/extractor_hash.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/storage/video_database/extractor_hash.rs')
-rw-r--r--src/storage/video_database/extractor_hash.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/storage/video_database/extractor_hash.rs b/src/storage/video_database/extractor_hash.rs
index 62a9eda..c956919 100644
--- a/src/storage/video_database/extractor_hash.rs
+++ b/src/storage/video_database/extractor_hash.rs
@@ -10,7 +10,7 @@
 
 use std::{collections::HashMap, fmt::Display, str::FromStr};
 
-use anyhow::{bail, Result};
+use anyhow::{bail, Context, Result};
 use blake3::Hash;
 use log::debug;
 use tokio::sync::OnceCell;
@@ -24,6 +24,12 @@ pub struct ExtractorHash {
     hash: Hash,
 }
 
+impl Display for ExtractorHash {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        self.hash.fmt(f)
+    }
+}
+
 #[derive(Debug, Clone)]
 pub struct ShortHash(String);
 
@@ -78,7 +84,10 @@ impl ExtractorHash {
         let needed_chars = if let Some(needed_chars) = EXTRACTOR_HASH_LENGTH.get() {
             *needed_chars
         } else {
-            let needed_chars = self.get_needed_char_len(app).await?;
+            let needed_chars = self
+                .get_needed_char_len(app)
+                .await
+                .context("Failed to calculate needed char length")?;
             EXTRACTOR_HASH_LENGTH
                 .set(needed_chars)
                 .expect("This should work at this stage");
@@ -96,7 +105,9 @@ impl ExtractorHash {
     }
 
     async fn short_hash_to_full_hash(app: &App, s: &ShortHash) -> Result<Hash> {
-        let all_hashes = get_all_hashes(app).await?;
+        let all_hashes = get_all_hashes(app)
+            .await
+            .context("Failed to fetch all extractor -hashesh from database")?;
 
         let needed_chars = s.0.len();
 
@@ -111,7 +122,9 @@ impl ExtractorHash {
 
     async fn get_needed_char_len(&self, app: &App) -> Result<usize> {
         debug!("Calculating the needed hash char length");
-        let all_hashes = get_all_hashes(app).await?;
+        let all_hashes = get_all_hashes(app)
+            .await
+            .context("Failed to fetch all extractor -hashesh from database")?;
 
         let all_char_vec_hashes = all_hashes
             .into_iter()