mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-02-12 18:32:44 +00: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
|
||||
*/
|
||||
async removeCache() {
|
||||
this.model.isReseted = true;
|
||||
await this.model.save();
|
||||
if (await storage.exists(this._model.repoId + "/")) {
|
||||
return storage.rm(this._model.repoId + "/");
|
||||
}
|
||||
|
||||
@@ -63,6 +63,10 @@ const AnonymizedRepositorySchema = new Schema({
|
||||
default: 0,
|
||||
},
|
||||
},
|
||||
isReseted: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
|
||||
export default AnonymizedRepositorySchema;
|
||||
|
||||
@@ -40,6 +40,7 @@ export interface IAnonymizedRepository {
|
||||
storage: number;
|
||||
file: number;
|
||||
};
|
||||
isReseted: boolean;
|
||||
}
|
||||
|
||||
export interface IAnonymizedRepositoryDocument
|
||||
|
||||
@@ -27,7 +27,10 @@ export function repositoryStatusCheck() {
|
||||
const job = schedule.scheduleJob("0 */6 * * *", async () => {
|
||||
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) => {
|
||||
const repo = new Repository(data);
|
||||
try {
|
||||
@@ -35,13 +38,13 @@ export function repositoryStatusCheck() {
|
||||
} catch (error) {
|
||||
console.log(`Repository ${repo.repoId} is expired`);
|
||||
}
|
||||
const sixMonthAgo = new Date();
|
||||
sixMonthAgo.setMonth(sixMonthAgo.getMonth() - 6);
|
||||
const fourMonthAgo = new Date();
|
||||
fourMonthAgo.setMonth(fourMonthAgo.getMonth() - 4);
|
||||
|
||||
if (repo.model.lastView < sixMonthAgo) {
|
||||
if (repo.model.lastView < fourMonthAgo) {
|
||||
repo.removeCache().then(() => {
|
||||
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);
|
||||
}
|
||||
|
||||
this.repository.model.isReseted = false;
|
||||
await this.repository.updateStatus(RepositoryStatus.READY);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,9 +59,11 @@ export default class GitHubStream extends GitHubBase implements SourceBase {
|
||||
} else {
|
||||
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)
|
||||
await this.repository.updateStatus(RepositoryStatus.READY);
|
||||
await storage.write(file.originalCachePath, content, file, this);
|
||||
return stream.Readable.from(content);
|
||||
} catch (error) {
|
||||
if ((error as any).status === 404 || (error as any).httpStatus === 404) {
|
||||
|
||||
Reference in New Issue
Block a user