mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-07-07 14:17:51 +02:00
fix(#57): handle links to anonymized repositories
This commit is contained in:
+58
-57
@@ -7,7 +7,7 @@ angular
|
|||||||
"pascalprecht.translate",
|
"pascalprecht.translate",
|
||||||
"angular-google-analytics",
|
"angular-google-analytics",
|
||||||
])
|
])
|
||||||
.config(function(
|
.config(function (
|
||||||
$routeProvider,
|
$routeProvider,
|
||||||
$locationProvider,
|
$locationProvider,
|
||||||
$translateProvider,
|
$translateProvider,
|
||||||
@@ -80,22 +80,22 @@ angular
|
|||||||
});
|
});
|
||||||
$locationProvider.html5Mode(true);
|
$locationProvider.html5Mode(true);
|
||||||
})
|
})
|
||||||
.run(["Analytics", function(Analytics) {}])
|
.run(["Analytics", function (Analytics) {}])
|
||||||
.filter("title", function() {
|
.filter("title", function () {
|
||||||
return function(str) {
|
return function (str) {
|
||||||
if (!str) return str;
|
if (!str) return str;
|
||||||
|
|
||||||
str = str.toLowerCase();
|
str = str.toLowerCase();
|
||||||
var words = str.split(" ");
|
var words = str.split(" ");
|
||||||
|
|
||||||
var capitalized = words.map(function(word) {
|
var capitalized = words.map(function (word) {
|
||||||
return word.charAt(0).toUpperCase() + word.substring(1, word.length);
|
return word.charAt(0).toUpperCase() + word.substring(1, word.length);
|
||||||
});
|
});
|
||||||
return capitalized.join(" ");
|
return capitalized.join(" ");
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.directive("tree", [
|
.directive("tree", [
|
||||||
function() {
|
function () {
|
||||||
return {
|
return {
|
||||||
restrict: "E",
|
restrict: "E",
|
||||||
scope: { file: "=", parent: "@" },
|
scope: { file: "=", parent: "@" },
|
||||||
@@ -104,11 +104,11 @@ angular
|
|||||||
"$scope",
|
"$scope",
|
||||||
"$routeParams",
|
"$routeParams",
|
||||||
"$compile",
|
"$compile",
|
||||||
function($element, $scope, $routeParams, $compile) {
|
function ($element, $scope, $routeParams, $compile) {
|
||||||
$scope.repoId = document.location.pathname.split("/")[2];
|
$scope.repoId = document.location.pathname.split("/")[2];
|
||||||
|
|
||||||
$scope.opens = {};
|
$scope.opens = {};
|
||||||
const toArray = function(obj) {
|
const toArray = function (obj) {
|
||||||
const output = [];
|
const output = [];
|
||||||
for (let name in obj) {
|
for (let name in obj) {
|
||||||
if (obj[name].size != null) {
|
if (obj[name].size != null) {
|
||||||
@@ -194,11 +194,11 @@ angular
|
|||||||
display();
|
display();
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.isActive = function(name) {
|
$scope.isActive = function (name) {
|
||||||
return $routeParams.path == name.substring(1);
|
return $routeParams.path == name.substring(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.openFolder = function(folder, event) {
|
$scope.openFolder = function (folder, event) {
|
||||||
$scope.opens[folder] = !$scope.opens[folder];
|
$scope.opens[folder] = !$scope.opens[folder];
|
||||||
if (event.srcElement.nextSibling == null) {
|
if (event.srcElement.nextSibling == null) {
|
||||||
const folders = folder.substring(1).split("/");
|
const folders = folder.substring(1).split("/");
|
||||||
@@ -211,10 +211,10 @@ angular
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const isFile = function(child) {
|
const isFile = function (child) {
|
||||||
return child == null || child.size != null;
|
return child == null || child.size != null;
|
||||||
};
|
};
|
||||||
const isDir = function(child) {
|
const isDir = function (child) {
|
||||||
return !isFile(child);
|
return !isFile(child);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -223,11 +223,11 @@ angular
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
.directive("notebook", [
|
.directive("notebook", [
|
||||||
function() {
|
function () {
|
||||||
return {
|
return {
|
||||||
restrict: "E",
|
restrict: "E",
|
||||||
scope: { file: "=" },
|
scope: { file: "=" },
|
||||||
controller: function($element, $scope, $http) {
|
controller: function ($element, $scope, $http) {
|
||||||
function render() {
|
function render() {
|
||||||
if (!$scope.file) return;
|
if (!$scope.file) return;
|
||||||
$http.get($scope.file).then((res) => {
|
$http.get($scope.file).then((res) => {
|
||||||
@@ -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.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -250,13 +250,13 @@ angular
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
.directive("loc", [
|
.directive("loc", [
|
||||||
function() {
|
function () {
|
||||||
return {
|
return {
|
||||||
restrict: "E",
|
restrict: "E",
|
||||||
scope: { stats: "=" },
|
scope: { stats: "=" },
|
||||||
template:
|
template:
|
||||||
"<div class='lang' ng-repeat='lang in elements' title='{{lang.lang|title}}: {{lang.loc | number}} lines' data-toggle='tooltip' data-placement='bottom' style='width:{{lang.loc*100/total}}%;background:{{lang.color}};'></div>",
|
"<div class='lang' ng-repeat='lang in elements' title='{{lang.lang|title}}: {{lang.loc | number}} lines' data-toggle='tooltip' data-placement='bottom' style='width:{{lang.loc*100/total}}%;background:{{lang.color}};'></div>",
|
||||||
controller: function($scope) {
|
controller: function ($scope) {
|
||||||
function render() {
|
function render() {
|
||||||
$scope.elements = [];
|
$scope.elements = [];
|
||||||
$scope.total = 0;
|
$scope.total = 0;
|
||||||
@@ -289,17 +289,14 @@ angular
|
|||||||
"$scope",
|
"$scope",
|
||||||
"$http",
|
"$http",
|
||||||
"$location",
|
"$location",
|
||||||
function($scope, $http, $location) {
|
function ($scope, $http, $location) {
|
||||||
$scope.title = "Main";
|
$scope.title = "Main";
|
||||||
$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);
|
||||||
$scope.isDarkMode = on;
|
$scope.isDarkMode = on;
|
||||||
if (on) {
|
if (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);
|
||||||
@@ -354,7 +348,7 @@ angular
|
|||||||
.controller("faqController", [
|
.controller("faqController", [
|
||||||
"$scope",
|
"$scope",
|
||||||
"$http",
|
"$http",
|
||||||
function($scope, $http) {
|
function ($scope, $http) {
|
||||||
function getSupportedFileTypes() {
|
function getSupportedFileTypes() {
|
||||||
$http.get("/api/supportedTypes").then((res) => {
|
$http.get("/api/supportedTypes").then((res) => {
|
||||||
$scope.supportedFileTypes = res.data;
|
$scope.supportedFileTypes = res.data;
|
||||||
@@ -366,7 +360,7 @@ angular
|
|||||||
.controller("profileController", [
|
.controller("profileController", [
|
||||||
"$scope",
|
"$scope",
|
||||||
"$http",
|
"$http",
|
||||||
function($scope, $http) {
|
function ($scope, $http) {
|
||||||
$scope.terms = "";
|
$scope.terms = "";
|
||||||
$scope.options = {
|
$scope.options = {
|
||||||
expirationMode: "remove",
|
expirationMode: "remove",
|
||||||
@@ -413,7 +407,7 @@ angular
|
|||||||
"$scope",
|
"$scope",
|
||||||
"$http",
|
"$http",
|
||||||
"$location",
|
"$location",
|
||||||
function($scope, $http, $location) {
|
function ($scope, $http, $location) {
|
||||||
$scope.repoId = null;
|
$scope.repoId = null;
|
||||||
$scope.repoUrl = null;
|
$scope.repoUrl = null;
|
||||||
$scope.claim = () => {
|
$scope.claim = () => {
|
||||||
@@ -439,7 +433,7 @@ angular
|
|||||||
"$scope",
|
"$scope",
|
||||||
"$http",
|
"$http",
|
||||||
"$location",
|
"$location",
|
||||||
function($scope, $http, $location) {
|
function ($scope, $http, $location) {
|
||||||
if ($scope.user && !$scope.user.status) {
|
if ($scope.user && !$scope.user.status) {
|
||||||
$location.url("/dashboard");
|
$location.url("/dashboard");
|
||||||
}
|
}
|
||||||
@@ -461,8 +455,8 @@ angular
|
|||||||
"$scope",
|
"$scope",
|
||||||
"$http",
|
"$http",
|
||||||
"$location",
|
"$location",
|
||||||
function($scope, $http, $location) {
|
function ($scope, $http, $location) {
|
||||||
$scope.$on("$routeChangeStart", function() {
|
$scope.$on("$routeChangeStart", function () {
|
||||||
// remove tooltip
|
// remove tooltip
|
||||||
$('[data-toggle="tooltip"]').tooltip("dispose");
|
$('[data-toggle="tooltip"]').tooltip("dispose");
|
||||||
});
|
});
|
||||||
@@ -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(() => {
|
||||||
@@ -543,7 +535,7 @@ angular
|
|||||||
"$scope",
|
"$scope",
|
||||||
"$http",
|
"$http",
|
||||||
"$routeParams",
|
"$routeParams",
|
||||||
function($scope, $http, $routeParams) {
|
function ($scope, $http, $routeParams) {
|
||||||
$scope.repoId = $routeParams.repoId;
|
$scope.repoId = $routeParams.repoId;
|
||||||
$scope.repo = null;
|
$scope.repo = null;
|
||||||
$scope.progress = 0;
|
$scope.progress = 0;
|
||||||
@@ -588,7 +580,7 @@ angular
|
|||||||
"$routeParams",
|
"$routeParams",
|
||||||
"$location",
|
"$location",
|
||||||
"$translate",
|
"$translate",
|
||||||
function($scope, $http, $sce, $routeParams, $location, $translate) {
|
function ($scope, $http, $sce, $routeParams, $location, $translate) {
|
||||||
$scope.repoUrl = "";
|
$scope.repoUrl = "";
|
||||||
$scope.repoId = "";
|
$scope.repoId = "";
|
||||||
$scope.terms = "";
|
$scope.terms = "";
|
||||||
@@ -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) {
|
||||||
@@ -967,7 +960,7 @@ angular
|
|||||||
"$location",
|
"$location",
|
||||||
"$routeParams",
|
"$routeParams",
|
||||||
"PDFViewerService",
|
"PDFViewerService",
|
||||||
function($scope, $http, $location, $routeParams, PDFViewerService) {
|
function ($scope, $http, $location, $routeParams, PDFViewerService) {
|
||||||
const extensionModes = {
|
const extensionModes = {
|
||||||
yml: "yaml",
|
yml: "yaml",
|
||||||
txt: "text",
|
txt: "text",
|
||||||
@@ -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.$on("$routeUpdate", function (event, current, old) {
|
||||||
$scope.type = "loading";
|
|
||||||
$scope.filePath = $routeParams.path || "";
|
|
||||||
$scope.paths = $scope.filePath.split("/");
|
|
||||||
|
|
||||||
$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();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1151,7 +1143,7 @@ angular
|
|||||||
fadeFoldWidgets: false,
|
fadeFoldWidgets: false,
|
||||||
mode: getMode(extension),
|
mode: getMode(extension),
|
||||||
|
|
||||||
onLoad: function(_editor) {
|
onLoad: function (_editor) {
|
||||||
_editor.setFontSize($scope.aceOption.fontSize);
|
_editor.setFontSize($scope.aceOption.fontSize);
|
||||||
_editor.setReadOnly($scope.aceOption.readOnly);
|
_editor.setReadOnly($scope.aceOption.readOnly);
|
||||||
_editor.setKeyboardHandler($scope.aceOption.keyBinding);
|
_editor.setKeyboardHandler($scope.aceOption.keyBinding);
|
||||||
@@ -1198,14 +1190,23 @@ angular
|
|||||||
getContent($scope.filePath);
|
getContent($scope.filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
getOptions((options) => {
|
function init() {
|
||||||
getFiles(() => {
|
$scope.repoId = $routeParams.repoId;
|
||||||
updateContent();
|
$scope.type = "loading";
|
||||||
|
$scope.filePath = $routeParams.path || "";
|
||||||
|
$scope.paths = $scope.filePath.split("/");
|
||||||
|
|
||||||
if (options.mode == "download") {
|
getOptions((options) => {
|
||||||
getStats();
|
getFiles(() => {
|
||||||
}
|
updateContent();
|
||||||
|
|
||||||
|
if (options.mode == "download") {
|
||||||
|
getStats();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user