mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-06-06 23:53:55 +02:00
improve logs
This commit is contained in:
+6
-5
@@ -40,7 +40,7 @@ async function anonymizeRepository(options) {
|
|||||||
try {
|
try {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error while updating the repository.");
|
console.error("Error while updating the repository.");
|
||||||
console.error(repoConfig.repoId, error);
|
console.error(repoConfig.repoId, req.path, error);
|
||||||
}
|
}
|
||||||
await repoUtils.updateAnonymizedRepository(repoConfig);
|
await repoUtils.updateAnonymizedRepository(repoConfig);
|
||||||
}
|
}
|
||||||
@@ -61,6 +61,7 @@ router.get("/:repoId/files", async (req, res) => {
|
|||||||
const files = await fileUtils.getFileList({ repoConfig });
|
const files = await fileUtils.getFileList({ repoConfig });
|
||||||
return res.json(files);
|
return res.json(files);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error(req.path, error);
|
||||||
return res.status(500).json({ error });
|
return res.status(500).json({ error });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -83,7 +84,7 @@ router.get("/:repoId/stats", async (req, res) => {
|
|||||||
const stats = await fileUtils.getStats({ repoConfig });
|
const stats = await fileUtils.getStats({ repoConfig });
|
||||||
return res.json(stats.languages);
|
return res.json(stats.languages);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(req.params.repoId, error);
|
console.error(req.path, error);
|
||||||
return res.status(500).json({ error });
|
return res.status(500).json({ error });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -98,7 +99,7 @@ router.get("/:repoId/options", async (req, res) => {
|
|||||||
await anonymizeRepository({ repoConfig });
|
await anonymizeRepository({ repoConfig });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Error during the anonymization of the repository");
|
console.log("Error during the anonymization of the repository");
|
||||||
console.error(req.params.repoId, error);
|
console.error(req.path, error);
|
||||||
}
|
}
|
||||||
if (repoConfig.status == "removed") {
|
if (repoConfig.status == "removed") {
|
||||||
throw "repository_expired";
|
throw "repository_expired";
|
||||||
@@ -115,7 +116,7 @@ router.get("/:repoId/options", async (req, res) => {
|
|||||||
|
|
||||||
return res.json(repoConfig.options);
|
return res.json(repoConfig.options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(req.params.repoId, error);
|
console.error(req.path, error);
|
||||||
return res.status(500).json({ error });
|
return res.status(500).json({ error });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -156,7 +157,7 @@ router.get("/:repoId/file/:path*", async (req, res) => {
|
|||||||
return res.status(404).json({ error: "file_not_found" });
|
return res.status(404).json({ error: "file_not_found" });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(req.params.repoId, req.params.path, error);
|
console.error(req.path, error);
|
||||||
return res.status(500).send({ error });
|
return res.status(500).send({ error });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ router.get("/:repoId/", async (req, res) => {
|
|||||||
}
|
}
|
||||||
res.status(404).send("repo_not_found");
|
res.status(404).send("repo_not_found");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error(req.path, error);
|
||||||
res.status(500).send(error);
|
res.status(500).send(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -119,7 +120,7 @@ router.post("/:repoId/", async (req, res) => {
|
|||||||
await githubUtils.downloadRepoAndAnonymize(repoConfig);
|
await githubUtils.downloadRepoAndAnonymize(repoConfig);
|
||||||
await repoUtils.updateStatus(repoConfig, "ready");
|
await repoUtils.updateStatus(repoConfig, "ready");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(req.path, error);
|
||||||
await repoUtils.updateStatus(repoConfig, "error", error);
|
await repoUtils.updateStatus(repoConfig, "error", error);
|
||||||
return res.status(500).json({ error });
|
return res.status(500).json({ error });
|
||||||
}
|
}
|
||||||
@@ -139,6 +140,7 @@ router.post("/:repoId/refresh", async (req, res) => {
|
|||||||
await repoUtils.updateAnonymizedRepository(repoConfig);
|
await repoUtils.updateAnonymizedRepository(repoConfig);
|
||||||
return res.send("ok");
|
return res.send("ok");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error(req.path, error);
|
||||||
return res.status(500).json({ error });
|
return res.status(500).json({ error });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -159,6 +161,7 @@ router.delete("/:repoId/", async (req, res) => {
|
|||||||
console.log(`${req.params.repoId} is removed`);
|
console.log(`${req.params.repoId} is removed`);
|
||||||
return res.json("ok");
|
return res.json("ok");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error(req.path, error);
|
||||||
return res.status(500).json({ error });
|
return res.status(500).json({ error });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -193,6 +196,7 @@ router.post("/claim", async (req, res) => {
|
|||||||
);
|
);
|
||||||
return res.send("Ok");
|
return res.send("Ok");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error(req.path, error);
|
||||||
return res.status(500).json({ error });
|
return res.status(500).json({ error });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -210,6 +214,7 @@ router.get("/:owner/:repo/", async (req, res) => {
|
|||||||
}
|
}
|
||||||
res.status(404).send("repo_not_found");
|
res.status(404).send("repo_not_found");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error(req.path, error);
|
||||||
res.status(500).send(error);
|
res.status(500).send(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -227,6 +232,7 @@ router.get("/:owner/:repo/branches", async (req, res) => {
|
|||||||
}
|
}
|
||||||
res.status(404).send("repo_not_found");
|
res.status(404).send("repo_not_found");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error(req.path, error);
|
||||||
res.status(500).send(error);
|
res.status(500).send(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -337,7 +343,7 @@ router.post("/", async (req, res) => {
|
|||||||
await githubUtils.downloadRepoAndAnonymize(data);
|
await githubUtils.downloadRepoAndAnonymize(data);
|
||||||
await repoUtils.updateStatus(repoConfig, "ready");
|
await repoUtils.updateStatus(repoConfig, "ready");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(req.path, error);
|
||||||
await repoUtils.updateStatus(repoConfig, "error", "unable_to_anonymize");
|
await repoUtils.updateStatus(repoConfig, "error", "unable_to_anonymize");
|
||||||
return res
|
return res
|
||||||
.status(500)
|
.status(500)
|
||||||
|
|||||||
@@ -11,33 +11,54 @@ const router = express.Router();
|
|||||||
router.use(connection.ensureAuthenticated);
|
router.use(connection.ensureAuthenticated);
|
||||||
|
|
||||||
router.get("/logout", async (req, res) => {
|
router.get("/logout", async (req, res) => {
|
||||||
|
try {
|
||||||
req.logout();
|
req.logout();
|
||||||
res.redirect("/");
|
res.redirect("/");
|
||||||
|
} catch (error) {
|
||||||
|
console.error(req.path, error);
|
||||||
|
res.status(500).json({ error });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/", async (req, res) => {
|
router.get("/", async (req, res) => {
|
||||||
|
try {
|
||||||
const photo = req.user.profile.photos.length
|
const photo = req.user.profile.photos.length
|
||||||
? req.user.profile.photos[0].value
|
? req.user.profile.photos[0].value
|
||||||
: null;
|
: null;
|
||||||
res.json({ username: req.user.profile.username, photo });
|
res.json({ username: req.user.profile.username, photo });
|
||||||
|
} catch (error) {
|
||||||
|
console.error(req.path, error);
|
||||||
|
res.status(500).json({ error });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/default", async (req, res) => {
|
router.get("/default", async (req, res) => {
|
||||||
|
try {
|
||||||
const d = await db
|
const d = await db
|
||||||
.get("users")
|
.get("users")
|
||||||
.findOne({ username: req.user.username }, { projection: { default: 1 } });
|
.findOne({ username: req.user.username }, { projection: { default: 1 } });
|
||||||
res.json(d.default);
|
res.json(d.default);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(req.path, error);
|
||||||
|
res.status(500).json({ error });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/default", async (req, res) => {
|
router.post("/default", async (req, res) => {
|
||||||
|
try {
|
||||||
const d = req.body;
|
const d = req.body;
|
||||||
await db
|
await db
|
||||||
.get("users")
|
.get("users")
|
||||||
.updateOne({ username: req.user.username }, { $set: { default: d } });
|
.updateOne({ username: req.user.username }, { $set: { default: d } });
|
||||||
res.send("ok");
|
res.send("ok");
|
||||||
|
} catch (error) {
|
||||||
|
console.error(req.path, error);
|
||||||
|
res.status(500).json({ error });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/anonymized_repositories", async (req, res) => {
|
router.get("/anonymized_repositories", async (req, res) => {
|
||||||
|
try {
|
||||||
const repos = await db
|
const repos = await db
|
||||||
.get("anonymized_repositories")
|
.get("anonymized_repositories")
|
||||||
.find(
|
.find(
|
||||||
@@ -61,9 +82,14 @@ router.get("/anonymized_repositories", async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.json(repos);
|
res.json(repos);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(req.path, error);
|
||||||
|
res.status(500).json({ error });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/all_repositories", async (req, res) => {
|
router.get("/all_repositories", async (req, res) => {
|
||||||
|
try {
|
||||||
const user = await db
|
const user = await db
|
||||||
.get()
|
.get()
|
||||||
.collection("users")
|
.collection("users")
|
||||||
@@ -99,6 +125,10 @@ router.get("/all_repositories", async (req, res) => {
|
|||||||
res.status(500).send(error);
|
res.status(500).send(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(req.path, error);
|
||||||
|
res.status(500).json({ error });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
+1
-1
@@ -58,7 +58,7 @@ async function webView(req, res) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(req.path, error);
|
||||||
return res.status(500).send({ error });
|
return res.status(500).send({ error });
|
||||||
}
|
}
|
||||||
return res.status(404).send("file_not_found");
|
return res.status(404).send("file_not_found");
|
||||||
|
|||||||
Reference in New Issue
Block a user