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
|
/*
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) 2026 metamuffin <metamuffin.org>
*/
use super::error::MyResult;
use crate::request_info::RequestInfo;
use rocket::{Either, get, response::content::RawHtml, serde::json::Json};
#[get("/n/<id>?<parents>&<children>&<filter..>")]
pub async fn r_node(
ri: RequestInfo<'_>,
id: A<NodeID>,
filter: Option<ANodeFilterSort>,
parents: bool,
children: bool,
) -> MyResult<Either<RawHtml<String>, Json<ApiNodeResponse>>> {
let filter: Option<NodeFilterSort> = filter.map(Into::into);
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.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,
lang: &ri.lang,
player: false,
},
ri.render_info(),
)))
})
}
|