aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-11-30 12:32:44 +0100
committermetamuffin <metamuffin@disroot.org>2025-11-30 12:32:44 +0100
commit8174d129fbabd2d39323678d11d868893ddb429a (patch)
tree7979a528114cd5fb827f748f678a916e8e8eeddc /common
parent5db15c323d76dca9ae71b0204d63dcb09fbbcbc5 (diff)
downloadjellything-8174d129fbabd2d39323678d11d868893ddb429a.tar
jellything-8174d129fbabd2d39323678d11d868893ddb429a.tar.bz2
jellything-8174d129fbabd2d39323678d11d868893ddb429a.tar.zst
new sync cache
Diffstat (limited to 'common')
-rw-r--r--common/Cargo.toml1
-rw-r--r--common/src/helpers.rs41
-rw-r--r--common/src/lib.rs9
-rw-r--r--common/src/routes.rs9
4 files changed, 48 insertions, 12 deletions
diff --git a/common/Cargo.toml b/common/Cargo.toml
index 37e9c6c..7e25933 100644
--- a/common/Cargo.toml
+++ b/common/Cargo.toml
@@ -9,3 +9,4 @@ chrono = { version = "0.4.42", features = ["serde"] }
blake3 = "1.8.2"
hex = "0.4.3"
jellystream-types = { path = "../stream/types" }
+base64 = "0.22.1"
diff --git a/common/src/helpers.rs b/common/src/helpers.rs
index db75ba9..431bf8c 100644
--- a/common/src/helpers.rs
+++ b/common/src/helpers.rs
@@ -4,7 +4,9 @@
Copyright (C) 2025 metamuffin <metamuffin.org>
*/
-use crate::{CreditCategory, IdentifierType};
+use base64::{Engine, prelude::BASE64_URL_SAFE};
+
+use crate::{CreditCategory, IdentifierType, Picture, PictureSlot};
use std::{fmt::Display, ops::Deref, str::FromStr};
#[derive(PartialEq)]
@@ -129,3 +131,40 @@ impl FromStr for IdentifierType {
})
}
}
+impl Display for PictureSlot {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.write_str(match self {
+ PictureSlot::Backdrop => "backdrop",
+ PictureSlot::Cover => "cover",
+ })
+ }
+}
+impl FromStr for PictureSlot {
+ type Err = ();
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ Ok(match s {
+ "backdrop" => PictureSlot::Backdrop,
+ "cover" => PictureSlot::Cover,
+ _ => return Err(()),
+ })
+ }
+}
+
+impl Display for Picture {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.write_str(&BASE64_URL_SAFE.encode(self.0))
+ }
+}
+impl FromStr for Picture {
+ type Err = &'static str;
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ let mut out = [0; 32];
+ let size = BASE64_URL_SAFE
+ .decode_slice(s, &mut out)
+ .map_err(|_| "invalid base64 picture key")?;
+ if size != out.len() {
+ return Err("picture key parse invalid size");
+ }
+ Ok(Self(out))
+ }
+}
diff --git a/common/src/lib.rs b/common/src/lib.rs
index f3d8416..3f535fd 100644
--- a/common/src/lib.rs
+++ b/common/src/lib.rs
@@ -68,7 +68,7 @@ pub struct Node {
pub federated: Option<String>,
pub tags: BTreeSet<String>,
pub ratings: BTreeMap<RatingType, f64>,
- pub pictures: BTreeMap<PictureSlot, Asset>,
+ pub pictures: BTreeMap<PictureSlot, Picture>,
pub credits: BTreeMap<CreditCategory, Vec<Appearance>>,
pub identifiers: BTreeMap<IdentifierType, String>,
pub visibility: Visibility,
@@ -78,10 +78,8 @@ pub struct Node {
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)]
#[serde(rename_all = "snake_case")]
pub enum PictureSlot {
- Poster,
Cover,
Backdrop,
- Headshot,
}
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)]
@@ -105,8 +103,9 @@ pub enum IdentifierType {
Omdb,
}
-#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
-pub struct Asset(pub PathBuf);
+// TODO custom b64 ser
+#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Copy)]
+pub struct Picture(pub [u8; 32]);
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Appearance {
diff --git a/common/src/routes.rs b/common/src/routes.rs
index f78c7f0..19b0206 100644
--- a/common/src/routes.rs
+++ b/common/src/routes.rs
@@ -3,7 +3,7 @@
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2025 metamuffin <metamuffin.org>
*/
-use crate::{api::NodeFilterSort, user::ApiWatchedState, NodeID, CreditCategory};
+use crate::{CreditCategory, NodeID, PictureSlot, api::NodeFilterSort, user::ApiWatchedState};
pub fn u_home() -> String {
"/home".to_owned()
@@ -20,11 +20,8 @@ pub fn u_node_slug_player(node: &str) -> String {
pub fn u_node_slug_player_time(node: &str, time: f64) -> String {
format!("/n/{node}/player?t={time}")
}
-pub fn u_node_slug_poster(node: &str, width: usize) -> String {
- format!("/n/{node}/poster?width={width}")
-}
-pub fn u_node_slug_backdrop(node: &str, width: usize) -> String {
- format!("/n/{node}/backdrop?width={width}")
+pub fn u_node_image(node: &str, slot: PictureSlot, width: usize) -> String {
+ format!("/n/{node}/image/{slot}?width={width}")
}
pub fn u_node_slug_watched(node: &str, state: ApiWatchedState) -> String {
format!("/n/{node}/watched?state={state}")