diff options
author | metamuffin <metamuffin@disroot.org> | 2025-05-04 15:11:11 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-05-04 15:11:11 +0200 |
commit | 3cbe45e24355396645b9a721fdca6d5116bd1c36 (patch) | |
tree | ecc5e61167c47362c49375e542bf6752aad12b09 | |
parent | 0a5c23757c2a0fc8784ea1b5a3ad5b0cba0709e0 (diff) | |
download | jellything-3cbe45e24355396645b9a721fdca6d5116bd1c36.tar jellything-3cbe45e24355396645b9a721fdca6d5116bd1c36.tar.bz2 jellything-3cbe45e24355396645b9a721fdca6d5116bd1c36.tar.zst |
fix live log
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | logic/Cargo.toml | 1 | ||||
-rw-r--r-- | logic/src/admin/log.rs | 4 | ||||
-rw-r--r-- | logic/src/admin/mod.rs | 14 | ||||
-rw-r--r-- | server/src/ui/admin/mod.rs | 58 | ||||
-rw-r--r-- | ui/src/admin/log.rs | 3 | ||||
-rw-r--r-- | web/script/log_stream.ts | 25 |
7 files changed, 30 insertions, 76 deletions
@@ -1849,6 +1849,7 @@ dependencies = [ "env_logger", "jellycommon", "jellydb", + "jellyimport", "jellyimport-asset-token", "log", "rand 0.9.1", diff --git a/logic/Cargo.toml b/logic/Cargo.toml index 23016f9..fd70b73 100644 --- a/logic/Cargo.toml +++ b/logic/Cargo.toml @@ -5,6 +5,7 @@ edition = "2024" [dependencies] jellyimport-asset-token = { path = "../import/asset_token" } +jellyimport = { path = "../import" } jellycommon = { path = "../common" } jellydb = { path = "../database" } log = "0.4.27" diff --git a/logic/src/admin/log.rs b/logic/src/admin/log.rs index 64d23ca..7130c45 100644 --- a/logic/src/admin/log.rs +++ b/logic/src/admin/log.rs @@ -44,9 +44,9 @@ pub fn get_log_buffer(warn: bool) -> VecDeque<Arc<LogLine>> { } pub fn get_log_stream(warn: bool) -> broadcast::Receiver<Arc<LogLine>> { if warn { - LOGGER.stream.0.subscribe() - } else { LOGGER.stream.1.subscribe() + } else { + LOGGER.stream.0.subscribe() } } diff --git a/logic/src/admin/mod.rs b/logic/src/admin/mod.rs index 270a732..2545ba4 100644 --- a/logic/src/admin/mod.rs +++ b/logic/src/admin/mod.rs @@ -4,5 +4,17 @@ Copyright (C) 2025 metamuffin <metamuffin.org> */ -pub mod user; pub mod log; +pub mod user; + +use crate::session::AdminSession; +use anyhow::Result; +use jellydb::Database; +use jellyimport::IMPORT_ERRORS; + +pub async fn get_import_errors(_session: &AdminSession) -> Vec<String> { + IMPORT_ERRORS.read().await.to_owned() +} +pub fn list_invites(_session: &AdminSession, database: &Database) -> Result<Vec<String>> { + database.list_invites() +} diff --git a/server/src/ui/admin/mod.rs b/server/src/ui/admin/mod.rs index 9bf85b5..a03d09b 100644 --- a/server/src/ui/admin/mod.rs +++ b/server/src/ui/admin/mod.rs @@ -13,8 +13,12 @@ use super::{ use crate::{helper::A, locale::AcceptLanguage}; use anyhow::{anyhow, Context}; use jellycommon::routes::u_admin_dashboard; -use jellyimport::{asset_token::AssetInner, import_wrap, is_importing, IMPORT_ERRORS}; -use jellylogic::{session::AdminSession, Database}; +use jellyimport::{asset_token::AssetInner, import_wrap, is_importing}; +use jellylogic::{ + admin::{get_import_errors, list_invites}, + session::AdminSession, + Database, +}; use jellyui::{ admin::AdminDashboardPage, render_page, @@ -37,10 +41,10 @@ pub async fn r_admin_dashboard( lang: AcceptLanguage, ) -> MyResult<RawHtml<String>> { let AcceptLanguage(lang) = lang; - let invites = database.list_invites()?; let flash = None; - let last_import_err = IMPORT_ERRORS.read().await.to_owned(); + let invites = list_invites(&session.0, database)?; + let last_import_err = get_import_errors(&session.0).await; let busy = if is_importing() { Some("An import is currently running.") @@ -181,49 +185,3 @@ pub async fn r_admin_transcode_posters( // .await Ok(Redirect::temporary(u_admin_dashboard())) } - -// fn db_stats(_db: &Database) -> anyhow::Result<DynRender> { -// // TODO -// // let txn = db.inner.begin_read()?; -// // let stats = [ -// // ("node", txn.open_table(T_NODE)?.stats()?), -// // ("user", txn.open_table(T_USER_NODE)?.stats()?), -// // ("user-node", txn.open_table(T_USER_NODE)?.stats()?), -// // ("invite", txn.open_table(T_INVITE)?.stats()?), -// // ]; - -// // let cache_stats = db.node_index.reader.searcher().doc_store_cache_stats(); -// // let ft_total_docs = db.node_index.reader.searcher().total_num_docs()?; - -// Ok(markup::new! { -// // h3 { "Key-Value-Store Statistics" } -// // table.border { -// // tbody { -// // tr { -// // th { "table name" } -// // th { "tree height" } -// // th { "stored bytes" } -// // th { "metadata bytes" } -// // th { "fragmented bytes" } -// // th { "branch pages" } -// // th { "leaf pages" } -// // } -// // @for (name, stats) in &stats { tr { -// // td { @name } -// // td { @stats.tree_height() } -// // td { @format_size(stats.stored_bytes(), DECIMAL) } -// // td { @format_size(stats.metadata_bytes(), DECIMAL) } -// // td { @format_size(stats.fragmented_bytes(), DECIMAL) } -// // td { @stats.branch_pages() } -// // td { @stats.leaf_pages() } -// // }} -// // } -// // } -// // h3 { "Search Engine Statistics" } -// // ul { -// // li { "Total documents: " @ft_total_docs } -// // li { "Cache misses: " @cache_stats.cache_misses } -// // li { "Cache hits: " @cache_stats.cache_hits } -// // } -// }) -// } diff --git a/ui/src/admin/log.rs b/ui/src/admin/log.rs index 3669571..8404229 100644 --- a/ui/src/admin/log.rs +++ b/ui/src/admin/log.rs @@ -16,6 +16,9 @@ impl Page for ServerLogPage<'_> { fn title(&self) -> String { "Server Log".to_string() } + fn class(&self) -> Option<&'static str> { + Some("admin_log") + } fn to_render(&self) -> markup::DynRender { markup::new!(@self) } diff --git a/web/script/log_stream.ts b/web/script/log_stream.ts index 5a6a3ce..053c110 100644 --- a/web/script/log_stream.ts +++ b/web/script/log_stream.ts @@ -9,34 +9,13 @@ globalThis.addEventListener("DOMContentLoaded", () => { const log = document.getElementById("log")! const warnonly = new URL(globalThis.location.href).searchParams.get("warnonly") == "true" - const ws = new WebSocket(`/admin/log?stream&warnonly=${warnonly}`) + const ws = new WebSocket(`/admin/log?stream&warnonly=${warnonly}&html=true`) ws.onopen = () => console.log("live log connected"); ws.onclose = () => console.log("live log disconnected"); ws.onerror = e => console.log(`live log ws error: ${e}`); ws.onmessage = msg => { - const line = JSON.parse(msg.data) - - const td_time = document.createElement("td") - td_time.classList.add("time") - td_time.textContent = line.time - - const td_level = document.createElement("td") - td_level.classList.add("level") - td_level.innerHTML = line.level_html - - const td_module = document.createElement("td") - td_module.classList.add("module") - td_module.textContent = line.module - - const td_message = document.createElement("td") - td_message.innerHTML = line.message - - const tr = document.createElement("tr"); - tr.classList.add(line.level_class) - tr.append(td_time, td_level, td_module, td_message) - - log.children[0].children[0].append(tr) + log.children[0].children[0].innerHTML += msg.data while (log.children[0].children[0].children.length > 1024) log.children[0].children[0].children[0].remove() } |