mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-02-12 18:32:44 +00:00
fix claim
This commit is contained in:
@@ -16,6 +16,41 @@ const router = express.Router();
|
||||
// user needs to be connected for all user API
|
||||
router.use(connection.ensureAuthenticated);
|
||||
|
||||
// claim a repository
|
||||
router.post("/claim", async (req, res) => {
|
||||
try {
|
||||
if (!req.body.repoId) {
|
||||
return res.status(500).json({ error: "repoId_not_defined" });
|
||||
}
|
||||
if (!req.body.repoUrl) {
|
||||
return res.status(500).json({ error: "repoUrl_not_defined" });
|
||||
}
|
||||
|
||||
const repoConfig = await repoUtils.getConfig(req.body.repoId);
|
||||
if (repoConfig == null) {
|
||||
return res.status(500).json({ error: "repo_not_found" });
|
||||
}
|
||||
|
||||
const repo = gh(req.body.repoUrl);
|
||||
if (repoConfig.fullName != repo.repository) {
|
||||
return res.status(500).json({ error: "repo_not_found" });
|
||||
}
|
||||
|
||||
console.log(`${req.user.username} claims ${repoConfig.fullName}.`);
|
||||
|
||||
await db
|
||||
.get("anonymized_repositories")
|
||||
.updateOne(
|
||||
{ repoId: repoConfig.repoId },
|
||||
{ $set: { owner: req.user.username } }
|
||||
);
|
||||
return res.send("Ok");
|
||||
} catch (error) {
|
||||
console.error(req.path, error);
|
||||
return res.status(500).json({ error });
|
||||
}
|
||||
});
|
||||
|
||||
router.get("/:repoId/", async (req, res) => {
|
||||
try {
|
||||
const repository = await repoUtils.getAnonymizedRepoDetails(
|
||||
@@ -173,41 +208,6 @@ router.delete("/:repoId/", async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// claim a repository
|
||||
router.post("/claim", async (req, res) => {
|
||||
try {
|
||||
if (!req.body.repoId) {
|
||||
return res.status(500).json({ error: "repoId_not_defined" });
|
||||
}
|
||||
if (!req.body.repoUrl) {
|
||||
return res.status(500).json({ error: "repoUrl_not_defined" });
|
||||
}
|
||||
|
||||
const repoConfig = await repoUtils.getConfig(req.body.repoId);
|
||||
if (repoConfig == null) {
|
||||
return res.status(500).json({ error: "repo_not_found" });
|
||||
}
|
||||
|
||||
const repo = gh(req.body.repoUrl);
|
||||
if (repoConfig.fullName != repo.repository) {
|
||||
return res.status(500).json({ error: "repo_not_found" });
|
||||
}
|
||||
|
||||
console.log(`${req.user.username} claims ${repoConfig.fullName}.`);
|
||||
|
||||
await db
|
||||
.get("anonymized_repositories")
|
||||
.updateOne(
|
||||
{ repoId: repoConfig.repoId },
|
||||
{ $set: { owner: req.user.username } }
|
||||
);
|
||||
return res.send("Ok");
|
||||
} catch (error) {
|
||||
console.error(req.path, error);
|
||||
return res.status(500).json({ error });
|
||||
}
|
||||
});
|
||||
|
||||
router.get("/:owner/:repo/", async (req, res) => {
|
||||
try {
|
||||
const repository = await repoUtils.getRepoDetails({
|
||||
|
||||
Reference in New Issue
Block a user