From 8cd4a998a8759f7b5928f0501b9e05686fa4f354 Mon Sep 17 00:00:00 2001 From: spinline Date: Fri, 6 Feb 2026 00:12:02 +0300 Subject: [PATCH] fix: Make push notifications optional for MIPS compatibility - Add push-notifications feature flag (enabled by default) - Make web-push and openssl optional dependencies - Conditionally compile push notification code - Disable push notifications for MIPS builds in CI - Fixes AtomicU64 error on 32-bit MIPS architecture - x86_64/ARM builds still have full push notification support --- .github/workflows/build-mips.yml | 2 +- .vscode/settings.json | 5 ++++ backend/Cargo.toml | 8 +++-- backend/src/handlers/mod.rs | 6 +++- backend/src/main.rs | 50 ++++++++++++++++++++++++++++++-- 5 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.github/workflows/build-mips.yml b/.github/workflows/build-mips.yml index 4f1deb3..429be75 100644 --- a/.github/workflows/build-mips.yml +++ b/.github/workflows/build-mips.yml @@ -55,7 +55,7 @@ jobs: CROSS_NO_WARNINGS: 0 run: | cd backend - cross build --target mips-unknown-linux-musl --release -Z build-std=std,panic_abort + cross build --target mips-unknown-linux-musl --release --no-default-features -Z build-std=std,panic_abort - name: Debug - List Files run: | diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..980e2a3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "chat.tools.terminal.autoApprove": { + "cargo check": true + } +} \ No newline at end of file diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 768d4b1..9c4193f 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -3,6 +3,10 @@ name = "backend" version = "0.1.0" edition = "2021" +[features] +default = ["push-notifications"] +push-notifications = ["web-push", "openssl"] + [dependencies] axum = { version = "0.8", features = ["macros", "ws"] } tokio = { version = "1", features = ["full"] } @@ -26,6 +30,6 @@ thiserror = "2.0.18" dotenvy = "0.15.7" utoipa = { version = "5.4.0", features = ["axum_extras"] } utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] } -web-push = "0.10" +web-push = { version = "0.10", optional = true } base64 = "0.22" -openssl = { version = "0.10", features = ["vendored"] } +openssl = { version = "0.10", features = ["vendored"], optional = true } diff --git a/backend/src/handlers/mod.rs b/backend/src/handlers/mod.rs index 9f46ab7..93217d5 100644 --- a/backend/src/handlers/mod.rs +++ b/backend/src/handlers/mod.rs @@ -1,8 +1,9 @@ use crate::{ - push, xmlrpc::{self, RpcParam}, AppState, }; +#[cfg(feature = "push-notifications")] +use crate::push; use axum::{ extract::{Json, Path, State}, http::{header, StatusCode, Uri}, @@ -677,6 +678,7 @@ pub async fn handle_timeout_error(err: BoxError) -> (StatusCode, &'static str) { // --- PUSH NOTIFICATION HANDLERS --- +#[cfg(feature = "push-notifications")] /// Get VAPID public key for push subscription #[utoipa::path( get, @@ -690,6 +692,8 @@ pub async fn get_push_public_key_handler() -> impl IntoResponse { (StatusCode::OK, Json(serde_json::json!({ "publicKey": public_key }))).into_response() } + +#[cfg(feature = "push-notifications")] /// Subscribe to push notifications #[utoipa::path( post, diff --git a/backend/src/main.rs b/backend/src/main.rs index a66d711..7f9876e 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -1,5 +1,6 @@ mod diff; mod handlers; +#[cfg(feature = "push-notifications")] mod push; mod scgi; mod sse; @@ -31,6 +32,7 @@ pub struct AppState { pub tx: Arc>>, pub event_bus: broadcast::Sender, pub scgi_socket_path: String, + #[cfg(feature = "push-notifications")] pub push_store: push::PushSubscriptionStore, } @@ -51,6 +53,7 @@ struct Args { port: u16, } +#[cfg(feature = "push-notifications")] #[derive(OpenApi)] #[openapi( paths( @@ -89,6 +92,41 @@ struct Args { )] struct ApiDoc; +#[cfg(not(feature = "push-notifications"))] +#[derive(OpenApi)] +#[openapi( + paths( + handlers::add_torrent_handler, + handlers::handle_torrent_action, + handlers::get_version_handler, + handlers::get_files_handler, + handlers::get_peers_handler, + handlers::get_trackers_handler, + handlers::set_file_priority_handler, + handlers::set_label_handler, + handlers::get_global_limit_handler, + handlers::set_global_limit_handler + ), + components( + schemas( + handlers::AddTorrentRequest, + shared::TorrentActionRequest, + shared::Torrent, + shared::TorrentStatus, + shared::TorrentFile, + shared::TorrentPeer, + shared::TorrentTracker, + shared::SetFilePriorityRequest, + shared::SetLabelRequest, + shared::GlobalLimitRequest + ) + ), + tags( + (name = "vibetorrent", description = "VibeTorrent API") + ) +)] +struct ApiDoc; + #[tokio::main] async fn main() { // Load .env file @@ -143,6 +181,7 @@ async fn main() { tx: tx.clone(), event_bus: event_bus.clone(), scgi_socket_path: args.socket.clone(), + #[cfg(feature = "push-notifications")] push_store: push::PushSubscriptionStore::new(), }; @@ -150,6 +189,7 @@ async fn main() { let tx_clone = tx.clone(); let event_bus_tx = event_bus.clone(); let socket_path = args.socket.clone(); // Clone for background task + #[cfg(feature = "push-notifications")] let push_store_clone = app_state.push_store.clone(); tokio::spawn(async move { @@ -202,6 +242,7 @@ async fn main() { diff::DiffResult::Partial(updates) => { for update in updates { // Check if this is a torrent completion notification + #[cfg(feature = "push-notifications")] if let AppEvent::Notification(ref notif) = update { if notif.message.contains("tamamlandı") { // Send push notification in background @@ -295,9 +336,14 @@ async fn main() { "/api/settings/global-limits", get(handlers::get_global_limit_handler).post(handlers::set_global_limit_handler), ) + .fallback(handlers::static_handler); // Serve static files for everything else + + #[cfg(feature = "push-notifications")] + let app = app .route("/api/push/public-key", get(handlers::get_push_public_key_handler)) - .route("/api/push/subscribe", post(handlers::subscribe_push_handler)) - .fallback(handlers::static_handler) // Serve static files for everything else + .route("/api/push/subscribe", post(handlers::subscribe_push_handler)); + + let app = app .layer(TraceLayer::new_for_http()) .layer( CompressionLayer::new()