112 lines
3.3 KiB
JavaScript
112 lines
3.3 KiB
JavaScript
const githubUsernameRegex = require("github-username-regex");
|
|
|
|
exports.validateUsername = function(username) {
|
|
return githubUsernameRegex.test(username);
|
|
}
|
|
|
|
exports.generateString = function(length) {
|
|
var result = "";
|
|
var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
for ( var i = 0; i < length; i++ ) {
|
|
result += characters.charAt(Math.floor(Math.random() * characters.length));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
exports.getType = function(mime) {
|
|
if (mime == "application/javascript") return "text";
|
|
if (
|
|
!mime.startsWith("video") &&
|
|
!mime.startsWith("audio") &&
|
|
!mime.startsWith("image") &&
|
|
!mime == "text/plain" &&
|
|
!mime == "text/html" &&
|
|
!mime == "text/css" &&
|
|
!mime == "text/javascript"
|
|
) return "generic";
|
|
else return mime.split("/")[0];
|
|
}
|
|
|
|
exports.humanSize = function(bytes) {
|
|
var i = bytes == 0 ? 0 : Math.floor(Math.log(bytes) / Math.log(1024));
|
|
return (bytes / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
|
|
}
|
|
|
|
exports.toMessage = function(code) {
|
|
switch(code) {
|
|
case "register":
|
|
return "You`ve successfully registered! You can now log in.";
|
|
case "rejected-delete":
|
|
return "You did not delete the file.";
|
|
case "deleted-file":
|
|
return "File deleted successfully.";
|
|
case "kill-done":
|
|
return "Account deleted successfully.";
|
|
case "promote-done":
|
|
return "Account promoted successfully.";
|
|
case "demote-done":
|
|
return "Account demoted successfully.";
|
|
case "self-delete":
|
|
return "Your account was deleted successfully.";
|
|
case "lifted-block":
|
|
return "The account or IP address was successfully unblocked.";
|
|
case "no-permission":
|
|
return "You do not have permission to do this action.";
|
|
case "done-redacting":
|
|
return "Completed redacting report.";
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
exports.toFullReportString = function(code) {
|
|
switch(code) {
|
|
case "0":
|
|
return "Illegal non-copyrighted content";
|
|
case "1":
|
|
return "DMCA";
|
|
case "2":
|
|
return "Hateful content";
|
|
case "3":
|
|
return "Other type";
|
|
}
|
|
}
|
|
|
|
exports.totalBytes = function(string) {
|
|
return encodeURI(string).split(/%..|./).length - 1;
|
|
}
|
|
|
|
exports.toBlockedStatus = function(string) {
|
|
switch(string) {
|
|
case "all":
|
|
return "this website";
|
|
default:
|
|
return "this page";
|
|
}
|
|
}
|
|
|
|
exports.isBlockedHere = function(blockedString, currentPath) {
|
|
if (blockedString == "all") return true;
|
|
|
|
let blockedFrom = blockedString.split(`|`);
|
|
if (currentPath.split("/").length > 1) currentPath = currentPath.split("/").slice(0, 2).join("/");
|
|
for (let a in blockedFrom) {
|
|
if (blockedFrom[a] == currentPath) return true;
|
|
else continue;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
exports.convertToBlockedStatus = function(object) {
|
|
if (object.site == "on") return "all";
|
|
let string = ``;
|
|
if (object.custom !== "") {
|
|
string = object.custom.split(`\r`).join(``).split(`\n`).join(`|`);
|
|
}
|
|
if (object.login == "on") string = `${string}|/login`;
|
|
if (object.register == "on") string = `${string}|/register|/signup-with-code`;
|
|
if (object.filePages == "on") string = `${string}|/f`;
|
|
if (object.upload == "on") string = `${string}|/upload|/paste`;
|
|
if (object.report == "on") string = `${string}|/report`;
|
|
return string;
|
|
} |