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

View File

@@ -10,7 +10,7 @@
<a href="/faq">FAQ</a> for more information.
</p>
<div class="progress" style="height: 25px;">
<div class="progress" style="height: 25px">
<div
class="progress-bar"
role="progressbar"
@@ -19,7 +19,13 @@
aria-valuemin="0"
aria-valuemax="100"
>
{{repo.status | title}}
<span>
{{repo.status | title}}
<span
ng-if="repo.status == 'download' && repo.statusMessage"
ng-bind="repo.statusMessage | humanFileSize"
></span>
</span>
</div>
</div>

View File

@@ -202,9 +202,10 @@ export default class Repository {
* @param status the new status
* @param errorMessage a potential error message to display
*/
async updateStatus(status: RepositoryStatus, errorMessage?: string) {
async updateStatus(status: RepositoryStatus, statusMessage?: string) {
this._model.status = status;
this._model.errorMessage = errorMessage;
this._model.statusDate = new Date();
this._model.statusMessage = statusMessage;
return this._model.save();
}
@@ -323,7 +324,8 @@ export default class Repository {
options: this._model.options,
conference: this._model.conference,
anonymizeDate: this._model.anonymizeDate,
status: this._model.status,
status: this.status,
statusMessage: this._model.statusMessage,
source: this.source.toJSON(),
lastView: this._model.lastView,
pageView: this._model.pageView,

View File

@@ -10,7 +10,8 @@ const AnonymizedRepositorySchema = new Schema({
type: String,
default: "preparing",
},
errorMessage: String,
statusDate: Date,
statusMessage: String,
anonymizeDate: Date,
lastView: Date,
pageView: Number,

View File

@@ -4,7 +4,8 @@ import { RepositoryStatus, Tree } from "../../types";
export interface IAnonymizedRepository {
repoId: string;
status?: RepositoryStatus;
errorMessage?: string;
statusMessage?: string;
statusDate: Date;
anonymizeDate: Date;
source: {
type: "GitHubDownload" | "GitHubStream" | "Zip";

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");
}