add repository status page

This commit is contained in:
tdurieux
2021-04-06 10:01:53 +02:00
parent fcdaf69b6a
commit 22465d455c
7 changed files with 193 additions and 14 deletions

View File

@@ -211,7 +211,7 @@ a.black_border:hover {
background-color: #ffffff;
padding: 8px 6px;
margin: 0;
border-bottom: 1px solid #dddddd ;
border-bottom: 1px solid #dddddd;
border-radius: 0;
}
@@ -314,3 +314,13 @@ loc .lang {
float: left;
height: 100%;
}
.rounded-circle.fa {
display: inline-block;
font-size: 75px;
height: 140px;
width: 140px;
border: 4px solid;
line-height: 140px;
text-align: center;
}

View File

@@ -7,11 +7,11 @@
"repo_is_updating": "Anonymous GitHub is still processing the repository, it can take several minutes.",
"repoUrl_not_defined": "The repository url needs to be defined.",
"repoId_already_used": "The repository id is already used.",
"invalid_repoId": "The format of the repository id is invalid",
"branch_not_specified": "The branch is not specified",
"options_not_provided": "options_not_provided",
"invalid_terms_format": "invalid_terms_format",
"unable_to_anonymize": "unable_to_anonymize",
"invalid_repoId": "The format of the repository id is invalid.",
"branch_not_specified": "The branch is not specified.",
"options_not_provided": "Anonimization options are mendatory.",
"invalid_terms_format": "Terms are in an invalid format.",
"unable_to_anonymize": "An error happened during the anonimization proccess. Please try later or report the issue.",
"non_supported_mode": "The selected anonymization mode is invalid, only download and stream are supported.",
"invalid_path": "The provided path is invalid or missing.",
"file_not_found": "The requested file is not found.",

116
public/partials/status.htm Normal file
View File

@@ -0,0 +1,116 @@
<div class="container py-4">
<h2>Status of <strong ng-bind="repoId"></strong></h2>
<section class="py-4">
<h2>Progress</h2>
<p>
The current status of your repository. The repository will take few
minutes to get ready depending on the size of the repository.
Visit the <a href="/faq">FAQ</a> for more information.
</p>
<div class="progress" style="height: 25px;">
<div
class="progress-bar"
role="progressbar"
style="width: {{progress}}%;"
aria-valuenow="{{progress}}"
aria-valuemin="0"
aria-valuemax="100"
>
{{repo.status | title}}
</div>
</div>
</section>
<hr class="featurette-divider" />
<section class="py-4">
<h2>Support the project</h2>
<div class="row text-center">
<div class="col-lg-4">
<i class="rounded-circle fa fa-edit"></i>
<h2>Contribute</h2>
<p>
Collabore to the Anonymous GitHub by implementing new features and
fixing bugs. Contribution likes supporting new file format or
improving the deployment are more than welcome.
</p>
<p>
<a
class="btn btn-secondary"
href="https://github.com/tdurieux/anonymous_github/"
target="__self"
>Go to GitHub &raquo;</a
>
</p>
</div>
<!-- /.col-lg-4 -->
<div class="col-lg-4">
<i class="rounded-circle fa fa-comments"></i>
<h2>Feedback</h2>
<p>
Feedback is also really valuable for the project. It helps to project
to identify bugs, missing feature and define priorities for the
project.
</p>
<p>
<a
class="btn btn-secondary"
href="https://github.com/tdurieux/anonymous_github/issues/new"
target="__self"
>Create an issue &raquo;</a
>
</p>
</div>
<!-- /.col-lg-4 -->
<div class="col-lg-4">
<i class="rounded-circle fa fa-dollar"></i>
<h2>Finance</h2>
<p>
You can also help the project by supporting financiarly the project.
The server costs around 25$ per month. Any help to support the cost
would be gradly appriciated.
</p>
<p>
<a
class="btn btn-secondary"
href="https://github.com/sponsors/tdurieux/"
target="__self"
>GitHub Sponsor &raquo;</a
>
<a
class="btn btn-secondary"
href="https://ko-fi.com/tdurieux"
target="__self"
>Ko-fi &raquo;</a
>
</p>
</div>
</div>
</section>
<hr class="featurette-divider" />
<section class="py-4">
<a
class="btn btn-primary"
href="/r/{{repoId}}"
target="__self"
ng-if="repo.status == 'ready'"
>Go to the anonymized repository</a
>
<a
class="btn btn-primary"
href="/w/{{repoId}}"
target="__self"
ng-if="repo.options.page && repo.status == 'ready'"
>Go to the anonymized Gh-page</a
>
</section>
</div>

View File

@@ -28,6 +28,11 @@ angular
controller: "anonymizeController",
title: "Anonymize - Anonymous GitHub",
})
.when("/status/:repoId", {
templateUrl: "/partials/status.htm",
controller: "statusController",
title: "Repository status - Anonymous GitHub",
})
.when("/404", {
templateUrl: "/partials/404.htm",
title: "Page not found - Anonymous GitHub",
@@ -218,6 +223,43 @@ angular
return false;
};
})
.controller("statusController", function($scope, $http, $routeParams) {
$scope.repoId = $routeParams.repoId;
$scope.repo = null;
$scope.progress = 0;
$scope.getStatus = () => {
$http
.get("/api/repo/" + $scope.repoId, {
repoId: $scope.repoId,
repoUrl: $scope.repoUrl,
})
.then(
(res) => {
$scope.repo = res.data;
if ($scope.repo.status == "ready") {
$scope.progress = 100;
} else if ($scope.repo.status == "queue") {
$scope.progress = 0;
} else if ($scope.repo.status == "downloaded") {
$scope.progress = 50;
} else if ($scope.repo.status == "downloading") {
$scope.progress = 25;
} else if ($scope.repo.status == "preparing") {
$scope.progress = 10;
} else if ($scope.repo.status == "anonimizing") {
$scope.progress = 75;
}
if ($scope.repo.status != "ready") {
setTimeout($scope.getStatus, 1000);
}
},
(err) => {
$scope.error = err.data;
}
);
};
$scope.getStatus();
})
.controller("anonymizeController", function(
$scope,
$http,
@@ -505,7 +547,7 @@ angular
await $http.post("/api/repo/", newRepo, {
headers: { "Content-Type": "application/json" },
});
window.location.href = "/r/" + $scope.repoId;
window.location.href = "/status/" + $scope.repoId;
} catch (error) {
if (error.data) {
$translate("ERRORS." + error.data.error).then((translation) => {
@@ -530,7 +572,7 @@ angular
await $http.post("/api/repo/" + newRepo.repoId, newRepo, {
headers: { "Content-Type": "application/json" },
});
window.location.href = "/r/" + $scope.repoId;
window.location.href = "/status/" + $scope.repoId;
} catch (error) {
if (error.data) {
displayErrorMessage(error.data.error);

View File

@@ -112,13 +112,15 @@ router.post("/:repoId/", async (req, res) => {
);
repoConfig = await repoUtils.getConfig(repoUpdate.repoId);
await repoUtils.updateStatus(repoConfig, "preparing");
res.send("ok");
await githubUtils.downloadRepoAndAnonymize(repoConfig);
await repoUtils.updateStatus(repoConfig, "ready");
return res.send("ok");
} catch (error) {
console.error(error);
await repoUtils.updateStatus(repoConfig, "error", error);
return res.status(500).json({ error });
}
});
@@ -320,17 +322,17 @@ router.post("/", async (req, res) => {
},
{ upsert: true }
);
res.send("ok");
try {
await githubUtils.downloadRepoAndAnonymize(data);
await repoUtils.updateStatus(repoConfig, "ready");
} catch (error) {
console.error(error);
await repoUtils.updateStatus(repoConfig, "error");
await repoUtils.updateStatus(repoConfig, "error", "unable_to_anonymize");
return res
.status(500)
.json({ error: "unable_to_anonymize", message: error.message });
}
res.send("ok");
});
module.exports = router;

View File

@@ -51,6 +51,7 @@ module.exports.downloadRepoAndAnonymize = async (repoConfig) => {
return true;
} else if (repoConfig.options.mode == "stream") {
// in stream mode only download the list of file from github
await repoUtils.updateStatus(repoConfig, "downloading");
await fileUtils.getFileList({ repoConfig });
await repoUtils.updateStatus(repoConfig, "ready");
return true;

View File

@@ -139,11 +139,19 @@ module.exports.downloadRepoZip = async (repoConfig, target) => {
});
};
module.exports.updateStatus = async (repoConfig, status) => {
module.exports.updateStatus = async (repoConfig, status, errorMessage) => {
repoConfig.status = status;
repoConfig.errorMessage = errorMessage;
const update = { $set: { status } };
if (!errorMessage) {
update["$unset"] = { errorMessage: "" };
} else {
update["$set"].errorMessage = errorMessage;
}
await db
.get("anonymized_repositories")
.updateOne({ repoId: repoConfig.repoId }, { $set: { status } });
.updateOne({ repoId: repoConfig.repoId }, update);
};
module.exports.downloadOriginalRepo = async (repoConfig, destination) => {