refactor: replace repository status by its enum

This commit is contained in:
tdurieux
2023-08-31 11:32:51 +02:00
parent 1671a16025
commit e553561ccb
+13 -9
View File
@@ -135,7 +135,7 @@ export default class Repository {
check() { check() {
if ( if (
this._model.options.expirationMode !== "never" && this._model.options.expirationMode !== "never" &&
this.status == "ready" && this.status == RepositoryStatus.READY &&
this._model.options.expirationDate this._model.options.expirationDate
) { ) {
if (this._model.options.expirationDate <= new Date()) { if (this._model.options.expirationDate <= new Date()) {
@@ -143,10 +143,10 @@ export default class Repository {
} }
} }
if ( if (
this.status == "expired" || this.status == RepositoryStatus.EXPIRED ||
this.status == "expiring" || this.status == RepositoryStatus.EXPIRING ||
this.status == "removing" || this.status == RepositoryStatus.REMOVING ||
this.status == "removed" this.status == RepositoryStatus.REMOVED
) { ) {
throw new AnonymousError("repository_expired", { throw new AnonymousError("repository_expired", {
object: this, object: this,
@@ -157,8 +157,9 @@ export default class Repository {
fiveMinuteAgo.setMinutes(fiveMinuteAgo.getMinutes() - 5); fiveMinuteAgo.setMinutes(fiveMinuteAgo.getMinutes() - 5);
if ( if (
this.status == "preparing" || this.status == RepositoryStatus.PREPARING ||
(this.status == "download" && this._model.statusDate > fiveMinuteAgo) (this.status == RepositoryStatus.DOWNLOAD &&
this._model.statusDate > fiveMinuteAgo)
) { ) {
throw new AnonymousError("repository_not_ready", { throw new AnonymousError("repository_not_ready", {
object: this, object: this,
@@ -206,7 +207,10 @@ export default class Repository {
const branch = this.source.branch; const branch = this.source.branch;
const newCommit = branches.filter((f) => f.name == branch.name)[0] const newCommit = branches.filter((f) => f.name == branch.name)[0]
?.commit; ?.commit;
if (branch.commit == newCommit && this.status == "ready") { if (
branch.commit == newCommit &&
this.status == RepositoryStatus.READY
) {
console.log(`[UPDATE] ${this._model.repoId} is up to date`); console.log(`[UPDATE] ${this._model.repoId} is up to date`);
return; return;
} }
@@ -428,7 +432,7 @@ export default class Repository {
} }
get size() { get size() {
if (this.status != "ready") return { storage: 0, file: 0 }; if (this.status != RepositoryStatus.READY) return { storage: 0, file: 0 };
return this._model.size; return this._model.size;
} }