mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-09-30 14:09:33 +02:00
Display error messages
This commit is contained in:
1 parent
54bc4e176d
commit
72715dfcd9
17 files changed
+117
-33
No files matched your search
@@ -21,6 +21,8 @@
|
||||
|
||||
<!-- JS -->
|
||||
<script src="/script/external/angular.min.js"></script>
|
||||
<script src="/script/external/angular-translate.min.js"></script>
|
||||
<script src="/script/external/angular-translate-loader-static-files.min.js"></script>
|
||||
<script src="/script/external/angular-sanitize.min.js"></script>
|
||||
<script src="/script/external/angular-route.min.js"></script>
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"ERRORS": {
|
||||
"repo_not_found": "The repository is not found.",
|
||||
"repo_not_accessible": "Anonymous GitHub does not have the persmission to access the repository.",
|
||||
"repository_expired": "The repository is expired",
|
||||
"repository_not_ready": "Anonymous GitHub is still processing the repository, it can take several minutes.",
|
||||
"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",
|
||||
"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.",
|
||||
"file_not_accessible": "The requested file is not accessible.",
|
||||
"file_not_supported": "The file type is not supported. Anonymous GitHub cannot handle it.",
|
||||
"file_too_big": "The file size exceed the limit of Anonymous GitHub.",
|
||||
"is_folder": "The path points to a folder.",
|
||||
"unable_to_write_file": "Unable to write file on disk.",
|
||||
"stats_unsupported": "Statistics are only supported in download mode.",
|
||||
"branches_not_found": "The requested branch is not found.",
|
||||
"readme_not_available": "No readme for the repository is found.",
|
||||
"user_not_found": "The current user is not found in the database",
|
||||
"not_connected": "User is not connectd",
|
||||
"page_not_supported_on_different_branch": "Anonimized GitHub pages are only supported on the same branch.",
|
||||
"page_not_activated": "Anonimized GitHub page is not enabled."
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,8 @@
|
||||
<!-- JS -->
|
||||
<script src="/script/external/angular.min.js"></script>
|
||||
<script src="/script/external/angular-sanitize.min.js"></script>
|
||||
<script src="/script/external/angular-translate.min.js"></script>
|
||||
<script src="/script/external/angular-translate-loader-static-files.min.js"></script>
|
||||
<script src="/script/external/angular-route.min.js"></script>
|
||||
|
||||
<script src="/script/external/jquery-3.4.1.min.js"></script>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<div class="container-fluid main">
|
||||
<ng-include src="'partials/header.htm'"></ng-include>
|
||||
<div class="row center">
|
||||
<div class="container text-center"><h1 class="display-1">404</h1></div>
|
||||
</div>
|
||||
<div class="container d-flex h-100">
|
||||
<h1 class=" m-auto text-center">
|
||||
<div class="display-1">404</div><small class="text-muted">Page not found</small>
|
||||
</h1>
|
||||
</div>
|
||||
@@ -459,7 +459,12 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="alert alert-danger"
|
||||
role="alert"
|
||||
ng-if="error"
|
||||
ng-bind="error"
|
||||
></div>
|
||||
<button
|
||||
id="submit"
|
||||
type="submit"
|
||||
|
||||
@@ -98,7 +98,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
ng-repeat="repo in repositories| filter:repoFiler| orderBy:orderBy"
|
||||
ng-repeat="repo in repositories| filter:repoFiler| orderBy:orderBy as filteredRepositories"
|
||||
>
|
||||
<th scope="row">{{$index + 1}}</th>
|
||||
<td>
|
||||
@@ -178,6 +178,10 @@
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr ng-hide="filteredRepositories.length">
|
||||
<td></td>
|
||||
<td>No Repository</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@@ -6,5 +6,5 @@
|
||||
<pdfviewer class="h-100 overflow-auto" src="{{url}}" id="viewer"></pdfviewer>
|
||||
</div>
|
||||
<div ng-if="type == 'IPython'"><notebook file="url"></notebook></div>
|
||||
<div ng-if="type == 'error'" class="file-error container d-flex h-100"><h1 class="display-1 m-auto" ng-bind="content">Error</h1></div></div>
|
||||
<div ng-if="type == 'error'" class="file-error container d-flex h-100"><h1 class="display-1 m-auto" translate="ERRORS.{{content}}">Error</h1></div></div>
|
||||
<div ng-if="content == null" class="file-error container d-flex h-100"><h1 class="display-1 m-auto">Empty file!</h1></div>
|
||||
@@ -1,4 +1,4 @@
|
||||
<div class="container d-flex h-100">
|
||||
<h1 class="display-1 m-auto" ng-if="!error">Loading...</h1>
|
||||
<h1 class="display-1 m-auto" ng-if="error" ng-bind="error"></h1>
|
||||
<h1 class="display-1 m-auto" ng-if="error" translate="{{error}}"></h1>
|
||||
</div>
|
||||
+18
-10
@@ -4,8 +4,16 @@ angular
|
||||
"ngSanitize",
|
||||
"ui.ace",
|
||||
"ngPDFViewer",
|
||||
"pascalprecht.translate",
|
||||
])
|
||||
.config(function($routeProvider, $locationProvider) {
|
||||
.config(function($routeProvider, $locationProvider, $translateProvider) {
|
||||
$translateProvider.useStaticFilesLoader({
|
||||
prefix: "/i18n/locale-",
|
||||
suffix: ".json",
|
||||
});
|
||||
|
||||
$translateProvider.preferredLanguage("en");
|
||||
|
||||
$routeProvider
|
||||
.when("/:path*", {
|
||||
templateUrl: "/partials/explore.htm",
|
||||
@@ -311,13 +319,7 @@ angular
|
||||
}
|
||||
},
|
||||
(err) => {
|
||||
if (err.data.error == "repository_expired") {
|
||||
$scope.error = "The repository is not available!";
|
||||
} else if (err.data.error == "repo_not_found") {
|
||||
$scope.error = "The repository is not found!";
|
||||
} else {
|
||||
console.log(err);
|
||||
}
|
||||
$scope.error = err.data.error;
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -451,8 +453,14 @@ angular
|
||||
},
|
||||
(err) => {
|
||||
$scope.type = "error";
|
||||
console.log(err);
|
||||
$scope.content = err.data;
|
||||
try {
|
||||
err.data = JSON.parse(err.data);
|
||||
} catch (ignore) {}
|
||||
if (err.data.error) {
|
||||
$scope.content = err.data.error;
|
||||
} else {
|
||||
$scope.content = err.data;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
/*!
|
||||
* angular-translate - v2.18.4 - 2021-01-14
|
||||
*
|
||||
* Copyright (c) 2021 The angular-translate team, Pascal Precht; Licensed MIT
|
||||
*/
|
||||
!function(e,i){"function"==typeof define&&define.amd?define([],function(){return i()}):"object"==typeof module&&module.exports?module.exports=i():i()}(0,function(){function e(n,a){"use strict";return function(r){if(!(r&&(angular.isArray(r.files)||angular.isString(r.prefix)&&angular.isString(r.suffix))))throw new Error("Couldn't load static files, no files and prefix or suffix specified!");r.files||(r.files=[{prefix:r.prefix,suffix:r.suffix}]);for(var e=function(e){if(!e||!angular.isString(e.prefix)||!angular.isString(e.suffix))throw new Error("Couldn't load static file, no prefix or suffix specified!");var i=[e.prefix,r.key,e.suffix].join("");return angular.isObject(r.fileMap)&&r.fileMap[i]&&(i=r.fileMap[i]),a(angular.extend({url:i,method:"GET"},r.$http)).then(function(e){return e.data},function(){return n.reject(r.key)})},i=[],t=r.files.length,f=0;f<t;f++)i.push(e({prefix:r.files[f].prefix,key:r.key,suffix:r.files[f].suffix}));return n.all(i).then(function(e){for(var i=e.length,r={},t=0;t<i;t++)for(var f in e[t])r[f]=e[t][f];return r})}}return e.$inject=["$q","$http"],angular.module("pascalprecht.translate").factory("$translateStaticFilesLoader",e),e.displayName="$translateStaticFilesLoader","pascalprecht.translate"});
|
||||
@@ -0,0 +1,6 @@
|
||||
/*!
|
||||
* angular-translate - v2.18.4 - 2021-01-14
|
||||
*
|
||||
* Copyright (c) 2021 The angular-translate team, Pascal Precht; Licensed MIT
|
||||
*/
|
||||
!function(t,e){"function"==typeof define&&define.amd?define([],function(){return e()}):"object"==typeof module&&module.exports?module.exports=e():e()}(0,function(){function t(e){"use strict";var n=e.storageKey(),a=e.storage(),t=function(){var t=e.preferredLanguage();angular.isString(t)?e.use(t):a.put(n,e.use())};t.displayName="fallbackFromIncorrectStorageValue",a?a.get(n)?e.use(a.get(n)).catch(t):t():angular.isString(e.preferredLanguage())&&e.use(e.preferredLanguage())}function e(t,r,e,i){"use strict";var T,c,z,x,F,I,_,n,V,R,D,K,U,M,H,G,q={},Y=[],B=t,J=[],Q="translate-cloak",W=!1,X=!1,Z=".",tt=!1,et=!1,nt=0,at=!0,a="default",s={default:function(t){return(t||"").split("-").join("_")},java:function(t){var e=(t||"").split("-").join("_"),n=e.split("_");return 1<n.length?n[0].toLowerCase()+"_"+n[1].toUpperCase():e},bcp47:function(t){var e=(t||"").split("_").join("-"),n=e.split("-");switch(n.length){case 1:n[0]=n[0].toLowerCase();break;case 2:n[0]=n[0].toLowerCase(),4===n[1].length?n[1]=n[1].charAt(0).toUpperCase()+n[1].slice(1).toLowerCase():n[1]=n[1].toUpperCase();break;case 3:n[0]=n[0].toLowerCase(),n[1]=n[1].charAt(0).toUpperCase()+n[1].slice(1).toLowerCase(),n[2]=n[2].toUpperCase();break;default:return e}return n.join("-")},"iso639-1":function(t){return(t||"").split("_").join("-").split("-")[0].toLowerCase()}},o=function(){if(angular.isFunction(i.getLocale))return i.getLocale();var t,e,n=r.$get().navigator,a=["language","browserLanguage","systemLanguage","userLanguage"];if(angular.isArray(n.languages))for(t=0;t<n.languages.length;t++)if((e=n.languages[t])&&e.length)return e;for(t=0;t<a.length;t++)if((e=n[a[t]])&&e.length)return e;return null};o.displayName="angular-translate/service: getFirstBrowserLanguage";var rt=function(){var t=o()||"";return s[a]&&(t=s[a](t)),t};rt.displayName="angular-translate/service: getLocale";var it=function(t,e){for(var n=0,a=t.length;n<a;n++)if(t[n]===e)return n;return-1},st=function(){return this.toString().replace(/^\s+|\s+$/g,"")},f=function(t){return angular.isString(t)?t.toLowerCase():t},ot=function(t){if(t){for(var e,n=[],a=f(t),r=0,i=Y.length;r<i;r++)n.push(f(Y[r]));if(-1<(r=it(n,a)))return Y[r];if(c)for(var s in c)if(c.hasOwnProperty(s)){var o=!1,l=Object.prototype.hasOwnProperty.call(c,s)&&f(s)===f(t);if("*"===s.slice(-1)&&(o=f(s.slice(0,-1))===f(t.slice(0,s.length-1))),(l||o)&&(e=c[s],-1<it(n,f(e))))return e}var u=t.split("_");return 1<u.length&&-1<it(n,f(u[0]))?u[0]:void 0}},lt=function(t,e){if(!t&&!e)return q;if(t&&!e){if(angular.isString(t))return q[t]}else angular.isObject(q[t])||(q[t]={}),angular.extend(q[t],ut(e));return this};this.translations=lt,this.cloakClassName=function(t){return t?(Q=t,this):Q},this.nestedObjectDelimeter=function(t){return t?(Z=t,this):Z};var ut=function(t,e,n,a){var r,i,s;for(r in e||(e=[]),n||(n={}),t)Object.prototype.hasOwnProperty.call(t,r)&&(s=t[r],angular.isObject(s)?ut(s,e.concat(r),n,r):(i=e.length?""+e.join(Z)+Z+r:r,e.length&&r===a&&(n[""+e.join(Z)]="@:"+i),n[i]=s));return n};ut.displayName="flatObject",this.addInterpolation=function(t){return J.push(t),this},this.useMessageFormatInterpolation=function(){return this.useInterpolation("$translateMessageFormatInterpolation")},this.useInterpolation=function(t){return R=t,this},this.useSanitizeValueStrategy=function(t){return e.useStrategy(t),this},this.preferredLanguage=function(t){return t?(ct(t),this):T};var ct=function(t){return t&&(T=t),T};this.translationNotFoundIndicator=function(t){return this.translationNotFoundIndicatorLeft(t),this.translationNotFoundIndicatorRight(t),this},this.translationNotFoundIndicatorLeft=function(t){return t?(U=t,this):U},this.translationNotFoundIndicatorRight=function(t){return t?(M=t,this):M},this.fallbackLanguage=function(t){return ft(t),this};var ft=function(t){return t?(angular.isString(t)?(x=!0,z=[t]):angular.isArray(t)&&(x=!1,z=t),angular.isString(T)&&it(z,T)<0&&z.push(T),this):x?z[0]:z};this.use=function(t){if(t){if(!q[t]&&!D)throw new Error("$translateProvider couldn't find translationTable for langKey: '"+t+"'");return F=t,this}return F},this.resolveClientLocale=function(){return rt()};var gt=function(t){return t?(B=t,this):n?n+B:B};this.storageKey=gt,this.useUrlLoader=function(t,e){return this.useLoader("$translateUrlLoader",angular.extend({url:t},e))},this.useStaticFilesLoader=function(t){return this.useLoader("$translateStaticFilesLoader",t)},this.useLoader=function(t,e){return D=t,K=e||{},this},this.useLocalStorage=function(){return this.useStorage("$translateLocalStorage")},this.useCookieStorage=function(){return this.useStorage("$translateCookieStorage")},this.useStorage=function(t){return _=t,this},this.storagePrefix=function(t){return t?(n=t,this):t},this.useMissingTranslationHandlerLog=function(){return this.useMissingTranslationHandler("$translateMissingTranslationHandlerLog")},this.useMissingTranslationHandler=function(t){return V=t,this},this.usePostCompiling=function(t){return W=!!t,this},this.forceAsyncReload=function(t){returnLine truncated
|
||||
@@ -1,6 +1,17 @@
|
||||
angular
|
||||
.module("anonymous-github", ["ngRoute", "ngSanitize"])
|
||||
.config(function($routeProvider, $locationProvider) {
|
||||
.module("anonymous-github", [
|
||||
"ngRoute",
|
||||
"ngSanitize",
|
||||
"pascalprecht.translate",
|
||||
])
|
||||
.config(function($routeProvider, $locationProvider, $translateProvider) {
|
||||
$translateProvider.useStaticFilesLoader({
|
||||
prefix: "/i18n/locale-",
|
||||
suffix: ".json",
|
||||
});
|
||||
|
||||
$translateProvider.preferredLanguage("en");
|
||||
|
||||
$routeProvider
|
||||
.when("/", {
|
||||
templateUrl: "/partials/home.htm",
|
||||
@@ -199,7 +210,8 @@ angular
|
||||
$http,
|
||||
$sce,
|
||||
$routeParams,
|
||||
$location
|
||||
$location,
|
||||
$translate
|
||||
) {
|
||||
$scope.repoUrl = "";
|
||||
$scope.repoId = "";
|
||||
@@ -233,8 +245,11 @@ angular
|
||||
$scope.repoUrl = "https://github.com/" + res.data.fullName;
|
||||
|
||||
$scope.terms = res.data.terms.join("\n");
|
||||
$scope.branch = res.data.branch;
|
||||
$scope.options = res.data.options;
|
||||
$scope.options.expirationDate = new Date(res.data.options.expirationDate);
|
||||
$scope.options.expirationDate = new Date(
|
||||
res.data.options.expirationDate
|
||||
);
|
||||
|
||||
$scope.details = (await $http.get(
|
||||
`/api/repo/${res.data.fullName}/`
|
||||
@@ -301,7 +316,7 @@ angular
|
||||
if ($scope.branches && $scope.branches[$scope.branch]) {
|
||||
$scope.commit = $scope.branches[$scope.branch].commit.sha;
|
||||
}
|
||||
if ($scope.details.has_page) {
|
||||
if ($scope.details && $scope.details.has_page) {
|
||||
$scope.anonymize.page.disabled(false);
|
||||
if ($scope.details.pageSource.branch != $scope.branch) {
|
||||
$scope.anonymize.page.disabled(true);
|
||||
@@ -334,7 +349,9 @@ angular
|
||||
{ params: { force: force === true ? "1" : "0" } }
|
||||
);
|
||||
$scope.branches = branches.data;
|
||||
$scope.branch = $scope.details.default_branch;
|
||||
if (!$scope.branch) {
|
||||
$scope.branch = $scope.details.default_branch;
|
||||
}
|
||||
if ($scope.branches[$scope.branch]) {
|
||||
$scope.commit = $scope.branches[$scope.branch].commit.sha;
|
||||
}
|
||||
@@ -476,6 +493,9 @@ angular
|
||||
window.location.href = "/r/" + $scope.repoId;
|
||||
} catch (error) {
|
||||
if (error.data) {
|
||||
$translate("ERRORS." + error.data.error).then((translation) => {
|
||||
$scope.error = translation;
|
||||
}, console.error);
|
||||
displayErrorMessage(error.data.error);
|
||||
} else {
|
||||
console.error(error);
|
||||
|
||||
+2
-1
@@ -23,6 +23,7 @@ async function anonymizeRepository(options) {
|
||||
console.log("The repository is expired");
|
||||
await repoUtils.updateStatus(repoConfig, "expired");
|
||||
await repoUtils.removeRepository(repoConfig);
|
||||
throw "repository_expired";
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -150,7 +151,7 @@ router.get("/:repoId/file/:path*", async (req, res) => {
|
||||
);
|
||||
return res.sendFile(ppath, { dotfiles: "allow" });
|
||||
} else {
|
||||
return res.status(404).send({ error: "file_not_found" });
|
||||
return res.status(404).json({ error: "file_not_found" });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
+2
-2
@@ -277,7 +277,7 @@ router.post("/", async (req, res) => {
|
||||
if (repoConfig.options.mode == "download") {
|
||||
// details.size is in kilobytes
|
||||
if (details.size > config.MAX_REPO_SIZE) {
|
||||
return res.status(500).send({ error: "invalid_mode" });
|
||||
return res.status(500).send({ error: "non_supported_mode" });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,7 +326,7 @@ router.post("/", async (req, res) => {
|
||||
await repoUtils.updateStatus(repoConfig, "error");
|
||||
return res
|
||||
.status(500)
|
||||
.json({ error: "unable_to_access", message: error.message });
|
||||
.json({ error: "unable_to_anonymize", message: error.message });
|
||||
}
|
||||
res.send("ok");
|
||||
});
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ router.get("/all_repositories", async (req, res) => {
|
||||
{ projection: { repositories: 1 } }
|
||||
);
|
||||
if (!user) {
|
||||
res.status(401).send("User not found");
|
||||
res.status(401).send({error: "user_not_found"});
|
||||
}
|
||||
if (user.repositories && req.query.force !== "1") {
|
||||
return res.json(user.repositories);
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ async function webView(req, res) {
|
||||
console.error(error);
|
||||
return res.status(500).send({ error });
|
||||
}
|
||||
return res.status(404).send("File_not_found");
|
||||
return res.status(404).send("file_not_found");
|
||||
}
|
||||
|
||||
router.get("/:repoId/*", webView);
|
||||
|
||||
+3
-3
@@ -416,13 +416,13 @@ module.exports.isFilePathValid = async (options) => {
|
||||
}
|
||||
if (error.status == 403) {
|
||||
console.log(error);
|
||||
throw "content_too_large";
|
||||
throw "file_too_big";
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
if (!ghRes.data.content && ghRes.data.size != 0) {
|
||||
throw "content_not_accessible";
|
||||
throw "file_not_accessible";
|
||||
}
|
||||
// empty file
|
||||
let content = "";
|
||||
@@ -460,7 +460,7 @@ module.exports.getStats = async (options) => {
|
||||
if (repoConfig == null) {
|
||||
throw "repo_not_found";
|
||||
}
|
||||
if (repoConfig.mode == "stream") {
|
||||
if (repoConfig.mode != "download") {
|
||||
throw "stats_unsupported";
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user