aboutsummaryrefslogtreecommitdiff
path: root/server/src/ui/stats.rs
blob: a91e67096ac56ab0d63041c3171bc605b4f2f358 (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
/*
    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::MyError,
    layout::{DynLayoutPage, LayoutPage},
};
use crate::{
    api::AcceptJson, database::Database, locale::AcceptLanguage, logic::session::Session, uri,
};
use jellybase::locale::tr;
use jellycommon::{
    api::{ApiStatsResponse, StatsBin},
    Node, NodeID, NodeKind, Visibility,
};
use jellylogic::stats::stats;
use markup::raw;
use rocket::{get, serde::json::Json, Either, State};
use serde::Serialize;
use serde_json::{json, Value};
use std::collections::BTreeMap;

#[get("/stats")]
pub fn r_stats(
    sess: Session,
    db: &State<Database>,
    aj: AcceptJson,
    lang: AcceptLanguage,
) -> Result<Either<DynLayoutPage<'_>, Json<ApiStatsResponse>>, MyError> {
    let AcceptLanguage(lang) = lang;
    let data = stats(db)?;

    Ok(if *aj {
        Either::Right(Json(data))
    } else {
        Either::Left(1)
    })
}