fix configuration issue during anonymization

This commit is contained in:
tdurieux
2021-08-24 09:35:48 +02:00
parent b03e43eb9a
commit cde9214579
8 changed files with 87 additions and 41 deletions
+2
View File
@@ -3,6 +3,7 @@ import repositoryPublic from "./repository-public";
import file from "./file";
import webview from "./webview";
import user from "./user";
import option from "./option";
export default {
repositoryPrivate,
@@ -10,4 +11,5 @@ export default {
file,
webview,
user,
option,
};
+14
View File
@@ -0,0 +1,14 @@
import * as express from "express";
import config from "../../config";
export const router = express.Router();
router.get("/", async (req: express.Request, res: express.Response) => {
res.json({
ENABLE_DOWNLOAD: config.ENABLE_DOWNLOAD,
MAX_FILE_SIZE: config.MAX_FILE_SIZE,
MAX_REPO_SIZE: config.MAX_REPO_SIZE,
ANONYMIZATION_MASK: config.ANONYMIZATION_MASK,
});
});
export default router;
+34 -28
View File
@@ -159,6 +159,22 @@ router.get(
}
);
// get repository information
router.get("/:repoId/", async (req: express.Request, res: express.Response) => {
try {
const repo = await getRepo(req, res, { nocheck: true });
if (!repo) throw new Error("repo_not_found");
const user = await getUser(req);
if (user.username != repo.model.owner) {
return res.status(401).send({ error: "not_authorized" });
}
res.json((await db.getRepository(req.params.repoId)).toJSON());
} catch (error) {
handleError(error, res);
}
});
function validateNewRepo(repoUpdate) {
const validCharacters = /^[0-9a-zA-Z\-\_]+$/;
if (
@@ -184,7 +200,19 @@ function validateNewRepo(repoUpdate) {
}
}
function updateRepoModel(model: IAnonymizedRepositoryDocument, repoUpdate) {
function updateRepoModel(
model: IAnonymizedRepositoryDocument,
repoUpdate: any
) {
if (repoUpdate.source.type) {
model.source.type = repoUpdate.source.type;
if (
model.source.type != "GitHubStream" &&
model.source.type != "GitHubDownload"
) {
model.source.type = "GitHubStream";
}
}
model.source.commit = repoUpdate.source.commit;
model.source.branch = repoUpdate.source.branch;
model.conference = repoUpdate.conference;
@@ -204,22 +232,6 @@ function updateRepoModel(model: IAnonymizedRepositoryDocument, repoUpdate) {
};
}
// get repository information
router.get("/:repoId/", async (req: express.Request, res: express.Response) => {
try {
const repo = await getRepo(req, res, { nocheck: true });
if (!repo) throw new Error("repo_not_found");
const user = await getUser(req);
if (user.username != repo.model.owner) {
return res.status(401).send({ error: "not_authorized" });
}
res.json((await db.getRepository(req.params.repoId)).toJSON());
} catch (error) {
handleError(error, res);
}
});
// update a repository
router.post(
"/:repoId/",
@@ -273,15 +285,11 @@ router.post("/", async (req: express.Request, res: express.Response) => {
repo.repoId = repoUpdate.repoId;
repo.anonymizeDate = new Date();
repo.owner = user.username;
repo.source = {
type:
repoUpdate.options.mode == "download"
? "GitHubDownload"
: "GitHubStream",
accessToken: user.accessToken,
repositoryId: repository.model.id,
repositoryName: repoUpdate.fullName,
};
updateRepoModel(repo, repoUpdate);
repo.source.accessToken = user.accessToken;
repo.source.repositoryId = repository.model.id;
repo.source.repositoryName = repoUpdate.fullName;
if (repo.source.type == "GitHubDownload") {
// details.size is in kilobytes
@@ -290,8 +298,6 @@ router.post("/", async (req: express.Request, res: express.Response) => {
}
}
updateRepoModel(repo, repoUpdate);
await repo.save();
res.send("ok");
new Repository(repo).anonymize();
+2 -1
View File
@@ -64,7 +64,8 @@ router.get(
res.json({
url: redirectURL,
download: !!config.ENABLE_DOWNLOAD,
download:
!!config.ENABLE_DOWNLOAD && repo.source.type == "GitHubDownload",
});
} catch (error) {
handleError(error, res);
+1
View File
@@ -57,6 +57,7 @@ export default async function start() {
app.use("/github", rate, connection.router);
// api routes
app.use("/api/options", rate, router.option);
app.use("/api/user", rate, router.user);
app.use("/api/repo", rate, router.repositoryPublic);
app.use("/api/repo", rate, router.file);