diff --git a/src/Repository.ts b/src/Repository.ts index c8ef82d..a96217b 100644 --- a/src/Repository.ts +++ b/src/Repository.ts @@ -109,7 +109,7 @@ export default class Repository { if (this._model.status == "removed") { throw new AnonymousError("repository_expired", this); } - if (this._model.status != "ready") { + if (this._model.status == "download") { throw new AnonymousError("repository_not_ready", this); } } @@ -225,7 +225,7 @@ export default class Repository { /** * Reset/delete the state of the repository */ - private async resetSate(status?: RepositoryStatus) { + async resetSate(status?: RepositoryStatus) { if (status) this._model.status = status; this._model.size = { storage: 0, file: 0 }; this._model.originalFiles = null; diff --git a/src/source/GitHubDownload.ts b/src/source/GitHubDownload.ts index bc3347a..15f7576 100644 --- a/src/source/GitHubDownload.ts +++ b/src/source/GitHubDownload.ts @@ -49,9 +49,11 @@ export default class GitHubDownload extends GitHubBase implements SourceBase { try { response = await this._getZipUrl(config.GITHUB_TOKEN); } catch (error) { + await this.repository.resetSate("error"); throw new AnonymousError("repo_not_accessible", this.repository); } } else { + await this.repository.resetSate("error"); throw new AnonymousError("repo_not_accessible", this.repository); } } diff --git a/src/source/GitHubStream.ts b/src/source/GitHubStream.ts index 2c42a1c..7550103 100644 --- a/src/source/GitHubStream.ts +++ b/src/source/GitHubStream.ts @@ -49,6 +49,8 @@ export default class GitHubStream extends GitHubBase implements SourceBase { } else { content = Buffer.from(""); } + if (this.repository.status != "ready") + await this.repository.updateStatus("ready"); await storage.write(file.originalCachePath, content); return stream.Readable.from(content.toString()); } catch (error) { @@ -83,6 +85,7 @@ export default class GitHubStream extends GitHubBase implements SourceBase { recursive: "1", }); } catch (error) { + await this.repository.resetSate("error"); throw new AnonymousError("repo_not_accessible", this.repository); } @@ -90,6 +93,8 @@ export default class GitHubStream extends GitHubBase implements SourceBase { if (ghRes.data.truncated) { await this.getTruncatedTree(sha, tree, parentPath); } + if (this.repository.status != "ready") + await this.repository.updateStatus("ready"); return tree; } diff --git a/src/types.ts b/src/types.ts index dee74b8..10bebdb 100644 --- a/src/types.ts +++ b/src/types.ts @@ -115,7 +115,8 @@ export type RepositoryStatus = | "download" | "ready" | "expired" - | "removed"; + | "removed" + | "error"; export type ConferenceStatus = "ready" | "expired" | "removed";