aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/Cargo.toml1
-rw-r--r--common/src/impl.rs22
-rw-r--r--common/src/lib.rs7
3 files changed, 28 insertions, 2 deletions
diff --git a/common/Cargo.toml b/common/Cargo.toml
index 13fe29b..066e79c 100644
--- a/common/Cargo.toml
+++ b/common/Cargo.toml
@@ -8,6 +8,7 @@ serde = { version = "1.0.217", features = ["derive"] }
bincode = { version = "2.0.0-rc.3", features = ["derive"] }
rocket = { workspace = true, optional = true }
chrono = { version = "0.4.39", features = ["serde"] }
+blake3 = "1.5.5"
[features]
rocket = ["dep:rocket"]
diff --git a/common/src/impl.rs b/common/src/impl.rs
index a35216b..a98015a 100644
--- a/common/src/impl.rs
+++ b/common/src/impl.rs
@@ -3,7 +3,9 @@
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2025 metamuffin <metamuffin.org>
*/
-use crate::{ObjectIds, PeopleGroup, SourceTrack, SourceTrackKind, TmdbKind, TraktKind};
+use crate::{
+ Node, NodeID, ObjectIds, PeopleGroup, SourceTrack, SourceTrackKind, TmdbKind, TraktKind,
+};
use std::{fmt::Display, str::FromStr};
impl SourceTrackKind {
@@ -146,3 +148,21 @@ impl FromStr for PeopleGroup {
})
}
}
+
+impl NodeID {
+ pub fn from_slug(slug: &str) -> Self {
+ let mut h = blake3::Hasher::new();
+ h.update(slug.as_bytes());
+ Self(*h.finalize().as_bytes())
+ }
+ #[inline]
+ pub fn from_node(node: &Node) -> Self {
+ Self::from_slug(&node.slug)
+ }
+}
+impl Node {
+ #[inline]
+ pub fn id(&self) -> NodeID {
+ NodeID::from_node(self)
+ }
+}
diff --git a/common/src/lib.rs b/common/src/lib.rs
index a72f345..05d1573 100644
--- a/common/src/lib.rs
+++ b/common/src/lib.rs
@@ -17,10 +17,15 @@ use bincode::{Decode, Encode};
use serde::{Deserialize, Serialize};
use std::{collections::BTreeMap, path::PathBuf};
+#[derive(
+ Clone, Copy, Debug, Serialize, Deserialize, Encode, Decode, PartialEq, Eq, PartialOrd, Ord,
+)]
+pub struct NodeID(pub [u8; 32]);
+
#[derive(Debug, Clone, Deserialize, Serialize, Default, Encode, Decode)]
pub struct Node {
pub slug: String,
- pub parents: Vec<String>,
+ pub parents: Vec<NodeID>,
pub kind: Option<NodeKind>,
pub poster: Option<Asset>,
pub backdrop: Option<Asset>,