mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-02-13 02:42:45 +00:00
fix configuration issue during anonymization
This commit is contained in:
@@ -35,7 +35,7 @@ const config: Config = {
|
||||
GITHUB_TOKEN: "",
|
||||
DEFAULT_QUOTA: 2 * 1024 * 1024 * 1024 * 8,
|
||||
MAX_FILE_SIZE: 10 * 1024 * 1024, // in b
|
||||
MAX_REPO_SIZE: 8 * 1024, // in kb
|
||||
MAX_REPO_SIZE: 500 * 8 * 1024, // in kb
|
||||
ENABLE_DOWNLOAD: false,
|
||||
AUTH_CALLBACK: "http://localhost:5000/github/auth",
|
||||
ANONYMIZATION_MASK: "XXXX",
|
||||
|
||||
@@ -341,7 +341,7 @@
|
||||
<small class="form-text text-muted"
|
||||
>How the repository will be anonymized. Stream mode will
|
||||
request the content on the flight. This is the only
|
||||
option for repositories bigger than 10mb. Download will
|
||||
option for repositories bigger than {{site_options.MAX_REPO_SIZE * 1024| humanFileSize}}. Download will
|
||||
download the repository the repository on the
|
||||
anonymous.4open.science server, it is faster and offer
|
||||
more features.</small
|
||||
|
||||
@@ -357,6 +357,7 @@ angular
|
||||
function ($scope, $http, $location) {
|
||||
$scope.title = "Main";
|
||||
$scope.user = { status: "connection" };
|
||||
$scope.site_options;
|
||||
|
||||
$scope.path = $location.url();
|
||||
$scope.paths = $location.path().substring(1).split("/");
|
||||
@@ -386,6 +387,18 @@ angular
|
||||
}
|
||||
getUser();
|
||||
|
||||
function getOptions() {
|
||||
$http.get("/api/options").then(
|
||||
(res) => {
|
||||
if (res) $scope.site_options = res.data;
|
||||
},
|
||||
() => {
|
||||
$scope.site_options = null;
|
||||
}
|
||||
);
|
||||
}
|
||||
getOptions();
|
||||
|
||||
function getMessage() {
|
||||
$http.get("/api/message").then(
|
||||
(res) => {
|
||||
@@ -435,7 +448,6 @@ angular
|
||||
notebook: true,
|
||||
loc: true,
|
||||
link: true,
|
||||
mode: "GitHubDownload",
|
||||
};
|
||||
|
||||
function getDefault() {
|
||||
@@ -859,7 +871,7 @@ angular
|
||||
resetValidity();
|
||||
const res = await $http.get(`/api/repo/${o.owner}/${o.repo}/`);
|
||||
$scope.details = res.data;
|
||||
if ($scope.details.size > 500 * 1024 * 8) {
|
||||
if ($scope.details.size > $scope.site_options.MAX_REPO_SIZE) {
|
||||
$scope.options.mode = "GitHubStream";
|
||||
$scope.anonymize.mode.$$element[0].disabled = true;
|
||||
}
|
||||
@@ -902,41 +914,51 @@ angular
|
||||
);
|
||||
}
|
||||
if (!$scope.options.link) {
|
||||
content = content.replace(urlRegex, "XXXX");
|
||||
content = content.replace(
|
||||
urlRegex,
|
||||
$scope.site_options.ANONYMIZATION_MASK
|
||||
);
|
||||
}
|
||||
|
||||
const host = document.location.protocol + "//" + document.location.host;
|
||||
|
||||
content = content.replace(
|
||||
new RegExp(
|
||||
`\\b${$scope.repoUrl}/blob/${$scope.source.branch}\\b`,
|
||||
"gi"
|
||||
),
|
||||
`https://anonymous.4open.science/r/${$scope.repoId}`
|
||||
`${host}/r/${$scope.repoId}`
|
||||
);
|
||||
content = content.replace(
|
||||
new RegExp(
|
||||
`\\b${$scope.repoUrl}/tree/${$scope.source.branch}\\b`,
|
||||
"gi"
|
||||
),
|
||||
`https://anonymous.4open.science/r/${$scope.repoId}`
|
||||
`${host}/r/${$scope.repoId}`
|
||||
);
|
||||
content = content.replace(
|
||||
new RegExp(`\\b${$scope.repoUrl}`, "gi"),
|
||||
`https://anonymous.4open.science/r/${$scope.repoId}`
|
||||
`${host}/r/${$scope.repoId}`
|
||||
);
|
||||
|
||||
for (let term of $scope.terms.split("\n")) {
|
||||
const terms = $scope.terms.split("\n");
|
||||
for (let i = 0; i < terms.length; i++) {
|
||||
const term = terms[i];
|
||||
if (term.trim() == "") {
|
||||
continue;
|
||||
}
|
||||
// remove whole url if it contains the term
|
||||
|
||||
content = content.replace(urlRegex, (match) => {
|
||||
if (new RegExp(`\\b${term}\\b`, "gi").test(match)) return "XXXX";
|
||||
if (new RegExp(`\\b${term}\\b`, "gi").test(match))
|
||||
return $scope.site_options.ANONYMIZATION_MASK + "-" + (i + 1);
|
||||
return match;
|
||||
});
|
||||
|
||||
// remove the term in the text
|
||||
content = content.replace(new RegExp(`\\b${term}\\b`, "gi"), "XXXX");
|
||||
content = content.replace(
|
||||
new RegExp(`\\b${term}\\b`, "gi"),
|
||||
$scope.site_options.ANONYMIZATION_MASK + "-" + (i + 1)
|
||||
);
|
||||
}
|
||||
|
||||
$scope.anonymize_readme = content;
|
||||
|
||||
@@ -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
src/routes/option.ts
Normal file
14
src/routes/option.ts
Normal 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;
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user