This commit is contained in:
shenjack 2024-08-24 16:22:15 +08:00
parent 65e44b1024
commit c0ea480832
Signed by: shenjack
GPG Key ID: 7B1134A979775551
5 changed files with 17 additions and 6 deletions

2
Cargo.lock generated
View File

@ -2591,7 +2591,7 @@ dependencies = [
[[package]]
name = "sr_download"
version = "1.1.0"
version = "1.1.1"
dependencies = [
"anyhow",
"axum",

View File

@ -1,6 +1,6 @@
[package]
name = "sr_download"
version = "1.1.0"
version = "1.1.1"
edition = "2021"
default-run = "sr_download"

View File

@ -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(());
}

View File

@ -77,7 +77,9 @@ async fn get_last_ship(State(db): State<DatabaseConnection>) -> Json<Option<Last
Json(LastShip::from_db(&db).await)
}
pub async fn web_main(conf: ConfigFile) -> 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()

View File

@ -1,5 +1,9 @@
# v1.0
## 1.1.1
修复了 serve 模式如果在配置文件里禁用, 实际上还是会启动的问题
## 1.1.0
现在加了个 serve 模式, 可以用来提供一个 api