|
|
|
@ -14,7 +14,6 @@ mod tasklist;
|
|
|
|
|
#[macro_use]
|
|
|
|
|
mod progress;
|
|
|
|
|
|
|
|
|
|
//TODO: Create a progress task module for atomically printing infos and stuff
|
|
|
|
|
//TODO: Create a module for temp files, pass the temp file to `perform` and do the regex fixing after `perform`
|
|
|
|
|
|
|
|
|
|
/// Download a loli async
|
|
|
|
@ -24,7 +23,8 @@ pub async fn perform(url: impl AsRef<str>, path: impl AsRef<Path>, mut progress:
|
|
|
|
|
let path = path.as_ref();
|
|
|
|
|
|
|
|
|
|
let task = url.to_owned(); //TODO: Real task name
|
|
|
|
|
progress.push_task(&task).await;
|
|
|
|
|
|
|
|
|
|
prog_send!(link progress.push_task(&task));
|
|
|
|
|
|
|
|
|
|
let mut resp = reqwest::get(url).await?;
|
|
|
|
|
let len = resp.content_length();
|
|
|
|
@ -34,19 +34,22 @@ pub async fn perform(url: impl AsRef<str>, path: impl AsRef<Path>, mut progress:
|
|
|
|
|
.create(true)
|
|
|
|
|
.truncate(true)
|
|
|
|
|
.write(true)
|
|
|
|
|
.read(true)
|
|
|
|
|
.open(path).await?;
|
|
|
|
|
|
|
|
|
|
progress.println(format!("req ok {:?}, file ok ({:?}), starting download", len, path)).await;
|
|
|
|
|
prog_send!(progress.println(format!("req ok {:?}, file ok ({:?}), starting download", len, path)));
|
|
|
|
|
let mut bytes = resp.bytes_stream();
|
|
|
|
|
while let Some(buffer) = bytes.next().await {
|
|
|
|
|
file.write(buffer?.as_ref()).await?;
|
|
|
|
|
progress.bump().await;
|
|
|
|
|
prog_send!(progress.bump());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
progress.println(format!("done for {}", url)).await;
|
|
|
|
|
progress.bump().await;
|
|
|
|
|
//TODO: Decode `file`.
|
|
|
|
|
|
|
|
|
|
prog_send!(progress.println(format!("done for {}", url)));
|
|
|
|
|
prog_send!(progress.bump());
|
|
|
|
|
|
|
|
|
|
progress.pop_task(task).await;
|
|
|
|
|
prog_send!(progress.pop_task(task));
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
@ -83,7 +86,7 @@ pub async fn work(conf: config::Config) -> Result<(), Box<dyn std::error::Error>
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prog_writer.println("Waiting for children...").await;
|
|
|
|
|
prog_send!(link prog_writer.println("Waiting for children..."));
|
|
|
|
|
for child in children.into_iter()
|
|
|
|
|
{
|
|
|
|
|
match child.await {
|
|
|
|
@ -95,7 +98,7 @@ pub async fn work(conf: config::Config) -> Result<(), Box<dyn std::error::Error>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prog_send!(try link prog_writer.kill());
|
|
|
|
|
prog.await.expect("fatal");
|
|
|
|
|
prog.await.expect("mpsc fatal");
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|