1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
/*
This file is part of jellything (https://codeberg.org/metamuffin/jellything)
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2025 metamuffin <metamuffin.org>
*/
use super::error::MyResult;
use crate::helper::{RequestInfo, A};
use jellycommon::{
api::{ApiNodeResponse, NodeFilterSort},
NodeID,
};
use jellylogic::node::get_node;
use jellyui::{node_page::NodePage, render_page};
use rocket::{get, response::content::RawHtml, serde::json::Json, Either};
#[get("/n/<id>?<parents>&<children>&<filter..>")]
pub async fn r_node<'a>(
ri: RequestInfo,
id: A<NodeID>,
filter: Option<A<NodeFilterSort>>,
parents: bool,
children: bool,
) -> MyResult<Either<RawHtml<String>, Json<ApiNodeResponse>>> {
let filter = filter.unwrap_or_default();
let r = get_node(
&ri.session,
id.0,
!ri.accept.is_json() || children,
!ri.accept.is_json() || parents,
filter.0.clone(),
)?;
Ok(if ri.accept.is_json() {
Either::Right(Json(r))
} else {
Either::Left(RawHtml(render_page(
&NodePage {
node: &r.node,
udata: &r.userdata,
children: &r.children,
parents: &r.parents,
similar: &[],
filter: &filter.0,
lang: &ri.lang,
player: false,
},
ri.render_info(),
)))
})
}
|