aboutsummaryrefslogtreecommitdiff
path: root/server/src/routes/ui/assets.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/routes/ui/assets.rs')
-rw-r--r--server/src/routes/ui/assets.rs36
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(