mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-07-05 13:17:59 +02:00
feat: add a flag to know if a repo has been reseted
This commit is contained in:
@@ -318,6 +318,8 @@ export default class Repository {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async removeCache() {
|
async removeCache() {
|
||||||
|
this.model.isReseted = true;
|
||||||
|
await this.model.save();
|
||||||
if (await storage.exists(this._model.repoId + "/")) {
|
if (await storage.exists(this._model.repoId + "/")) {
|
||||||
return storage.rm(this._model.repoId + "/");
|
return storage.rm(this._model.repoId + "/");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,10 @@ const AnonymizedRepositorySchema = new Schema({
|
|||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
isReseted: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default AnonymizedRepositorySchema;
|
export default AnonymizedRepositorySchema;
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ export interface IAnonymizedRepository {
|
|||||||
storage: number;
|
storage: number;
|
||||||
file: number;
|
file: number;
|
||||||
};
|
};
|
||||||
|
isReseted: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IAnonymizedRepositoryDocument
|
export interface IAnonymizedRepositoryDocument
|
||||||
|
|||||||
+8
-5
@@ -27,7 +27,10 @@ export function repositoryStatusCheck() {
|
|||||||
const job = schedule.scheduleJob("0 */6 * * *", async () => {
|
const job = schedule.scheduleJob("0 */6 * * *", async () => {
|
||||||
console.log("[schedule] Check repository status and unused repositories");
|
console.log("[schedule] Check repository status and unused repositories");
|
||||||
(
|
(
|
||||||
await AnonymizedRepositoryModel.find({ status: { $eq: "ready" } })
|
await AnonymizedRepositoryModel.find({
|
||||||
|
status: { $eq: "ready" },
|
||||||
|
isReseted: { $eq: false },
|
||||||
|
})
|
||||||
).forEach((data) => {
|
).forEach((data) => {
|
||||||
const repo = new Repository(data);
|
const repo = new Repository(data);
|
||||||
try {
|
try {
|
||||||
@@ -35,13 +38,13 @@ export function repositoryStatusCheck() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`Repository ${repo.repoId} is expired`);
|
console.log(`Repository ${repo.repoId} is expired`);
|
||||||
}
|
}
|
||||||
const sixMonthAgo = new Date();
|
const fourMonthAgo = new Date();
|
||||||
sixMonthAgo.setMonth(sixMonthAgo.getMonth() - 6);
|
fourMonthAgo.setMonth(fourMonthAgo.getMonth() - 4);
|
||||||
|
|
||||||
if (repo.model.lastView < sixMonthAgo) {
|
if (repo.model.lastView < fourMonthAgo) {
|
||||||
repo.removeCache().then(() => {
|
repo.removeCache().then(() => {
|
||||||
console.log(
|
console.log(
|
||||||
`Repository ${repo.repoId} not visited for 6 months remove the cached files`
|
`Repository ${repo.repoId} not visited for 4 months remove the cached files`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ export default class GitHubDownload extends GitHubBase implements SourceBase {
|
|||||||
clearTimeout(progressTimeout);
|
clearTimeout(progressTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.repository.model.isReseted = false;
|
||||||
await this.repository.updateStatus(RepositoryStatus.READY);
|
await this.repository.updateStatus(RepositoryStatus.READY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,9 +59,11 @@ export default class GitHubStream extends GitHubBase implements SourceBase {
|
|||||||
} else {
|
} else {
|
||||||
content = Buffer.from("");
|
content = Buffer.from("");
|
||||||
}
|
}
|
||||||
|
await storage.write(file.originalCachePath, content, file, this);
|
||||||
|
this.repository.model.isReseted = false;
|
||||||
|
await this.repository.model.save();
|
||||||
if (this.repository.status !== RepositoryStatus.READY)
|
if (this.repository.status !== RepositoryStatus.READY)
|
||||||
await this.repository.updateStatus(RepositoryStatus.READY);
|
await this.repository.updateStatus(RepositoryStatus.READY);
|
||||||
await storage.write(file.originalCachePath, content, file, this);
|
|
||||||
return stream.Readable.from(content);
|
return stream.Readable.from(content);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if ((error as any).status === 404 || (error as any).httpStatus === 404) {
|
if ((error as any).status === 404 || (error as any).httpStatus === 404) {
|
||||||
|
|||||||
Reference in New Issue
Block a user