From 56f7f3579bacc27f4a33498c37c7ec4afbeb73ce Mon Sep 17 00:00:00 2001 From: Louis <836250617@qq.com> Date: Tue, 6 Feb 2024 22:36:27 +0800 Subject: [PATCH] fix: each Ctrl-C only cancel 10 jobs(a batch); --- src/api/error.rs | 2 ++ src/api/pull.rs | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/api/error.rs b/src/api/error.rs index 2377ed0..8a953be 100644 --- a/src/api/error.rs +++ b/src/api/error.rs @@ -9,6 +9,8 @@ pub enum ApiError { LogoutFail { source: reqwest::Error, msg: String }, #[snafu(display("{}", msg))] PullFail { msg: String }, + #[snafu(display("Ctrl-C Cancelled"))] + Canclled, #[snafu(display("Create temp file fail"), context(false))] CreateTempFileFail { source: std::io::Error }, #[snafu(display("Persist temp file fail"), context(false))] diff --git a/src/api/pull.rs b/src/api/pull.rs index c808330..25e8af5 100644 --- a/src/api/pull.rs +++ b/src/api/pull.rs @@ -1,7 +1,7 @@ use super::error::MergeFail; use super::wbi::{encode_wbi, get_wbi_keys}; use super::{client, error::Result, parse_message}; -use crate::api::error::PullFail; +use crate::api::error::{ApiError, Canclled, PullFail}; use crate::cli::utils::download_bar; use crate::config::config; use crate::proto::data::{Dash, Meta, Qn, VideoMeta}; @@ -62,6 +62,10 @@ async fn try_pull(videos: Vec<*mut VideoMeta>) { (**v).saved = true; } } + Err(ApiError::Canclled) => { + warn!("Pulling is canclled"); + return; + } Err(e) => warn!("{}", e), } } @@ -147,9 +151,7 @@ async fn download(title: &str, v_url: &str, a_url: &str) -> Result<()> { _ = tokio::signal::ctrl_c() => { file_v.into_inner().unwrap().close()?; file_a.into_inner().unwrap().close()?; - return PullFail { - msg: "Download Cancelled; Ctrl-C", - }.fail(); + return Canclled.fail(); } }