fix: fix repository status

This commit is contained in:
tdurieux
2021-09-06 23:58:26 +02:00
parent 470e19c13e
commit 03b0fab519
4 changed files with 11 additions and 3 deletions
+2 -2
View File
@@ -109,7 +109,7 @@ export default class Repository {
if (this._model.status == "removed") { if (this._model.status == "removed") {
throw new AnonymousError("repository_expired", this); throw new AnonymousError("repository_expired", this);
} }
if (this._model.status != "ready") { if (this._model.status == "download") {
throw new AnonymousError("repository_not_ready", this); throw new AnonymousError("repository_not_ready", this);
} }
} }
@@ -225,7 +225,7 @@ export default class Repository {
/** /**
* Reset/delete the state of the repository * Reset/delete the state of the repository
*/ */
private async resetSate(status?: RepositoryStatus) { async resetSate(status?: RepositoryStatus) {
if (status) this._model.status = status; if (status) this._model.status = status;
this._model.size = { storage: 0, file: 0 }; this._model.size = { storage: 0, file: 0 };
this._model.originalFiles = null; this._model.originalFiles = null;
+2
View File
@@ -49,9 +49,11 @@ export default class GitHubDownload extends GitHubBase implements SourceBase {
try { try {
response = await this._getZipUrl(config.GITHUB_TOKEN); response = await this._getZipUrl(config.GITHUB_TOKEN);
} catch (error) { } catch (error) {
await this.repository.resetSate("error");
throw new AnonymousError("repo_not_accessible", this.repository); throw new AnonymousError("repo_not_accessible", this.repository);
} }
} else { } else {
await this.repository.resetSate("error");
throw new AnonymousError("repo_not_accessible", this.repository); throw new AnonymousError("repo_not_accessible", this.repository);
} }
} }
+5
View File
@@ -49,6 +49,8 @@ export default class GitHubStream extends GitHubBase implements SourceBase {
} else { } else {
content = Buffer.from(""); content = Buffer.from("");
} }
if (this.repository.status != "ready")
await this.repository.updateStatus("ready");
await storage.write(file.originalCachePath, content); await storage.write(file.originalCachePath, content);
return stream.Readable.from(content.toString()); return stream.Readable.from(content.toString());
} catch (error) { } catch (error) {
@@ -83,6 +85,7 @@ export default class GitHubStream extends GitHubBase implements SourceBase {
recursive: "1", recursive: "1",
}); });
} catch (error) { } catch (error) {
await this.repository.resetSate("error");
throw new AnonymousError("repo_not_accessible", this.repository); throw new AnonymousError("repo_not_accessible", this.repository);
} }
@@ -90,6 +93,8 @@ export default class GitHubStream extends GitHubBase implements SourceBase {
if (ghRes.data.truncated) { if (ghRes.data.truncated) {
await this.getTruncatedTree(sha, tree, parentPath); await this.getTruncatedTree(sha, tree, parentPath);
} }
if (this.repository.status != "ready")
await this.repository.updateStatus("ready");
return tree; return tree;
} }
+2 -1
View File
@@ -115,7 +115,8 @@ export type RepositoryStatus =
| "download" | "download"
| "ready" | "ready"
| "expired" | "expired"
| "removed"; | "removed"
| "error";
export type ConferenceStatus = "ready" | "expired" | "removed"; export type ConferenceStatus = "ready" | "expired" | "removed";