mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-06-04 06:38:04 +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)
|
||||||
|
|||||||
+99
-69
@@ -11,93 +11,123 @@ const router = express.Router();
|
|||||||
router.use(connection.ensureAuthenticated);
|
router.use(connection.ensureAuthenticated);
|
||||||
|
|
||||||
router.get("/logout", async (req, res) => {
|
router.get("/logout", async (req, res) => {
|
||||||
req.logout();
|
try {
|
||||||
res.redirect("/");
|
req.logout();
|
||||||
|
res.redirect("/");
|
||||||
|
} catch (error) {
|
||||||
|
console.error(req.path, error);
|
||||||
|
res.status(500).json({ error });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/", async (req, res) => {
|
router.get("/", async (req, res) => {
|
||||||
const photo = req.user.profile.photos.length
|
try {
|
||||||
? req.user.profile.photos[0].value
|
const photo = req.user.profile.photos.length
|
||||||
: null;
|
? req.user.profile.photos[0].value
|
||||||
res.json({ username: req.user.profile.username, photo });
|
: null;
|
||||||
|
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) => {
|
||||||
const d = await db
|
try {
|
||||||
.get("users")
|
const d = await db
|
||||||
.findOne({ username: req.user.username }, { projection: { default: 1 } });
|
.get("users")
|
||||||
res.json(d.default);
|
.findOne({ username: req.user.username }, { projection: { default: 1 } });
|
||||||
|
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) => {
|
||||||
const d = req.body;
|
try {
|
||||||
await db
|
const d = req.body;
|
||||||
.get("users")
|
await db
|
||||||
.updateOne({ username: req.user.username }, { $set: { default: d } });
|
.get("users")
|
||||||
res.send("ok");
|
.updateOne({ username: req.user.username }, { $set: { default: d } });
|
||||||
|
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) => {
|
||||||
const repos = await db
|
try {
|
||||||
.get("anonymized_repositories")
|
const repos = await db
|
||||||
.find(
|
.get("anonymized_repositories")
|
||||||
{
|
.find(
|
||||||
owner: req.user.username,
|
{
|
||||||
},
|
owner: req.user.username,
|
||||||
{ projection: { token: 0, files: 0, originalFiles: 0 } }
|
},
|
||||||
)
|
{ projection: { token: 0, files: 0, originalFiles: 0 } }
|
||||||
.toArray();
|
)
|
||||||
for (let repo of repos) {
|
.toArray();
|
||||||
if (repo.options.expirationDate) {
|
for (let repo of repos) {
|
||||||
repo.options.expirationDate = new Date(repo.options.expirationDate);
|
if (repo.options.expirationDate) {
|
||||||
}
|
repo.options.expirationDate = new Date(repo.options.expirationDate);
|
||||||
if (
|
}
|
||||||
repo.options.expirationMode != "never" &&
|
if (
|
||||||
repo.options.expirationDate != null &&
|
repo.options.expirationMode != "never" &&
|
||||||
repo.options.expirationDate < new Date()
|
repo.options.expirationDate != null &&
|
||||||
) {
|
repo.options.expirationDate < new Date()
|
||||||
await repoUtils.updateStatus({ repoId: repo.repoId }, "expired");
|
) {
|
||||||
repo.status = "expired";
|
await repoUtils.updateStatus({ repoId: repo.repoId }, "expired");
|
||||||
|
repo.status = "expired";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
res.json(repos);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(req.path, error);
|
||||||
|
res.status(500).json({ error });
|
||||||
}
|
}
|
||||||
res.json(repos);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/all_repositories", async (req, res) => {
|
router.get("/all_repositories", async (req, res) => {
|
||||||
const user = await db
|
try {
|
||||||
.get()
|
const user = await db
|
||||||
.collection("users")
|
.get()
|
||||||
.findOne(
|
.collection("users")
|
||||||
{ username: req.user.username },
|
.findOne(
|
||||||
{ projection: { repositories: 1 } }
|
{ username: req.user.username },
|
||||||
);
|
{ projection: { repositories: 1 } }
|
||||||
if (!user) {
|
);
|
||||||
res.status(401).send({ error: "user_not_found" });
|
if (!user) {
|
||||||
}
|
res.status(401).send({ error: "user_not_found" });
|
||||||
if (user.repositories && req.query.force !== "1") {
|
|
||||||
return res.json(user.repositories);
|
|
||||||
} else {
|
|
||||||
const octokit = new Octokit({ auth: req.user.accessToken });
|
|
||||||
const repositories = await octokit.paginate(
|
|
||||||
octokit.repos.listForAuthenticatedUser,
|
|
||||||
{
|
|
||||||
visibility: "all",
|
|
||||||
sort: "pushed",
|
|
||||||
per_page: 100,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
try {
|
|
||||||
await db
|
|
||||||
.get()
|
|
||||||
.collection("users")
|
|
||||||
.updateOne(
|
|
||||||
{ username: req.user.profile.username },
|
|
||||||
{ $set: { repositories } }
|
|
||||||
);
|
|
||||||
res.json(repositories);
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).send(error);
|
|
||||||
}
|
}
|
||||||
|
if (user.repositories && req.query.force !== "1") {
|
||||||
|
return res.json(user.repositories);
|
||||||
|
} else {
|
||||||
|
const octokit = new Octokit({ auth: req.user.accessToken });
|
||||||
|
const repositories = await octokit.paginate(
|
||||||
|
octokit.repos.listForAuthenticatedUser,
|
||||||
|
{
|
||||||
|
visibility: "all",
|
||||||
|
sort: "pushed",
|
||||||
|
per_page: 100,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
await db
|
||||||
|
.get()
|
||||||
|
.collection("users")
|
||||||
|
.updateOne(
|
||||||
|
{ username: req.user.profile.username },
|
||||||
|
{ $set: { repositories } }
|
||||||
|
);
|
||||||
|
res.json(repositories);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).send(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(req.path, error);
|
||||||
|
res.status(500).json({ error });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+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