From 6edf0fd93abf7e58b4c0974e3d3e54bcf8517946 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 8 Dec 2025 19:53:12 +0100 Subject: human-readable cache keys --- server/src/helper/asset.rs | 37 +++++++++++++++++++++++++++++++++++++ server/src/helper/mod.rs | 2 +- server/src/helper/picture.rs | 32 -------------------------------- 3 files changed, 38 insertions(+), 33 deletions(-) create mode 100644 server/src/helper/asset.rs delete mode 100644 server/src/helper/picture.rs (limited to 'server/src/helper') diff --git a/server/src/helper/asset.rs b/server/src/helper/asset.rs new file mode 100644 index 0000000..244aa70 --- /dev/null +++ b/server/src/helper/asset.rs @@ -0,0 +1,37 @@ +/* + This file is part of jellything (https://codeberg.org/metamuffin/jellything) + which is licensed under the GNU Affero General Public License (version 3); see /COPYING. + Copyright (C) 2025 metamuffin +*/ + +use crate::helper::A; +use jellycommon::Asset; +use rocket::{ + http::uri::fmt::{FromUriParam, Path, UriDisplay}, + request::{FromParam, FromSegments}, +}; +use std::fmt::Write; + +impl<'a> FromParam<'a> for A { + type Error = (); + fn from_param(param: &'a str) -> Result { + Ok(A(Asset(param.to_owned()))) + } +} +impl UriDisplay for A { + fn fmt(&self, f: &mut rocket::http::uri::fmt::Formatter<'_, Path>) -> std::fmt::Result { + write!(f, "{}", self.0 .0) + } +} +impl FromUriParam for A { + type Target = A; + fn from_uri_param(param: Asset) -> Self::Target { + A(param) + } +} +impl<'r> FromSegments<'r> for A { + type Error = (); + fn from_segments(segments: rocket::http::uri::Segments<'r, Path>) -> Result { + Ok(A(Asset(segments.collect::>().join("/")))) + } +} diff --git a/server/src/helper/mod.rs b/server/src/helper/mod.rs index 6d1c834..cf592d7 100644 --- a/server/src/helper/mod.rs +++ b/server/src/helper/mod.rs @@ -10,7 +10,7 @@ pub mod filter_sort; pub mod language; pub mod node_id; pub mod session; -pub mod picture; +pub mod asset; use crate::ui::error::{MyError, MyResult}; use accept::Accept; diff --git a/server/src/helper/picture.rs b/server/src/helper/picture.rs deleted file mode 100644 index d5887e3..0000000 --- a/server/src/helper/picture.rs +++ /dev/null @@ -1,32 +0,0 @@ -/* - This file is part of jellything (https://codeberg.org/metamuffin/jellything) - which is licensed under the GNU Affero General Public License (version 3); see /COPYING. - Copyright (C) 2025 metamuffin -*/ - -use crate::helper::A; -use jellycommon::Picture; -use rocket::{ - http::uri::fmt::{FromUriParam, Path, UriDisplay}, - request::FromParam, -}; -use std::fmt::Write; -use std::str::FromStr; - -impl<'a> FromParam<'a> for A { - type Error = (); - fn from_param(param: &'a str) -> Result { - Picture::from_str(param).map_err(|_| ()).map(A) - } -} -impl UriDisplay for A { - fn fmt(&self, f: &mut rocket::http::uri::fmt::Formatter<'_, Path>) -> std::fmt::Result { - write!(f, "{}", self.0) - } -} -impl FromUriParam for A { - type Target = A; - fn from_uri_param(param: Picture) -> Self::Target { - A(param) - } -} -- cgit v1.3