mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-07-08 01:32:41 +08:00
Update
This commit is contained in:
@@ -27,6 +27,12 @@ impl PdFileStatus {
|
||||
pub fn is_downloading(&self) -> bool {
|
||||
*self == PdFileStatus::Downloading
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Returns true if the download is started.
|
||||
pub fn is_started(&self) -> bool {
|
||||
*self == PdFileStatus::Started
|
||||
}
|
||||
}
|
||||
|
||||
/// The type of the downloader.
|
||||
|
||||
@@ -224,6 +224,12 @@ impl PdFile {
|
||||
self.status.get_ref().is_downloading()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Returns true if the download is started.
|
||||
pub fn is_started(&self) -> bool {
|
||||
self.status.get_ref().is_started()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Returns true if stored in memory only.
|
||||
fn is_mem_only(&self) -> bool {
|
||||
|
||||
@@ -142,6 +142,25 @@ pub async fn create_download_tasks_simple<
|
||||
handle_download(d, result).await
|
||||
}
|
||||
|
||||
/// Do first job when download in multiple mode.
|
||||
pub async fn create_download_tasks_multi_first<
|
||||
T: Seek + Write + Send + Sync + ClearFile + GetTargetFileName,
|
||||
>(
|
||||
d: Arc<DownloaderInternal<T>>,
|
||||
) -> Result<(), DownloaderError> {
|
||||
let result = d
|
||||
.client
|
||||
.get(d.url.deref().clone(), d.headers.as_ref().clone())
|
||||
.await
|
||||
.try_err(gettext("Failed to get url."))?;
|
||||
let status = result.status();
|
||||
if status.as_u16() >= 400 {
|
||||
return Err(DownloaderError::from(status));
|
||||
}
|
||||
// # TODO
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handle download process
|
||||
pub async fn handle_download<T: Seek + Write + Send + Sync + ClearFile + GetTargetFileName>(
|
||||
d: Arc<DownloaderInternal<T>>,
|
||||
@@ -224,6 +243,11 @@ pub async fn check_tasks<
|
||||
if !d.is_multi_threads() {
|
||||
let task = tokio::spawn(create_download_tasks_simple(Arc::clone(&d)));
|
||||
d.add_task(task);
|
||||
} else {
|
||||
if d.pd.is_started() {
|
||||
let task = tokio::spawn(create_download_tasks_multi_first(Arc::clone(&d)));
|
||||
d.add_task(task);
|
||||
}
|
||||
}
|
||||
loop {
|
||||
check_dropped!(d);
|
||||
|
||||
Reference in New Issue
Block a user