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