mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-06-28 22:57:05 +08:00
Use i64 for retry count
This commit is contained in:
@@ -507,7 +507,7 @@ impl<T: Write + Seek + Send + Sync + ClearFile + GetTargetFileName + 'static> Do
|
||||
self.disable_progress_bar();
|
||||
}
|
||||
match helper.retry() {
|
||||
Some(u) => self.set_max_retry_count(u as i64),
|
||||
Some(u) => self.set_max_retry_count(u),
|
||||
None => {}
|
||||
}
|
||||
self.set_retry_interval(helper.retry_interval());
|
||||
@@ -593,11 +593,13 @@ async fn test_failed_downloader() {
|
||||
.aget_retry_interval_as_mut()
|
||||
.await
|
||||
.replace(retry_interval.clone());
|
||||
client.set_retry(1);
|
||||
let downloader =
|
||||
Downloader::<LocalFile>::new2(client, url, None, Some(&pb), Some(true)).unwrap();
|
||||
match downloader {
|
||||
DownloaderResult::Ok(v) => {
|
||||
v.set_retry_interval(retry_interval);
|
||||
v.set_max_retry_count(1);
|
||||
assert_eq!(v.is_created(), true);
|
||||
v.disable_progress_bar();
|
||||
v.download();
|
||||
|
||||
@@ -85,13 +85,13 @@ impl OptHelper {
|
||||
}
|
||||
|
||||
/// Return retry count
|
||||
pub fn retry(&self) -> Option<u64> {
|
||||
pub fn retry(&self) -> Option<i64> {
|
||||
if self.opt.get_ref().retry.is_some() {
|
||||
return Some(self.opt.get_ref().retry.unwrap());
|
||||
}
|
||||
let re = self.settings.get_ref().get("retry");
|
||||
if re.is_some() {
|
||||
return Some(re.unwrap().as_u64().unwrap());
|
||||
return Some(re.unwrap().as_i64().unwrap());
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ pub struct CommandOpts {
|
||||
/// Whether to overwrite file
|
||||
pub overwrite: Option<bool>,
|
||||
/// Max retry count.
|
||||
pub retry: Option<u64>,
|
||||
pub retry: Option<i64>,
|
||||
/// Retry interval
|
||||
pub retry_interval: Option<NonTailList<Duration>>,
|
||||
/// Use data from webpage first
|
||||
@@ -335,7 +335,7 @@ pub fn parse_cmd() -> Option<CommandOpts> {
|
||||
if result.opt_present("retry") {
|
||||
let s = result.opt_str("retry").unwrap();
|
||||
let s = s.trim();
|
||||
let c = s.parse::<u64>();
|
||||
let c = s.parse::<i64>();
|
||||
if c.is_err() {
|
||||
println!(
|
||||
"{} {}",
|
||||
|
||||
@@ -12,7 +12,7 @@ pub fn get_settings_list() -> Vec<SettingDes> {
|
||||
SettingDes::new("refresh_tokens", gettext("Pixiv's refresh tokens. Used to login."), JsonValueType::Str, None).unwrap(),
|
||||
SettingDes::new("cookies", gettext("The location of cookies file. Used for web API."), JsonValueType::Str, None).unwrap(),
|
||||
SettingDes::new("language", gettext("The language of translated tags."), JsonValueType::Str, None).unwrap(),
|
||||
SettingDes::new("retry", gettext("Max retry count if request failed."), JsonValueType::Number, Some(check_u64)).unwrap(),
|
||||
SettingDes::new("retry", gettext("Max retry count if request failed."), JsonValueType::Number, Some(check_i64)).unwrap(),
|
||||
SettingDes::new("retry-interval", gettext("The interval (in seconds) between two retries."), JsonValueType::Multiple, Some(check_retry_interval)).unwrap(),
|
||||
SettingDes::new("use-webpage", gettext("Use data from webpage first."), JsonValueType::Boolean, None).unwrap(),
|
||||
SettingDes::new("author-name-filters", gettext("Remove the part which after these parttens."), JsonValueType::Array, Some(check_author_name_filters)).unwrap(),
|
||||
@@ -24,8 +24,8 @@ pub fn get_settings_list() -> Vec<SettingDes> {
|
||||
]
|
||||
}
|
||||
|
||||
fn check_u64(obj: &JsonValue) -> bool {
|
||||
let r = obj.as_u64();
|
||||
fn check_i64(obj: &JsonValue) -> bool {
|
||||
let r = obj.as_i64();
|
||||
r.is_some()
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::atomic::AtomicU64;
|
||||
use std::sync::atomic::AtomicI64;
|
||||
use std::sync::Arc;
|
||||
use std::sync::RwLock;
|
||||
use std::sync::RwLockReadGuard;
|
||||
@@ -94,8 +94,8 @@ pub struct WebClient {
|
||||
cookies: RwLock<CookieJar>,
|
||||
/// Verbose logging
|
||||
verbose: Arc<AtomicBool>,
|
||||
/// Retry times, 0 means disable
|
||||
retry: Arc<AtomicU64>,
|
||||
/// Retry times, 0 means disable, < 0 means always retry
|
||||
retry: Arc<AtomicI64>,
|
||||
/// Retry interval
|
||||
retry_interval: RwLock<Option<NonTailList<Duration>>>,
|
||||
}
|
||||
@@ -110,7 +110,7 @@ impl WebClient {
|
||||
headers: RwLock::new(HashMap::new()),
|
||||
cookies: RwLock::new(CookieJar::new()),
|
||||
verbose: Arc::new(AtomicBool::new(false)),
|
||||
retry: Arc::new(AtomicU64::new(3)),
|
||||
retry: Arc::new(AtomicI64::new(3)),
|
||||
retry_interval: RwLock::new(None),
|
||||
}
|
||||
}
|
||||
@@ -186,7 +186,7 @@ impl WebClient {
|
||||
}
|
||||
|
||||
/// return retry times, 0 means disable
|
||||
pub fn get_retry(&self) -> u64 {
|
||||
pub fn get_retry(&self) -> i64 {
|
||||
self.retry.qload()
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ impl WebClient {
|
||||
}
|
||||
|
||||
/// Set retry times, 0 means disable
|
||||
pub fn set_retry(&self, retry: u64) {
|
||||
pub fn set_retry(&self, retry: i64) {
|
||||
self.retry.qstore(retry)
|
||||
}
|
||||
|
||||
@@ -391,15 +391,15 @@ impl WebClient {
|
||||
url: U,
|
||||
headers: H,
|
||||
) -> Option<Response> {
|
||||
let mut count = 0u64;
|
||||
let mut count = 0i64;
|
||||
let retry = self.get_retry();
|
||||
while count <= retry {
|
||||
while retry < 0 || count <= retry {
|
||||
let r = self._aget2(url.clone(), headers.clone()).await;
|
||||
if r.is_some() {
|
||||
return r;
|
||||
}
|
||||
count += 1;
|
||||
if count <= retry {
|
||||
if retry < 0 || count <= retry {
|
||||
let t =
|
||||
self.get_retry_interval().as_ref().unwrap()[(count - 1).try_into().unwrap()];
|
||||
if !t.is_zero() {
|
||||
|
||||
Reference in New Issue
Block a user