mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-09-12 21:58:57 +02:00
fix: prevent stale downloads from reviving removed repositories
This commit is contained in:
+20
-12
@@ -470,22 +470,30 @@ export default class Repository {
|
||||
* @param status the new status
|
||||
* @param errorMessage a potential error message to display
|
||||
*/
|
||||
public protectLifecycle = false;
|
||||
|
||||
async updateStatus(status: RepositoryStatus, statusMessage?: string) {
|
||||
if (!status) return this.model;
|
||||
this._model.status = status;
|
||||
this._model.statusDate = new Date();
|
||||
this._model.statusMessage = statusMessage;
|
||||
if (!isConnected) return this.model;
|
||||
await AnonymizedRepositoryModel.updateOne(
|
||||
{ _id: this._model._id },
|
||||
{
|
||||
$set: {
|
||||
status,
|
||||
statusDate: this._model.statusDate,
|
||||
statusMessage,
|
||||
const statusDate = new Date();
|
||||
if (isConnected) {
|
||||
const result = await AnonymizedRepositoryModel.updateOne(
|
||||
{
|
||||
_id: this._model._id,
|
||||
...(this.protectLifecycle ? {
|
||||
status: { $nin: [RepositoryStatus.REMOVING, RepositoryStatus.REMOVED,
|
||||
RepositoryStatus.EXPIRING, RepositoryStatus.EXPIRED] },
|
||||
anonymizeDate: this._model.anonymizeDate,
|
||||
} : {}),
|
||||
},
|
||||
{ $set: { status, statusDate, statusMessage } }
|
||||
).exec();
|
||||
if (this.protectLifecycle && result.matchedCount === 0) {
|
||||
throw new AnonymousError("repository_job_cancelled", { httpStatus: 410 });
|
||||
}
|
||||
).exec();
|
||||
}
|
||||
this._model.status = status;
|
||||
this._model.statusDate = statusDate;
|
||||
this._model.statusMessage = statusMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,9 @@ export default async function (job: SandboxedJob<RepoJobData, void>) {
|
||||
await connect();
|
||||
|
||||
const repo = await getRepository(job.data.repoId);
|
||||
if ([RepositoryStatus.REMOVING, RepositoryStatus.REMOVED,
|
||||
RepositoryStatus.EXPIRING, RepositoryStatus.EXPIRED].some((status) => status === repo.status)) return;
|
||||
repo.protectLifecycle = true;
|
||||
const token = await getToken(repo);
|
||||
const tokenKey = token.slice(-8);
|
||||
|
||||
@@ -88,6 +91,7 @@ export default async function (job: SandboxedJob<RepoJobData, void>) {
|
||||
logger.info("downloaded", { repoId: job.data.repoId });
|
||||
} catch (error) {
|
||||
clearInterval(statusInterval);
|
||||
if (error instanceof Error && error.message === "repository_job_cancelled") return;
|
||||
if (tickPromise) await tickPromise;
|
||||
|
||||
// Rate-limited: delay the job and free the worker slot
|
||||
@@ -123,6 +127,7 @@ export default async function (job: SandboxedJob<RepoJobData, void>) {
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
clearInterval(statusInterval);
|
||||
if (error instanceof Error && error.message === "repository_job_cancelled") return;
|
||||
if (tickPromise) {
|
||||
try {
|
||||
await tickPromise;
|
||||
|
||||
Reference in New Issue
Block a user