Split up librqbit http_api and tracing_subscriber into separate features (#188)

* fix lints that were under features

* Split up some features and fix desktop

* fix github script

* fix github script

* fix github script

* try caching check-desktop
This commit is contained in:
Igor Katson 2024-08-15 18:54:59 +01:00 committed by GitHub
parent 33554159bf
commit 37ee8b70ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 65 additions and 36 deletions

View file

@ -13,12 +13,14 @@ readme = "README.md"
[features]
default = ["default-tls"]
http-api = ["axum", "tower-http"]
webui = []
timed_existence = []
default-tls = ["reqwest/default-tls"]
rust-tls = ["reqwest/rustls-tls"]
storage_middleware = ["lru"]
storage_examples = []
tracing-subscriber-utils = ["tracing-subscriber"]
postgres = ["sqlx"]
[dependencies]
@ -42,8 +44,8 @@ tokio = { version = "1", features = [
"fs",
"io-util",
] }
axum = { version = "0.7.4" }
tower-http = { version = "0.5", features = ["cors", "trace"] }
axum = { version = "0.7.4", optional = true }
tower-http = { version = "0.5", features = ["cors", "trace"], optional = true }
tokio-stream = "0.1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
@ -64,15 +66,11 @@ parking_lot = "0.12"
tracing = "0.1.40"
size_format = "1"
rand = "0.8"
openssl = { version = "0.10", optional = true }
crypto-hash = { version = "0.3", optional = true }
sha1 = { version = "0.10", optional = true }
tracing-subscriber = { version = "0.3", default-features = false, features = [
"json",
"fmt",
"env-filter",
] }
], optional = true }
uuid = { version = "1.2", features = ["v4"] }
futures = "0.3"
url = "2"

View file

@ -2,6 +2,7 @@ use anyhow::{bail, Context};
use std::path::Path;
use std::process::Command;
#[allow(dead_code)]
fn run_cmd(cwd: &Path, cmd: &str) -> anyhow::Result<()> {
#[cfg(target_os = "windows")]
let (shell, shell_args) = ("powershell", ["-command"].as_slice());

View file

@ -3,12 +3,10 @@ use std::{collections::HashSet, marker::PhantomData, net::SocketAddr, str::FromS
use anyhow::Context;
use buffers::ByteBufOwned;
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::{
@ -20,9 +18,15 @@ use crate::{
peer::stats::snapshot::{PeerStatsFilter, PeerStatsSnapshot},
FileStream, ManagedTorrentHandle,
},
tracing_subscriber_config_utils::LineBroadcast,
};
#[cfg(feature = "tracing-subscriber-utils")]
use crate::tracing_subscriber_config_utils::LineBroadcast;
#[cfg(feature = "tracing-subscriber-utils")]
use futures::Stream;
#[cfg(feature = "tracing-subscriber-utils")]
use tokio_stream::wrappers::{errors::BroadcastStreamRecvError, BroadcastStream};
pub use crate::torrent_state::stats::{LiveStats, TorrentStats};
pub type Result<T> = std::result::Result<T, ApiError>;
@ -33,6 +37,7 @@ pub type Result<T> = std::result::Result<T, ApiError>;
pub struct Api {
session: Arc<Session>,
rust_log_reload_tx: Option<UnboundedSender<String>>,
#[cfg(feature = "tracing-subscriber-utils")]
line_broadcast: Option<LineBroadcast>,
}
@ -127,11 +132,12 @@ impl Api {
pub fn new(
session: Arc<Session>,
rust_log_reload_tx: Option<UnboundedSender<String>>,
line_broadcast: Option<LineBroadcast>,
#[cfg(feature = "tracing-subscriber-utils")] line_broadcast: Option<LineBroadcast>,
) -> Self {
Self {
session,
rust_log_reload_tx,
#[cfg(feature = "tracing-subscriber-utils")]
line_broadcast,
}
}
@ -258,6 +264,7 @@ impl Api {
Ok(Default::default())
}
#[cfg(feature = "tracing-subscriber-utils")]
pub fn api_log_lines_stream(
&self,
) -> Result<

View file

@ -1,3 +1,4 @@
#[cfg(feature = "http-api")]
use axum::response::{IntoResponse, Response};
use http::StatusCode;
use serde::{Serialize, Serializer};
@ -147,6 +148,7 @@ impl std::fmt::Display for ApiError {
}
}
#[cfg(feature = "http-api")]
impl IntoResponse for ApiError {
fn into_response(self) -> Response {
let mut response = axum::Json(&self).into_response();

View file

@ -1,7 +1,7 @@
use anyhow::Context;
use axum::body::Bytes;
use axum::extract::{Path, Query, State};
use axum::response::{IntoResponse, Redirect};
use axum::response::IntoResponse;
use axum::routing::{get, post};
use futures::future::BoxFuture;
use futures::{FutureExt, TryStreamExt};
@ -459,6 +459,8 @@ impl HttpApi {
#[cfg(feature = "webui")]
{
use axum::response::Redirect;
let webui_router = Router::new()
.route(
"/",

View file

@ -32,7 +32,9 @@ mod create_torrent_file;
mod dht_utils;
pub mod file_info;
mod file_ops;
#[cfg(feature = "http-api")]
pub mod http_api;
#[cfg(feature = "http-api")]
pub mod http_api_client;
mod merge_streams;
mod peer_connection;
@ -44,6 +46,7 @@ mod spawn_utils;
pub mod storage;
mod stream_connect;
mod torrent_state;
#[cfg(feature = "tracing-subscriber-utils")]
pub mod tracing_subscriber_config_utils;
mod type_aliases;

View file

@ -12,7 +12,7 @@ readme = "README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["default-tls", "webui", "postgres"]
default = ["default-tls", "postgres", "webui"]
openssl-vendored = ["openssl/vendored"]
tokio-console = ["console-subscriber", "tokio/tracing"]
webui = ["librqbit/webui"]
@ -23,7 +23,10 @@ debug_slow_disk = ["librqbit/storage_middleware"]
postgres = ["librqbit/postgres"]
[dependencies]
librqbit = { path = "../librqbit", default-features = false, version = "7.0.0-beta.0" }
librqbit = { path = "../librqbit", default-features = false, features = [
"http-api",
"tracing-subscriber-utils",
], version = "7.0.0-beta.0" }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
console-subscriber = { version = "0.2", optional = true }
anyhow = "1"