Skip to content

Commit

Permalink
Split up librqbit http_api and tracing_subscriber into separate featu…
Browse files Browse the repository at this point in the history
…res (#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
  • Loading branch information
ikatson authored Aug 15, 2024
1 parent 3355415 commit 37ee8b7
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 36 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ jobs:
- run: rustup override set ${{ matrix.rust_version }}
- name: cargo check
run: cargo check
check-desktop:
runs-on: windows-latest
steps:
- name: rustup toolchain install 1.75
run: |
rustup toolchain install 1.75
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- run: rustup override set 1.75
- name: cargo check desktop
working-directory: desktop/src-tauri
run: cargo check
test:
runs-on: windows-latest
steps:
Expand Down
11 changes: 4 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions crates/librqbit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions crates/librqbit/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
15 changes: 11 additions & 4 deletions crates/librqbit/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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>;
Expand All @@ -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>,
}

Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -258,6 +264,7 @@ impl Api {
Ok(Default::default())
}

#[cfg(feature = "tracing-subscriber-utils")]
pub fn api_log_lines_stream(
&self,
) -> Result<
Expand Down
2 changes: 2 additions & 0 deletions crates/librqbit/src/api_error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "http-api")]
use axum::response::{IntoResponse, Response};
use http::StatusCode;
use serde::{Serialize, Serializer};
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion crates/librqbit/src/http_api.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -459,6 +459,8 @@ impl HttpApi {

#[cfg(feature = "webui")]
{
use axum::response::Redirect;

let webui_router = Router::new()
.route(
"/",
Expand Down
3 changes: 3 additions & 0 deletions crates/librqbit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
7 changes: 5 additions & 2 deletions crates/rqbit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions desktop/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ tauri-build = { version = "1.5", features = [] }
tauri = { version = "1.6.7", features = ["shell-open"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
librqbit = { path = "../../crates/librqbit", features = ["webui"] }
librqbit = { path = "../../crates/librqbit", features = [
"tracing-subscriber-utils",
"http-api",
"webui",
] }
tokio = { version = "1.34.0", features = ["rt-multi-thread"] }
anyhow = "1.0.75"
base64 = "0.21.5"
Expand Down
18 changes: 9 additions & 9 deletions desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use config::RqbitDesktopConfig;
use http::StatusCode;
use librqbit::{
api::{
ApiAddTorrentResponse, EmptyJsonResponse, TorrentDetailsResponse, TorrentListResponse,
TorrentStats,
ApiAddTorrentResponse, EmptyJsonResponse, TorrentDetailsResponse, TorrentIdOrHash,
TorrentListResponse, TorrentStats,
},
dht::PersistentDhtConfig,
tracing_subscriber_config_utils::{init_logging, InitLoggingOptions, InitLoggingResult},
Expand Down Expand Up @@ -261,55 +261,55 @@ async fn torrent_create_from_base64_file(
#[tauri::command]
async fn torrent_details(
state: tauri::State<'_, State>,
id: usize,
id: TorrentIdOrHash,
) -> Result<TorrentDetailsResponse, ApiError> {
state.api()?.api_torrent_details(id)
}

#[tauri::command]
async fn torrent_stats(
state: tauri::State<'_, State>,
id: usize,
id: TorrentIdOrHash,
) -> Result<TorrentStats, ApiError> {
state.api()?.api_stats_v1(id)
}

#[tauri::command]
async fn torrent_action_delete(
state: tauri::State<'_, State>,
id: usize,
id: TorrentIdOrHash,
) -> Result<EmptyJsonResponse, ApiError> {
state.api()?.api_torrent_action_delete(id).await
}

#[tauri::command]
async fn torrent_action_pause(
state: tauri::State<'_, State>,
id: usize,
id: TorrentIdOrHash,
) -> Result<EmptyJsonResponse, ApiError> {
state.api()?.api_torrent_action_pause(id).await
}

#[tauri::command]
async fn torrent_action_forget(
state: tauri::State<'_, State>,
id: usize,
id: TorrentIdOrHash,
) -> Result<EmptyJsonResponse, ApiError> {
state.api()?.api_torrent_action_forget(id).await
}

#[tauri::command]
async fn torrent_action_start(
state: tauri::State<'_, State>,
id: usize,
id: TorrentIdOrHash,
) -> Result<EmptyJsonResponse, ApiError> {
state.api()?.api_torrent_action_start(id).await
}

#[tauri::command]
async fn torrent_action_configure(
state: tauri::State<'_, State>,
id: usize,
id: TorrentIdOrHash,
only_files: Vec<usize>,
) -> Result<EmptyJsonResponse, ApiError> {
state
Expand Down

0 comments on commit 37ee8b7

Please sign in to comment.