fix(#57): handle links to anonymized repositories

This commit is contained in:
tdurieux
2021-05-21 15:21:51 +02:00
parent 7d15a26e51
commit 11182352fd
+22 -21
View File
@@ -237,7 +237,7 @@ angular
$element.append(rendered); $element.append(rendered);
Prism.highlightAll(); Prism.highlightAll();
} catch (error) { } catch (error) {
$element.html("Unable to render the notebook.") $element.html("Unable to render the notebook.");
} }
}); });
} }
@@ -294,10 +294,7 @@ angular
$scope.user = { status: "connection" }; $scope.user = { status: "connection" };
$scope.path = $location.url(); $scope.path = $location.url();
$scope.paths = $location $scope.paths = $location.path().substring(1).split("/");
.path()
.substring(1)
.split("/");
$scope.darkMode = function (on) { $scope.darkMode = function (on) {
localStorage.setItem("darkMode", on); localStorage.setItem("darkMode", on);
@@ -341,10 +338,7 @@ angular
$scope.title = current.title; $scope.title = current.title;
} }
$scope.path = $location.url(); $scope.path = $location.url();
$scope.paths = $location $scope.paths = $location.path().substring(1).split("/");
.path()
.substring(1)
.split("/");
} }
$scope.$on("$routeChangeSuccess", changedUrl); $scope.$on("$routeChangeSuccess", changedUrl);
@@ -509,9 +503,7 @@ angular
$scope.removeRepository = (repo) => { $scope.removeRepository = (repo) => {
if ( if (
confirm( confirm(
`Are you sure that you want to remove the repository ${ `Are you sure that you want to remove the repository ${repo.repoId}?`
repo.repoId
}?`
) )
) { ) {
$http.delete(`/api/repo/${repo.repoId}`).then(() => { $http.delete(`/api/repo/${repo.repoId}`).then(() => {
@@ -655,9 +647,9 @@ angular
); );
} }
$scope.details = (await $http.get( $scope.details = (
`/api/repo/${res.data.fullName}/` await $http.get(`/api/repo/${res.data.fullName}/`)
)).data; ).data;
await getReadme(); await getReadme();
await $scope.getBranches(); await $scope.getBranches();
@@ -805,7 +797,8 @@ angular
} }
async function anonymize() { async function anonymize() {
const urlRegex = /<?\b((https?|ftp|file):\/\/)[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]\b\/?>?/g; const urlRegex =
/<?\b((https?|ftp|file):\/\/)[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]\b\/?>?/g;
let content = $scope.readme; let content = $scope.readme;
if (!$scope.options.image) { if (!$scope.options.image) {
@@ -977,15 +970,14 @@ angular
const textFiles = ["license", "txt"]; const textFiles = ["license", "txt"];
const imageFiles = ["png", "jpg", "jpeg", "gif"]; const imageFiles = ["png", "jpg", "jpeg", "gif"];
$scope.repoId = $routeParams.repoId;
$scope.type = "loading";
$scope.filePath = $routeParams.path || "";
$scope.paths = $scope.filePath.split("/");
$scope.$on("$routeUpdate", function (event, current, old) { $scope.$on("$routeUpdate", function (event, current, old) {
$scope.filePath = $routeParams.path || ""; $scope.filePath = $routeParams.path || "";
$scope.paths = $scope.filePath.split("/"); $scope.paths = $scope.filePath.split("/");
if ($scope.repoId != $routeParams.repoId) {
return init();
}
updateContent(); updateContent();
}); });
@@ -1198,6 +1190,12 @@ angular
getContent($scope.filePath); getContent($scope.filePath);
} }
function init() {
$scope.repoId = $routeParams.repoId;
$scope.type = "loading";
$scope.filePath = $routeParams.path || "";
$scope.paths = $scope.filePath.split("/");
getOptions((options) => { getOptions((options) => {
getFiles(() => { getFiles(() => {
updateContent(); updateContent();
@@ -1207,5 +1205,8 @@ angular
} }
}); });
}); });
}
init();
}, },
]); ]);