From 446cb24c0b12fc3ace5b0a7f5e200518a3574135 Mon Sep 17 00:00:00 2001 From: strawberry Date: Tue, 5 Mar 2024 22:34:37 -0500 Subject: [PATCH] use Default value of 0 if BE array is not valid Signed-off-by: strawberry --- src/database/key_value/media.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/database/key_value/media.rs b/src/database/key_value/media.rs index af16d1f6..007ccdf2 100644 --- a/src/database/key_value/media.rs +++ b/src/database/key_value/media.rs @@ -142,10 +142,13 @@ impl service::media::Data for KeyValueDatabase { let mut values = values.split(|&b| b == 0xFF); - let _ts = match values.next().map(|b| u64::from_be_bytes(b.try_into().expect("valid BE array"))) { + let _ts = values.next(); + /* if we ever decide to use timestamp, this is here. + match values.next().map(|b| u64::from_be_bytes(b.try_into().expect("valid BE array"))) { Some(0) => None, x => x, - }; + };*/ + let title = match values.next().and_then(|b| String::from_utf8(b.to_vec()).ok()) { Some(s) if s.is_empty() => None, x => x, @@ -158,15 +161,15 @@ impl service::media::Data for KeyValueDatabase { Some(s) if s.is_empty() => None, x => x, }; - let image_size = match values.next().map(|b| usize::from_be_bytes(b.try_into().expect("valid BE array"))) { + let image_size = match values.next().map(|b| usize::from_be_bytes(b.try_into().unwrap_or_default())) { Some(0) => None, x => x, }; - let image_width = match values.next().map(|b| u32::from_be_bytes(b.try_into().expect("valid BE array"))) { + let image_width = match values.next().map(|b| u32::from_be_bytes(b.try_into().unwrap_or_default())) { Some(0) => None, x => x, }; - let image_height = match values.next().map(|b| u32::from_be_bytes(b.try_into().expect("valid BE array"))) { + let image_height = match values.next().map(|b| u32::from_be_bytes(b.try_into().unwrap_or_default())) { Some(0) => None, x => x, };