fix: check last status activity

This commit is contained in:
tdurieux
2021-09-08 09:40:44 +02:00
parent 2f97d92332
commit fd2fc8fa7e
+14 -8
View File
@@ -97,19 +97,22 @@ export default class Repository {
check() { check() {
if ( if (
this._model.options.expirationMode !== "never" && this._model.options.expirationMode !== "never" &&
this._model.status == "ready" this.status == "ready"
) { ) {
if (this._model.options.expirationDate <= new Date()) { if (this._model.options.expirationDate <= new Date()) {
this.expire(); this.expire();
} }
} }
if (this._model.status == "expired") { if (this.status == "expired") {
throw new AnonymousError("repository_expired", this); throw new AnonymousError("repository_expired", this);
} }
if (this._model.status == "removed") { if (this.status == "removed") {
throw new AnonymousError("repository_expired", this); throw new AnonymousError("repository_expired", this);
} }
if (this._model.status == "download") { const fiveMinuteAgo = new Date();
fiveMinuteAgo.setMinutes(fiveMinuteAgo.getMinutes() - 5);
if (this.status == "download" && this._model.statusDate > fiveMinuteAgo) {
throw new AnonymousError("repository_not_ready", this); throw new AnonymousError("repository_not_ready", this);
} }
} }
@@ -137,7 +140,10 @@ export default class Repository {
yesterday.setDate(yesterday.getDate() - 1); yesterday.setDate(yesterday.getDate() - 1);
if (this._model.options.update && this._model.lastView < yesterday) { if (this._model.options.update && this._model.lastView < yesterday) {
if (this._model.status == "download") {
const fiveMinuteAgo = new Date();
fiveMinuteAgo.setMinutes(fiveMinuteAgo.getMinutes() - 5);
if (this.status == "download" && this._model.statusDate > fiveMinuteAgo) {
throw new AnonymousError("repository_not_ready", this); throw new AnonymousError("repository_not_ready", this);
} }
@@ -182,7 +188,7 @@ export default class Repository {
* @returns void * @returns void
*/ */
async anonymize() { async anonymize() {
if (this._model.status == "ready") return; if (this.status == "ready") return;
await this.updateStatus("preparing"); await this.updateStatus("preparing");
await this.files(); await this.files();
return this.updateStatus("ready"); return this.updateStatus("ready");
@@ -251,7 +257,7 @@ export default class Repository {
*/ */
file: number; file: number;
}> { }> {
if (this._model.status != "ready") return { storage: 0, file: 0 }; if (this.status != "ready") return { storage: 0, file: 0 };
if (this._model.size.file) return this._model.size; if (this._model.size.file) return this._model.size;
function recursiveCount(files) { function recursiveCount(files) {
const out = { storage: 0, file: 0 }; const out = { storage: 0, file: 0 };
@@ -314,7 +320,7 @@ export default class Repository {
} }
get size() { get size() {
if (this._model.status != "ready") return { storage: 0, file: 0 }; if (this.status != "ready") return { storage: 0, file: 0 };
return this._model.size; return this._model.size;
} }