aboutsummaryrefslogtreecommitdiff
path: root/server/src/routes/ui/node.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-02-07 14:08:20 +0100
committermetamuffin <metamuffin@disroot.org>2025-02-07 14:08:20 +0100
commit346095d20e3d817d150cbea49e87a49fbcaa2304 (patch)
tree1fc3868fa68287e916e511c8f5b43b62087f0ff9 /server/src/routes/ui/node.rs
parent976bdd8e2d14049c766a654a7575f9f5109c7395 (diff)
downloadjellything-346095d20e3d817d150cbea49e87a49fbcaa2304.tar
jellything-346095d20e3d817d150cbea49e87a49fbcaa2304.tar.bz2
jellything-346095d20e3d817d150cbea49e87a49fbcaa2304.tar.zst
nodeid guard
Diffstat (limited to 'server/src/routes/ui/node.rs')
-rw-r--r--server/src/routes/ui/node.rs35
1 files changed, 17 insertions, 18 deletions
diff --git a/server/src/routes/ui/node.rs b/server/src/routes/ui/node.rs
index 365182c..ebd21db 100644
--- a/server/src/routes/ui/node.rs
+++ b/server/src/routes/ui/node.rs
@@ -40,21 +40,20 @@ use std::sync::Arc;
/// This function is a stub and only useful for use in the uri! macro.
#[get("/n/<id>")]
-pub fn r_library_node(id: String) {
- drop(id)
+pub fn r_library_node(id: NodeID) {
+ id.0[0];
}
-#[get("/n/<slug>?<parents>&<children>&<filter..>")]
+#[get("/n/<id>?<parents>&<children>&<filter..>")]
pub async fn r_library_node_filter<'a>(
session: Session,
- slug: &'a str,
+ id: NodeID,
db: &'a State<Database>,
aj: AcceptJson,
filter: NodeFilterSort,
parents: bool,
children: bool,
) -> MyResult<Either<DynLayoutPage<'a>, Json<ApiNodeResponse>>> {
- let id = NodeID::from_slug(slug);
let (node, udata) = db.get_node_with_userdata(id, &session)?;
let mut children = if !*aj || children {
@@ -99,7 +98,7 @@ pub async fn r_library_node_filter<'a>(
Either::Left(LayoutPage {
title: node.title.clone().unwrap_or_default(),
content: markup::new! {
- @NodePage { node: &node, id: slug, udata: &udata, children: &children, parents: &parents, filter: &filter }
+ @NodePage { node: &node, udata: &udata, children: &children, parents: &parents, filter: &filter }
},
..Default::default()
})
@@ -152,43 +151,43 @@ markup::define! {
}
}
}
- NodePage<'a>(id: &'a str, node: &'a Node, udata: &'a NodeUserData, children: &'a [(Arc<Node>, NodeUserData)], parents: &'a [(Arc<Node>, NodeUserData)], filter: &'a NodeFilterSort) {
+ NodePage<'a>(node: &'a Node, udata: &'a NodeUserData, children: &'a [(Arc<Node>, NodeUserData)], parents: &'a [(Arc<Node>, NodeUserData)], filter: &'a NodeFilterSort) {
@if !matches!(node.kind, NodeKind::Collection) {
- img.backdrop[src=uri!(r_item_backdrop(id, Some(2048))), loading="lazy"];
+ img.backdrop[src=uri!(r_item_backdrop(&node.slug, Some(2048))), loading="lazy"];
}
.page.node {
@if !matches!(node.kind, NodeKind::Collection) {
@let cls = format!("bigposter {}", aspect_class(node.kind));
- div[class=cls] { img[src=uri!(r_item_poster(id, Some(2048))), loading="lazy"]; }
+ div[class=cls] { img[src=uri!(r_item_poster(&node.slug, Some(2048))), loading="lazy"]; }
}
.title {
h1 { @node.title }
ul.parents { @for (node, _) in *parents { li {
a.component[href=uri!(r_library_node(&node.slug))] { @node.title }
}}}
- @if node.media.is_some() { a.play[href=&uri!(r_player(id, PlayerConfig::default()))] { "Watch now" }}
+ @if node.media.is_some() { a.play[href=&uri!(r_player(&node.slug, PlayerConfig::default()))] { "Watch now" }}
@if !matches!(node.kind, NodeKind::Collection | NodeKind::Channel) {
@if matches!(udata.watched, WatchedState::None | WatchedState::Pending | WatchedState::Progress(_)) {
- form.mark_watched[method="POST", action=uri!(r_node_userdata_watched(id, UrlWatchedState::Watched))] {
+ form.mark_watched[method="POST", action=uri!(r_node_userdata_watched(&node.slug, UrlWatchedState::Watched))] {
input[type="submit", value="Mark Watched"];
}
}
@if matches!(udata.watched, WatchedState::Watched) {
- form.mark_unwatched[method="POST", action=uri!(r_node_userdata_watched(id, UrlWatchedState::None))] {
+ form.mark_unwatched[method="POST", action=uri!(r_node_userdata_watched(&node.slug, UrlWatchedState::None))] {
input[type="submit", value="Mark Unwatched"];
}
}
@if matches!(udata.watched, WatchedState::None) {
- form.mark_unwatched[method="POST", action=uri!(r_node_userdata_watched(id, UrlWatchedState::Pending))] {
+ form.mark_unwatched[method="POST", action=uri!(r_node_userdata_watched(&node.slug, UrlWatchedState::Pending))] {
input[type="submit", value="Add to Watchlist"];
}
}
@if matches!(udata.watched, WatchedState::Pending) {
- form.mark_unwatched[method="POST", action=uri!(r_node_userdata_watched(id, UrlWatchedState::None))] {
+ form.mark_unwatched[method="POST", action=uri!(r_node_userdata_watched(&node.slug, UrlWatchedState::None))] {
input[type="submit", value="Remove from Watchlist"];
}
}
- form.rating[method="POST", action=uri!(r_node_userdata_rating(id))] {
+ form.rating[method="POST", action=uri!(r_node_userdata_rating(&node.slug))] {
input[type="range", name="rating", min=-10, max=10, step=1, value=udata.rating];
input[type="submit", value="Update Rating"];
}
@@ -207,8 +206,8 @@ markup::define! {
@let (inl, sub) = format_chapter(chap);
li { .card."aspect-thumb" {
.poster {
- a[href=&uri!(r_player(id, PlayerConfig::seek(chap.time_start.unwrap_or(0.))))] {
- img[src=&uri!(r_node_thumbnail(id, chapter_key_time(chap, media.duration), Some(1024))), loading="lazy"];
+ a[href=&uri!(r_player(&node.slug, PlayerConfig::seek(chap.time_start.unwrap_or(0.))))] {
+ img[src=&uri!(r_node_thumbnail(&node.slug, chapter_key_time(chap, media.duration), Some(1024))), loading="lazy"];
}
.cardhover { .props { p { @inl } } }
}
@@ -225,7 +224,7 @@ markup::define! {
li { .card."aspect-port" {
.poster {
a[href="#"] {
- img[src=&uri!(r_person_asset(id, i, group.to_string(), Some(1024))), loading="lazy"];
+ img[src=&uri!(r_person_asset(&node.slug, i, group.to_string(), Some(1024))), loading="lazy"];
}
}
.title {