feat: display download progress

This commit is contained in:
tdurieux
2021-09-07 12:10:25 +02:00
parent 1808fe5b2e
commit 7a44a42331
5 changed files with 39 additions and 8 deletions
+22 -1
View File
@@ -60,7 +60,28 @@ export default class GitHubDownload extends GitHubBase implements SourceBase {
await this.repository.updateStatus("download");
const originalPath = this.repository.originalCachePath;
await storage.mk(originalPath);
await storage.extractTar(originalPath, got.stream(response.url));
let progress = null;
let progressInterval = setInterval(async () => {
if (progress) {
await this.repository.updateStatus(
this.repository.status,
progress.transferred
);
}
}, 1000);
await storage.extractTar(
originalPath,
got
.stream(response.url)
.on("downloadProgress", async (p) => {
console.log(p);
progress = p;
})
.on("error", () => clearInterval(progressInterval))
.on("end", () => clearInterval(progressInterval))
.on("close", () => clearInterval(progressInterval))
);
clearInterval(progressInterval);
await this.repository.updateStatus("ready");
}