diff --git a/Cargo.lock b/Cargo.lock index 9247868..4532e83 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2591,7 +2591,7 @@ dependencies = [ [[package]] name = "sr_download" -version = "1.1.0" +version = "1.1.1" dependencies = [ "anyhow", "axum", diff --git a/sr_download/Cargo.toml b/sr_download/Cargo.toml index 5e6e7e9..b52064a 100644 --- a/sr_download/Cargo.toml +++ b/sr_download/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sr_download" -version = "1.1.0" +version = "1.1.1" edition = "2021" default-run = "sr_download" diff --git a/sr_download/src/main.rs b/sr_download/src/main.rs index c35d12c..f89da6c 100644 --- a/sr_download/src/main.rs +++ b/sr_download/src/main.rs @@ -87,6 +87,11 @@ async fn serve_mode(mut stop_receiver: Receiver<()>) -> anyhow::Result<()> { db_part::migrate(&db_connect).await?; let mut db_max_id = db_part::find_max_id(&db_connect).await; + let mut web_waiter = None; + if conf.serve.enable { + web_waiter = Some(tokio::spawn(serve::web_main())); + } + event!( Level::INFO, "{}", @@ -104,14 +109,14 @@ async fn serve_mode(mut stop_receiver: Receiver<()>) -> anyhow::Result<()> { // 开始等待的时间 let mut start_wait_time = tokio::time::Instant::now(); - let web_waiter = tokio::spawn(serve::web_main(conf)); - loop { if stop_receiver.try_recv().is_ok() { event!(Level::INFO, "{}", "结束下载!".yellow()); // 结束 db db_connect.close().await?; - web_waiter.abort(); + if conf.serve.enable && web_waiter.is_some() { + web_waiter.unwrap().abort(); + } return Ok(()); } diff --git a/sr_download/src/serve.rs b/sr_download/src/serve.rs index 6d9fc34..e211749 100644 --- a/sr_download/src/serve.rs +++ b/sr_download/src/serve.rs @@ -77,7 +77,9 @@ async fn get_last_ship(State(db): State) -> Json anyhow::Result<()> { +pub async fn web_main() -> anyhow::Result<()> { + let conf = crate::config::ConfigFile::try_read()?; + let listener = tokio::net::TcpListener::bind(conf.serve.host_with_port.clone()).await?; let db = db_part::connect_server(&conf).await?; let app = Router::new() diff --git a/update.md b/update.md index 9225fdf..ec7c80b 100644 --- a/update.md +++ b/update.md @@ -1,5 +1,9 @@ # v1.0 +## 1.1.1 + +修复了 serve 模式如果在配置文件里禁用, 实际上还是会启动的问题 + ## 1.1.0 现在加了个 serve 模式, 可以用来提供一个 api