diff options
author | metamuffin <metamuffin@disroot.org> | 2023-08-02 11:23:48 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-08-02 11:23:48 +0200 |
commit | 59e6e7a6feafaf1dada3054466d415cca047ca1a (patch) | |
tree | 220f4a8d492ced2ffb587d0c99e44f7e2d5f5b9f /server/src/routes/ui | |
parent | 96abb9182e20cc4ab80d272de26cbce427b94473 (diff) | |
download | jellything-59e6e7a6feafaf1dada3054466d415cca047ca1a.tar jellything-59e6e7a6feafaf1dada3054466d415cca047ca1a.tar.bz2 jellything-59e6e7a6feafaf1dada3054466d415cca047ca1a.tar.zst |
node api on the same route
Diffstat (limited to 'server/src/routes/ui')
-rw-r--r-- | server/src/routes/ui/node.rs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/server/src/routes/ui/node.rs b/server/src/routes/ui/node.rs index e4bf329..93186bf 100644 --- a/server/src/routes/ui/node.rs +++ b/server/src/routes/ui/node.rs @@ -6,29 +6,37 @@ use super::{assets::rocket_uri_macro_r_item_assets, error::MyError, player::player_uri}; use crate::{ database::Database, - routes::ui::{ - account::session::Session, - assets::AssetRole, - layout::{DynLayoutPage, LayoutPage}, + routes::{ + api::AcceptJson, + ui::{ + account::session::Session, + assets::AssetRole, + layout::{DynLayoutPage, LayoutPage}, + }, }, uri, }; use anyhow::{anyhow, Context}; use jellycommon::{Node, NodeKind}; -use rocket::{get, State}; +use rocket::{get, serde::json::Json, Either, State}; #[get("/n/<id>")] pub async fn r_library_node( _sess: Session, id: String, db: &State<Database>, -) -> Result<DynLayoutPage<'_>, MyError> { + aj: AcceptJson, +) -> Result<Either<DynLayoutPage<'_>, Json<Node>>, MyError> { let node = db .node .get(&id) .context("retrieving library node")? .ok_or(anyhow!("node does not exist"))?; + if *aj { + return Ok(Either::Right(Json(node))); + } + let children = node .public .children @@ -43,14 +51,14 @@ pub async fn r_library_node( .into_iter() .collect(); - Ok(LayoutPage { + Ok(Either::Left(LayoutPage { title: node.public.title.to_string(), show_back: matches!(node.public.kind, NodeKind::Movie | NodeKind::Episode), content: markup::new! { @NodePage { node: &node, id: &id, children: &children } }, ..Default::default() - }) + })) } markup::define! { |