stream properties refactored

This commit is contained in:
euzu
2025-12-26 14:09:44 +01:00
parent 76bde0fcc4
commit d5207e886f
102 changed files with 7817 additions and 2546 deletions
+3 -17
View File
@@ -1,21 +1,11 @@
use base64::Engine;
use base64::engine::general_purpose;
use std::fmt::Write;
use url::Url;
use crate::model::{PlaylistItemType, UUIDType};
#[inline]
pub fn string_to_uuid_type(text: &str) -> UUIDType {
let mut bytes = [0u8; 32];
let s_bytes = text.as_bytes();
let len = s_bytes.len().min(32);
bytes[..len].copy_from_slice(&s_bytes[..len]);
bytes
}
#[inline]
pub fn hash_bytes(bytes: &[u8]) -> UUIDType {
blake3::hash(bytes).into()
UUIDType(blake3::hash(bytes).into())
}
/// generates a hash from a string
@@ -29,13 +19,9 @@ pub fn short_hash(text: &str) -> String {
hex_encode(&hash.as_bytes()[..8])
}
#[inline]
pub fn hex_encode(bytes: &[u8]) -> String {
bytes.iter().fold(String::new(), |mut output, b| {
let _ = write!(output, "{b:02X}");
output
})
hex::encode_upper(bytes)
}
pub fn hex_decode(hex: &str) -> Result<Vec<u8>, String> {
if !hex.len().is_multiple_of(2) {
@@ -52,7 +38,7 @@ pub fn hex_decode(hex: &str) -> Result<Vec<u8>, String> {
}
pub fn hash_string_as_hex(url: &str) -> String {
hex_encode(&hash_string(url))
hex_encode(hash_string(url).as_ref())
}
pub fn extract_id_from_url(url: &str) -> Option<String> {
+1 -1
View File
@@ -167,7 +167,7 @@ where
match deserialize_number_from_string(deserializer) {
Ok(Some(v)) => Ok(v),
Ok(None) => Ok(T::default()),
Err(e) => Err(serde::de::Error::custom(e)),
Err(e) => Err(e),
}
}
+2 -2
View File
@@ -18,7 +18,7 @@ impl<T: AsRef<str>> Capitalize for T {
}
}
pub fn get_trimmed_string(value: &Option<String>) -> Option<String> {
pub fn get_trimmed_string(value: Option<&String>) -> Option<String> {
if let Some(v) = value {
let trimmed = v.trim();
if !trimmed.is_empty() {
@@ -58,7 +58,7 @@ pub fn get_non_empty_str<'a>(first: &'a str, second: &'a str, third: &'a str) ->
}
}
pub fn is_blank_optional_string(s: &Option<String>) -> bool {
pub fn is_blank_optional_string(s: Option<&String>) -> bool {
s.is_none() || s.as_ref().is_some_and(|s| s.trim().is_empty())
}