From 69e8f99da60aef50ed3d94201cedb97a50f97a63 Mon Sep 17 00:00:00 2001 From: spinline Date: Fri, 30 Jan 2026 00:54:08 +0300 Subject: [PATCH] fix: Restore missing handler in main.rs --- backend/src/main.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/backend/src/main.rs b/backend/src/main.rs index 366652e..3f81b20 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -71,7 +71,32 @@ use tokio::sync::watch; use std::sync::Arc; use std::time::Duration; -/* ... add_torrent_handler ... */ +#[derive(Deserialize)] +struct AddTorrentRequest { + uri: String, +} + +async fn add_torrent_handler( + State(state): State, + Json(payload): Json, +) -> StatusCode { + println!("Received add_torrent request. URI length: {}", payload.uri.len()); + let client = xmlrpc::RtorrentClient::new(&state.scgi_socket_path); + match client.call("load.start", &["", &payload.uri]).await { + Ok(response) => { + println!("rTorrent response to load.start: {}", response); + if response.contains("faultCode") { + eprintln!("rTorrent returned fault: {}", response); + return StatusCode::INTERNAL_SERVER_ERROR; + } + StatusCode::OK + }, + Err(e) => { + eprintln!("Failed to add torrent: {}", e); + StatusCode::INTERNAL_SERVER_ERROR + } + } +} #[tokio::main] async fn main() {