diff options
author | metamuffin <metamuffin@disroot.org> | 2024-01-21 23:38:28 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-01-21 23:38:28 +0100 |
commit | b127ee51925f59b306b032dbacc11464ed175a60 (patch) | |
tree | b7097c20a560019f90394de9e21da4c498aadabb /server/src/routes/ui/assets.rs | |
parent | a8fe841aaefe904121d936e608572a1422191167 (diff) | |
download | jellything-b127ee51925f59b306b032dbacc11464ed175a60.tar jellything-b127ee51925f59b306b032dbacc11464ed175a60.tar.bz2 jellything-b127ee51925f59b306b032dbacc11464ed175a60.tar.zst |
refactor tmdb api, cast&crew, node ext
Diffstat (limited to 'server/src/routes/ui/assets.rs')
-rw-r--r-- | server/src/routes/ui/assets.rs | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/server/src/routes/ui/assets.rs b/server/src/routes/ui/assets.rs index 05ddc7c..ebd9453 100644 --- a/server/src/routes/ui/assets.rs +++ b/server/src/routes/ui/assets.rs @@ -10,13 +10,13 @@ use crate::{ use anyhow::{anyhow, Context}; use jellybase::{ cache::async_cache_file, - database::{TableExt, T_NODE}, + database::{TableExt, T_NODE, T_NODE_EXTENDED}, federation::Federation, permission::NodePermissionExt, AssetLocationExt, }; pub use jellycommon::AssetRole; -use jellycommon::{AssetLocation, LocalTrack, SourceTrackKind, TrackSource}; +use jellycommon::{AssetLocation, LocalTrack, PeopleGroup, SourceTrackKind, TrackSource}; use log::info; use rocket::{get, http::ContentType, State}; use std::{path::PathBuf, str::FromStr}; @@ -56,6 +56,38 @@ pub async fn r_item_assets( Ok(asset_with_res(asset, width).await?) } +#[get("/n/<id>/person/<index>/asset?<group>&<width>")] +pub async fn r_person_asset( + session: Session, + db: &State<DataAcid>, + id: &str, + index: usize, + group: PeopleGroup, + width: Option<usize>, +) -> MyResult<(ContentType, CacheControlFile)> { + T_NODE + .get(&db, id)? + .only_if_permitted(&session.user.permissions) + .ok_or(anyhow!("node does not exist"))?; + + let ext = T_NODE_EXTENDED.get(db, id)?.unwrap_or_default(); + let app = ext + .people + .get(&group) + .ok_or(anyhow!("group has no members"))? + .get(index) + .ok_or(anyhow!("person does not exist"))?; + + let asset = app + .person + .asset + .as_ref() + .ok_or(anyhow!("no asset"))? + .to_owned(); + + Ok(asset_with_res(asset, width).await?) +} + // TODO this can create "federation recursion" because track selection cannot be relied on. #[get("/n/<id>/thumbnail?<t>&<width>")] pub async fn r_node_thumbnail( |