aboutsummaryrefslogtreecommitdiff
path: root/server/src/ui/admin/log.rs
blob: bd6d7af4ca23a0ba58f3888449678b42a143b904 (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
/*
    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 crate::ui::error::MyResult;
use jellylogic::{admin::log::get_log_stream, session::AdminSession};
use jellyui::admin::log::render_log_line;
use rocket::{get, response::content::RawHtml};
use rocket_ws::{Message, Stream, WebSocket};
use serde_json::json;

#[get("/admin/log?<warnonly>", rank = 2)]
pub fn r_admin_log<'a>(_session: AdminSession, warnonly: bool) -> MyResult<RawHtml<String>> {}

#[get("/admin/log?stream&<warnonly>&<html>", rank = 1)]
pub fn r_admin_log_stream(
    _session: AdminSession,
    ws: WebSocket,
    warnonly: bool,
    html: bool,
) -> Stream!['static] {
    let mut stream = get_log_stream(warnonly);
    Stream! { ws =>
        if html {
            let _ = ws;
            while let Ok(line) = stream.recv().await {
                yield Message::Text(render_log_line(&line));
            }
        } else {
            let _ = ws;
            while let Ok(line) = stream.recv().await {
                yield Message::Text(json!(line).to_string());
            }
        }
    }
}