mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-08-15 00:10:44 +02:00
feat: display download progress
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
<a href="/faq">FAQ</a> for more information.
|
<a href="/faq">FAQ</a> for more information.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="progress" style="height: 25px;">
|
<div class="progress" style="height: 25px">
|
||||||
<div
|
<div
|
||||||
class="progress-bar"
|
class="progress-bar"
|
||||||
role="progressbar"
|
role="progressbar"
|
||||||
@@ -19,7 +19,13 @@
|
|||||||
aria-valuemin="0"
|
aria-valuemin="0"
|
||||||
aria-valuemax="100"
|
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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
+5
-3
@@ -202,9 +202,10 @@ export default class Repository {
|
|||||||
* @param status the new status
|
* @param status the new status
|
||||||
* @param errorMessage a potential error message to display
|
* @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.status = status;
|
||||||
this._model.errorMessage = errorMessage;
|
this._model.statusDate = new Date();
|
||||||
|
this._model.statusMessage = statusMessage;
|
||||||
return this._model.save();
|
return this._model.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,7 +324,8 @@ export default class Repository {
|
|||||||
options: this._model.options,
|
options: this._model.options,
|
||||||
conference: this._model.conference,
|
conference: this._model.conference,
|
||||||
anonymizeDate: this._model.anonymizeDate,
|
anonymizeDate: this._model.anonymizeDate,
|
||||||
status: this._model.status,
|
status: this.status,
|
||||||
|
statusMessage: this._model.statusMessage,
|
||||||
source: this.source.toJSON(),
|
source: this.source.toJSON(),
|
||||||
lastView: this._model.lastView,
|
lastView: this._model.lastView,
|
||||||
pageView: this._model.pageView,
|
pageView: this._model.pageView,
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ const AnonymizedRepositorySchema = new Schema({
|
|||||||
type: String,
|
type: String,
|
||||||
default: "preparing",
|
default: "preparing",
|
||||||
},
|
},
|
||||||
errorMessage: String,
|
statusDate: Date,
|
||||||
|
statusMessage: String,
|
||||||
anonymizeDate: Date,
|
anonymizeDate: Date,
|
||||||
lastView: Date,
|
lastView: Date,
|
||||||
pageView: Number,
|
pageView: Number,
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ import { RepositoryStatus, Tree } from "../../types";
|
|||||||
export interface IAnonymizedRepository {
|
export interface IAnonymizedRepository {
|
||||||
repoId: string;
|
repoId: string;
|
||||||
status?: RepositoryStatus;
|
status?: RepositoryStatus;
|
||||||
errorMessage?: string;
|
statusMessage?: string;
|
||||||
|
statusDate: Date;
|
||||||
anonymizeDate: Date;
|
anonymizeDate: Date;
|
||||||
source: {
|
source: {
|
||||||
type: "GitHubDownload" | "GitHubStream" | "Zip";
|
type: "GitHubDownload" | "GitHubStream" | "Zip";
|
||||||
|
|||||||
@@ -60,7 +60,28 @@ export default class GitHubDownload extends GitHubBase implements SourceBase {
|
|||||||
await this.repository.updateStatus("download");
|
await this.repository.updateStatus("download");
|
||||||
const originalPath = this.repository.originalCachePath;
|
const originalPath = this.repository.originalCachePath;
|
||||||
await storage.mk(originalPath);
|
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");
|
await this.repository.updateStatus("ready");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user