Desktop: button to show a modal with logs (#48)

* Add an endpoint to stream logs /stream_logs
* Display logs in desktop app
* UI component to stream logs
This commit is contained in:
Igor Katson 2023-12-08 19:47:48 +00:00 committed by GitHub
parent f7345ae6df
commit 9385524a1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 521 additions and 125 deletions

View file

@ -3,10 +3,12 @@ use std::{net::SocketAddr, sync::Arc};
use anyhow::Context;
use buffers::ByteString;
use dht::{DhtStats, Id20};
use futures::Stream;
use http::StatusCode;
use librqbit_core::torrent_metainfo::TorrentMetaV1Info;
use serde::{Deserialize, Serialize};
use tokio::sync::mpsc::UnboundedSender;
use tokio_stream::wrappers::{errors::BroadcastStreamRecvError, BroadcastStream};
use tracing::warn;
use crate::{
@ -17,7 +19,7 @@ use crate::{
torrent_state::{
peer::stats::snapshot::{PeerStatsFilter, PeerStatsSnapshot},
ManagedTorrentHandle,
},
}, log_subscriber::LineBroadcast,
};
pub use crate::torrent_state::stats::{LiveStats, TorrentStats};
@ -30,13 +32,19 @@ pub type Result<T> = std::result::Result<T, ApiError>;
pub struct Api {
session: Arc<Session>,
rust_log_reload_tx: Option<UnboundedSender<String>>,
line_broadcast: Option<LineBroadcast>,
}
impl Api {
pub fn new(session: Arc<Session>, rust_log_reload_tx: Option<UnboundedSender<String>>) -> Self {
pub fn new(
session: Arc<Session>,
rust_log_reload_tx: Option<UnboundedSender<String>>,
line_broadcast: Option<LineBroadcast>
) -> Self {
Self {
session,
rust_log_reload_tx,
line_broadcast
}
}
@ -123,6 +131,21 @@ impl Api {
Ok(Default::default())
}
pub fn api_log_lines_stream(
&self,
) -> Result<
impl Stream<Item = std::result::Result<bytes::Bytes, BroadcastStreamRecvError>>
+ Send
+ Sync
+ 'static,
> {
Ok(self
.line_broadcast
.as_ref()
.map(|sender| BroadcastStream::new(sender.subscribe()))
.context("line_rx wasn't set")?)
}
pub async fn api_add_torrent(
&self,
add: AddTorrent<'_>,