mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-02-13 02:42:45 +00:00
feat: display download progress
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -10,7 +10,8 @@ const AnonymizedRepositorySchema = new Schema({
|
||||
type: String,
|
||||
default: "preparing",
|
||||
},
|
||||
errorMessage: String,
|
||||
statusDate: Date,
|
||||
statusMessage: String,
|
||||
anonymizeDate: Date,
|
||||
lastView: Date,
|
||||
pageView: Number,
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user