aboutsummaryrefslogtreecommitdiff
path: root/server/src/ui/node.rs
blob: 6241f4fe74d0575428f82dd746f25b1463a3450e (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
    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::{api::AcceptJson, database::Database, helper::A, locale::AcceptLanguage};
use jellycommon::{
    api::{ApiNodeResponse, NodeFilterSort},
    NodeID,
};
use jellyimport::is_importing;
use jellylogic::{node::get_node, session::Session};
use jellyui::{
    node_page::NodePage,
    render_page,
    scaffold::{RenderInfo, SessionInfo},
};
use rocket::{get, response::content::RawHtml, serde::json::Json, Either, State};

#[get("/n/<id>?<parents>&<children>&<filter..>")]
pub async fn r_node<'a>(
    session: A<Session>,
    id: A<NodeID>,
    db: &'a State<Database>,
    aj: AcceptJson,
    filter: A<NodeFilterSort>,
    lang: AcceptLanguage,
    parents: bool,
    children: bool,
) -> MyResult<Either<RawHtml<String>, Json<ApiNodeResponse>>> {
    let AcceptLanguage(lang) = lang;

    let r = get_node(
        &db,
        id.0,
        &session.0,
        !*aj || children,
        !*aj || parents,
        filter.0.clone(),
    )?;

    Ok(if *aj {
        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: &lang,
                player: false,
            },
            RenderInfo {
                importing: is_importing(),
                session: Some(SessionInfo {
                    user: session.0.user,
                }),
            },
            lang,
        )))
    })
}