aboutsummaryrefslogtreecommitdiff
path: root/server/src/helper
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-12-08 19:53:12 +0100
committermetamuffin <metamuffin@disroot.org>2025-12-08 19:53:12 +0100
commit6edf0fd93abf7e58b4c0974e3d3e54bcf8517946 (patch)
tree32577db9d987897d4037ba9af0084b95b55e145c /server/src/helper
parente4584a8135584e6591bac7d5397cf227cf3cff92 (diff)
downloadjellything-6edf0fd93abf7e58b4c0974e3d3e54bcf8517946.tar
jellything-6edf0fd93abf7e58b4c0974e3d3e54bcf8517946.tar.bz2
jellything-6edf0fd93abf7e58b4c0974e3d3e54bcf8517946.tar.zst
human-readable cache keys
Diffstat (limited to 'server/src/helper')
-rw-r--r--server/src/helper/asset.rs37
-rw-r--r--server/src/helper/mod.rs2
-rw-r--r--server/src/helper/picture.rs32
3 files changed, 38 insertions, 33 deletions
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 <metamuffin.org>
+*/
+
+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<Asset> {
+ type Error = ();
+ fn from_param(param: &'a str) -> Result<Self, Self::Error> {
+ Ok(A(Asset(param.to_owned())))
+ }
+}
+impl UriDisplay<Path> for A<Asset> {
+ fn fmt(&self, f: &mut rocket::http::uri::fmt::Formatter<'_, Path>) -> std::fmt::Result {
+ write!(f, "{}", self.0 .0)
+ }
+}
+impl FromUriParam<Path, Asset> for A<Asset> {
+ type Target = A<Asset>;
+ fn from_uri_param(param: Asset) -> Self::Target {
+ A(param)
+ }
+}
+impl<'r> FromSegments<'r> for A<Asset> {
+ type Error = ();
+ fn from_segments(segments: rocket::http::uri::Segments<'r, Path>) -> Result<Self, Self::Error> {
+ Ok(A(Asset(segments.collect::<Vec<_>>().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 <metamuffin.org>
-*/
-
-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<Picture> {
- type Error = ();
- fn from_param(param: &'a str) -> Result<Self, Self::Error> {
- Picture::from_str(param).map_err(|_| ()).map(A)
- }
-}
-impl UriDisplay<Path> for A<Picture> {
- fn fmt(&self, f: &mut rocket::http::uri::fmt::Formatter<'_, Path>) -> std::fmt::Result {
- write!(f, "{}", self.0)
- }
-}
-impl FromUriParam<Path, Picture> for A<Picture> {
- type Target = A<Picture>;
- fn from_uri_param(param: Picture) -> Self::Target {
- A(param)
- }
-}