aboutsummaryrefslogtreecommitdiff
path: root/server/src/ui/home.rs
blob: 9e11900d5a13ef92504decf3f13e890046ab7258 (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
/*
    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::Accept, RequestInfo};
use jellycommon::api::ApiHomeResponse;
use jellyui::{home::HomePage, render_page};
use rocket::{get, response::content::RawHtml, serde::json::Json, Either};

#[get("/home")]
pub fn r_home(ri: RequestInfo) -> MyResult<Either<RawHtml<String>, Json<ApiHomeResponse>>> {
    let r = jellylogic::home::home(&ri.session)?;

    Ok(if matches!(ri.accept, Accept::Json) {
        Either::Right(Json(r))
    } else {
        Either::Left(RawHtml(render_page(
            &HomePage { lang: &ri.lang, r },
            ri.render_info(),
        )))
    })
}