diff options
| author | metamuffin <metamuffin@disroot.org> | 2025-11-30 12:32:44 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2025-11-30 12:32:44 +0100 |
| commit | 8174d129fbabd2d39323678d11d868893ddb429a (patch) | |
| tree | 7979a528114cd5fb827f748f678a916e8e8eeddc /server/src/helper | |
| parent | 5db15c323d76dca9ae71b0204d63dcb09fbbcbc5 (diff) | |
| download | jellything-8174d129fbabd2d39323678d11d868893ddb429a.tar jellything-8174d129fbabd2d39323678d11d868893ddb429a.tar.bz2 jellything-8174d129fbabd2d39323678d11d868893ddb429a.tar.zst | |
new sync cache
Diffstat (limited to 'server/src/helper')
| -rw-r--r-- | server/src/helper/cache.rs | 15 | ||||
| -rw-r--r-- | server/src/helper/mod.rs | 1 | ||||
| -rw-r--r-- | server/src/helper/picture.rs | 32 |
3 files changed, 48 insertions, 0 deletions
diff --git a/server/src/helper/cache.rs b/server/src/helper/cache.rs index d4c0595..93743e7 100644 --- a/server/src/helper/cache.rs +++ b/server/src/helper/cache.rs @@ -12,6 +12,7 @@ use rocket::{ }; use std::{ hash::{DefaultHasher, Hash, Hasher}, + io::Cursor, os::unix::fs::MetadataExt, path::Path, }; @@ -54,3 +55,17 @@ impl<'r> Responder<'r, 'static> for CacheControlFile { } } } + +pub struct CacheControlImage(pub Vec<u8>); +impl<'r> Responder<'r, 'static> for CacheControlImage { + fn respond_to(self, _req: &'r Request<'_>) -> response::Result<'static> { + Response::build() + .status(Status::Ok) + .header(Header::new( + "cache-control", + "private, immutable, maxage=86400", + )) + .sized_body(self.0.len(), Cursor::new(self.0)) + .ok() + } +} diff --git a/server/src/helper/mod.rs b/server/src/helper/mod.rs index a4e0e1f..6d1c834 100644 --- a/server/src/helper/mod.rs +++ b/server/src/helper/mod.rs @@ -10,6 +10,7 @@ pub mod filter_sort; pub mod language; pub mod node_id; pub mod session; +pub mod picture; use crate::ui::error::{MyError, MyResult}; use accept::Accept; diff --git a/server/src/helper/picture.rs b/server/src/helper/picture.rs new file mode 100644 index 0000000..d5887e3 --- /dev/null +++ b/server/src/helper/picture.rs @@ -0,0 +1,32 @@ +/* + 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) + } +} |