aboutsummaryrefslogtreecommitdiff
path: root/server/src/ui/home.rs
blob: 4a423cf79994d8f1c4b3802f4f9caba3b5930cc0 (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
/*
    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::{accept::AcceptJson, language::AcceptLanguage, A};
use jellycommon::api::ApiHomeResponse;
use jellyimport::is_importing;
use jellylogic::session::Session;
use jellyui::{
    home::HomePage,
    render_page,
    scaffold::{RenderInfo, SessionInfo},
};
use rocket::{get, response::content::RawHtml, serde::json::Json, Either};

#[get("/home")]
pub fn r_home(
    session: A<Session>,
    aj: AcceptJson,
    lang: AcceptLanguage,
) -> MyResult<Either<RawHtml<String>, Json<ApiHomeResponse>>> {
    let AcceptLanguage(lang) = lang;

    let r = jellylogic::home::home(&session.0)?;

    Ok(if *aj {
        Either::Right(Json(r))
    } else {
        Either::Left(RawHtml(render_page(
            &HomePage { lang: &lang, r },
            RenderInfo {
                importing: is_importing(),
                session: Some(SessionInfo {
                    user: session.0.user,
                }),
            },
            lang,
        )))
    })
}