|
|
@@ -11,10 +11,7 @@ const knexUtils = require("./knex");
|
|
|
const knex = require("../knex");
|
|
|
const env = require("../env");
|
|
|
|
|
|
-const nanoid = customAlphabet(
|
|
|
- "abcdefghkmnpqrstuvwxyzABCDEFGHKLMNPQRSTUVWXYZ23456789",
|
|
|
- env.LINK_LENGTH
|
|
|
-);
|
|
|
+const nanoid = customAlphabet(env.LINK_CUSTOM_ALPHABET, env.LINK_LENGTH);
|
|
|
|
|
|
class CustomError extends Error {
|
|
|
constructor(message, statusCode, data) {
|
|
|
@@ -27,6 +24,12 @@ class CustomError extends Error {
|
|
|
|
|
|
const urlRegex = /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i;
|
|
|
|
|
|
+const charsNeedEscapeInRegExp = ".$*+?()[]{}|^-";
|
|
|
+const customAlphabetEscaped = env.LINK_CUSTOM_ALPHABET
|
|
|
+ .split("").map(c => charsNeedEscapeInRegExp.includes(c) ? "\\" + c : c).join("");
|
|
|
+const customAlphabetRegex = new RegExp(`^[${customAlphabetEscaped}_-]+$`);
|
|
|
+const customAddressRegex = new RegExp("^[a-zA-Z0-9-_]+$");
|
|
|
+
|
|
|
function isAdmin(user) {
|
|
|
return user.role === ROLES.ADMIN;
|
|
|
}
|
|
|
@@ -390,6 +393,8 @@ function getCustomCSSFileNames() {
|
|
|
|
|
|
module.exports = {
|
|
|
addProtocol,
|
|
|
+ customAddressRegex,
|
|
|
+ customAlphabetRegex,
|
|
|
CustomError,
|
|
|
dateToUTC,
|
|
|
deleteCurrentToken,
|