watching basic version works

This commit is contained in:
Igor Katson 2024-09-13 12:34:51 +01:00
parent 624b41a297
commit 06613d9ef1
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
8 changed files with 284 additions and 10 deletions

View file

@ -27,6 +27,7 @@ librqbit = { version = "7.1.0-beta.0", path = "../librqbit", default-features =
"http-api",
"tracing-subscriber-utils",
"upnp-serve-adapter",
"watch",
] }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
console-subscriber = { version = "0.4", optional = true }

View file

@ -1,4 +1,11 @@
use std::{io, net::SocketAddr, path::PathBuf, sync::Arc, thread, time::Duration};
use std::{
io,
net::SocketAddr,
path::{Path, PathBuf},
sync::Arc,
thread,
time::Duration,
};
use anyhow::{bail, Context};
use clap::{CommandFactory, Parser, ValueEnum};
@ -236,6 +243,11 @@ struct ServerStartOptions {
/// [Experimental] if set, will try to resume quickly after restart and skip checksumming.
#[arg(long = "fastresume", env = "RQBIT_FASTRESUME")]
fastresume: bool,
/// The folder to watch for added .torrent files. All files in this folder will be automatically added
/// to the session.
#[arg(long = "watch-folder", env = "RQBIT_WATCH_FOLDER")]
watch_folder: Option<String>,
}
#[derive(Parser)]
@ -580,7 +592,7 @@ async fn async_main(opts: Opts, cancel: CancellationToken) -> anyhow::Result<()>
};
let api = Api::new(
session,
session.clone(),
Some(log_config.rust_log_reload_tx),
Some(log_config.line_broadcast),
);
@ -595,6 +607,10 @@ async fn async_main(opts: Opts, cancel: CancellationToken) -> anyhow::Result<()>
let upnp_router = upnp_server.as_mut().and_then(|s| s.take_router().ok());
let http_api_fut = http_api.make_http_api_and_run(tcp_listener, upnp_router);
if let Some(watch_folder) = start_opts.watch_folder.as_ref() {
session.watch_folder(Path::new(watch_folder));
}
let res = match upnp_server {
Some(srv) => {
let upnp_fut = srv.run_ssdp_forever();
@ -609,7 +625,6 @@ async fn async_main(opts: Opts, cancel: CancellationToken) -> anyhow::Result<()>
r = http_api_fut => r,
},
};
res.context("error running server")
}
},