mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-06-09 09:03:56 +02:00
fix: Prevent error when repo is not found
This commit is contained in:
@@ -15,7 +15,7 @@ const router = express.Router();
|
|||||||
|
|
||||||
// get repository information
|
// get repository information
|
||||||
router.get("/:repoId/", async (req: express.Request, res: express.Response) => {
|
router.get("/:repoId/", async (req: express.Request, res: express.Response) => {
|
||||||
const repo = await getRepo(req, res, { nocheck: true });
|
const repo = await getRepo(req, res, { nocheck: false });
|
||||||
if (!repo) return;
|
if (!repo) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -75,10 +75,10 @@ router.post("/claim", async (req: express.Request, res: express.Response) => {
|
|||||||
router.post(
|
router.post(
|
||||||
"/:repoId/refresh",
|
"/:repoId/refresh",
|
||||||
async (req: express.Request, res: express.Response) => {
|
async (req: express.Request, res: express.Response) => {
|
||||||
const repo = await getRepo(req, res, { nocheck: true });
|
|
||||||
if (!repo) return;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const repo = await getRepo(req, res, { nocheck: true });
|
||||||
|
if (!repo) throw new Error("repo_not_found");
|
||||||
|
|
||||||
const user = await getUser(req);
|
const user = await getUser(req);
|
||||||
if (repo.owner.username != user.username) {
|
if (repo.owner.username != user.username) {
|
||||||
return res.status(401).json({ error: "not_authorized" });
|
return res.status(401).json({ error: "not_authorized" });
|
||||||
@@ -220,17 +220,17 @@ function updateRepoModel(model: IAnonymizedRepositoryDocument, repoUpdate) {
|
|||||||
router.post(
|
router.post(
|
||||||
"/:repoId/",
|
"/:repoId/",
|
||||||
async (req: express.Request, res: express.Response) => {
|
async (req: express.Request, res: express.Response) => {
|
||||||
const repo = await getRepo(req, res, { nocheck: true });
|
|
||||||
if (!repo) return;
|
|
||||||
const user = await getUser(req);
|
|
||||||
|
|
||||||
if (repo.owner.username != user.username) {
|
|
||||||
return res.status(401).json({ error: "not_authorized" });
|
|
||||||
}
|
|
||||||
|
|
||||||
const repoUpdate = req.body;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const repo = await getRepo(req, res, { nocheck: true });
|
||||||
|
if (!repo) throw new Error("repo_not_found");
|
||||||
|
const user = await getUser(req);
|
||||||
|
|
||||||
|
if (repo.owner.username != user.username) {
|
||||||
|
return res.status(401).json({ error: "not_authorized" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const repoUpdate = req.body;
|
||||||
|
|
||||||
validateNewRepo(repoUpdate);
|
validateNewRepo(repoUpdate);
|
||||||
|
|
||||||
if (repoUpdate.commit != repo.model.source.commit) {
|
if (repoUpdate.commit != repo.model.source.commit) {
|
||||||
|
|||||||
Reference in New Issue
Block a user