mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-02-12 18:32:44 +00:00
feat: check repo status before update
This commit is contained in:
@@ -181,6 +181,7 @@ export default class Repository {
|
||||
this._model.options.expirationDate
|
||||
) {
|
||||
if (this._model.options.expirationDate <= new Date()) {
|
||||
this._model.status = RepositoryStatus.EXPIRED;
|
||||
this.expire();
|
||||
}
|
||||
}
|
||||
@@ -261,6 +262,21 @@ export default class Repository {
|
||||
.getTracer("ano-file")
|
||||
.startSpan("Repository.updateIfNeeded");
|
||||
span.setAttribute("repoId", this.repoId);
|
||||
|
||||
if (
|
||||
this._model.options.expirationMode !== "never" &&
|
||||
this.status != RepositoryStatus.EXPIRED &&
|
||||
this._model.options.expirationDate
|
||||
) {
|
||||
if (this._model.options.expirationDate <= new Date()) {
|
||||
this._model.status = RepositoryStatus.EXPIRED;
|
||||
await this.expire();
|
||||
throw new AnonymousError("repository_expired", {
|
||||
object: this,
|
||||
httpStatus: 410,
|
||||
});
|
||||
}
|
||||
}
|
||||
const yesterday = new Date();
|
||||
yesterday.setDate(yesterday.getDate() - 1);
|
||||
if (
|
||||
|
||||
@@ -85,17 +85,17 @@ router.get(
|
||||
if (!repo) return;
|
||||
let redirectURL = null;
|
||||
if (
|
||||
repo.status == "expired" &&
|
||||
repo.status == RepositoryStatus.EXPIRED &&
|
||||
repo.options.expirationMode == "redirect" &&
|
||||
repo.model.source.repositoryName
|
||||
) {
|
||||
redirectURL = `https://github.com/${repo.model.source.repositoryName}`;
|
||||
} else {
|
||||
if (
|
||||
repo.status == "expired" ||
|
||||
repo.status == "expiring" ||
|
||||
repo.status == "removing" ||
|
||||
repo.status == "removed"
|
||||
repo.status == RepositoryStatus.EXPIRED ||
|
||||
repo.status == RepositoryStatus.EXPIRING ||
|
||||
repo.status == RepositoryStatus.REMOVING ||
|
||||
repo.status == RepositoryStatus.REMOVED
|
||||
) {
|
||||
throw new AnonymousError("repository_expired", {
|
||||
object: repo,
|
||||
|
||||
@@ -4,6 +4,7 @@ import * as db from "../database";
|
||||
import UserModel from "../../core/model/users/users.model";
|
||||
import User from "../../core/User";
|
||||
import { HTTPError } from "got";
|
||||
import { RepositoryStatus } from "../../core/types";
|
||||
|
||||
export async function getPullRequest(
|
||||
req: express.Request,
|
||||
@@ -50,7 +51,7 @@ export async function getRepo(
|
||||
} else {
|
||||
// redirect if the repository is expired
|
||||
if (
|
||||
repo.status == "expired" &&
|
||||
repo.status == RepositoryStatus.EXPIRED &&
|
||||
repo.options.expirationMode == "redirect" &&
|
||||
repo.model.source.repositoryId
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user