aboutsummaryrefslogtreecommitdiff
path: root/server/src/ui/assets.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2026-01-25 23:32:53 +0100
committermetamuffin <metamuffin@disroot.org>2026-01-25 23:32:53 +0100
commit783d3598753bf84756296a2016e5dab30300519b (patch)
treef7eaf276b65de8aab10db21d27e534f775d83167 /server/src/ui/assets.rs
parent5075aede44cb8ab2df10e6debba38483e8d11e96 (diff)
downloadjellything-783d3598753bf84756296a2016e5dab30300519b.tar
jellything-783d3598753bf84756296a2016e5dab30300519b.tar.bz2
jellything-783d3598753bf84756296a2016e5dab30300519b.tar.zst
work on login
Diffstat (limited to 'server/src/ui/assets.rs')
-rw-r--r--server/src/ui/assets.rs77
1 files changed, 38 insertions, 39 deletions
diff --git a/server/src/ui/assets.rs b/server/src/ui/assets.rs
index 8f3fb4a..c956672 100644
--- a/server/src/ui/assets.rs
+++ b/server/src/ui/assets.rs
@@ -4,58 +4,57 @@
Copyright (C) 2026 metamuffin <metamuffin.org>
*/
use super::error::MyResult;
-use anyhow::{Context, anyhow};
-use rocket::{get, http::ContentType, response::Redirect};
-use std::str::FromStr;
+use crate::{request_info::RequestInfo, responders::cache::CacheControlImage};
+use anyhow::Context;
+use rocket::{get, http::ContentType};
+use std::path::PathBuf;
pub const AVIF_QUALITY: u32 = 70;
pub const AVIF_SPEED: u8 = 5;
-#[get("/image/<key..>?<size>")]
+#[get("/image/<path..>?<size>")]
pub async fn r_image(
- _session: A<Session>,
- key: A<Asset>,
+ ri: RequestInfo<'_>,
+ path: PathBuf,
size: Option<usize>,
) -> MyResult<(ContentType, CacheControlImage)> {
let size = size.unwrap_or(2048);
-
- if !key.0.0.ends_with(".image") {
- Err(anyhow!("request to non-image"))?
- }
+ let path = path.to_string_lossy().to_string();
// fit the resolution into a finite set so the maximum cache is finite too.
let width = 2usize.pow(size.clamp(128, 2048).ilog2());
- let encoded = jellytranscoder::image::transcode(&key.0.0, AVIF_QUALITY, AVIF_SPEED, width)
- .context("transcoding asset")?;
+ let encoded =
+ jellytranscoder::image::transcode(&ri.state.cache, &path, AVIF_QUALITY, AVIF_SPEED, width)
+ .context("transcoding asset")?;
Ok((ContentType::AVIF, CacheControlImage(encoded)))
}
-#[get("/n/<id>/image/<slot>?<size>")]
-pub async fn r_item_poster(
- session: A<Session>,
- id: A<NodeID>,
- slot: &str,
- size: Option<usize>,
-) -> MyResult<Redirect> {
- let slot = PictureSlot::from_str(slot).map_err(|_| anyhow!("slot invalid"))?;
- let node = get_node(&session.0, id.0, false, false, NodeFilterSort::default())?;
- let picture = node
- .node
- .pictures
- .get(&slot)
- .cloned()
- .ok_or(anyhow!("no pic todo"))?;
- Ok(Redirect::permanent(rocket::uri!(r_image(picture, size))))
-}
+// #[get("/n/<id>/image/<slot>?<size>")]
+// pub async fn r_item_poster(
+// session: A<Session>,
+// id: A<NodeID>,
+// slot: &str,
+// size: Option<usize>,
+// ) -> MyResult<Redirect> {
+// let slot = PictureSlot::from_str(slot).map_err(|_| anyhow!("slot invalid"))?;
+// let node = get_node(&session.0, id.0, false, false, NodeFilterSort::default())?;
+// let picture = node
+// .node
+// .pictures
+// .get(&slot)
+// .cloned()
+// .ok_or(anyhow!("no pic todo"))?;
+// Ok(Redirect::permanent(rocket::uri!(r_image(picture, size))))
+// }
-#[get("/n/<id>/thumbnail?<t>&<size>")]
-pub async fn r_node_thumbnail(
- session: A<Session>,
- id: A<NodeID>,
- t: f64,
- size: Option<usize>,
-) -> MyResult<Redirect> {
- let picture = get_node_thumbnail(&session.0, id.0, t).await?;
- Ok(Redirect::permanent(rocket::uri!(r_image(picture, size))))
-}
+// #[get("/n/<id>/thumbnail?<t>&<size>")]
+// pub async fn r_node_thumbnail(
+// session: A<Session>,
+// id: A<NodeID>,
+// t: f64,
+// size: Option<usize>,
+// ) -> MyResult<Redirect> {
+// let picture = get_node_thumbnail(&session.0, id.0, t).await?;
+// Ok(Redirect::permanent(rocket::uri!(r_image(picture, size))))
+// }