Reemplace shortid with nanoid in background with alphabet and length configurable #810
This commit is contained in:
parent
aed115a64b
commit
8b900c94ba
3 changed files with 32 additions and 0 deletions
|
@ -55,6 +55,10 @@ enabledLanguages:
|
|||
# Inject custom scripts in subscription/layout.mjml.hbs
|
||||
# customSubscriptionScripts: [/custom/hello-world.js]
|
||||
|
||||
# Customize the random string generation for cid
|
||||
cid:
|
||||
alphabet: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
length: 10
|
||||
|
||||
# Enable to use Redis session cache or disable if Redis is not installed
|
||||
redis:
|
||||
|
|
27
server/lib/shortid.js
Normal file
27
server/lib/shortid.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
"use strict";
|
||||
|
||||
// Modules
|
||||
const nanoid = require('nanoid');
|
||||
const config = require('./config');
|
||||
|
||||
// Default hardcoded values
|
||||
let alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
let customlength = 10;
|
||||
|
||||
// Gets from config if defined
|
||||
if (config.cid && config.cid.alphabet) alphabet=config.cid.alphabet;
|
||||
if (config.cid && config.cid.length) customlength=config.cid.length;
|
||||
|
||||
// Create custom nanoid
|
||||
const customnanoid = nanoid.customAlphabet(alphabet, customlength);
|
||||
|
||||
const re = new RegExp('['+alphabet+']{'+customlength+'}');
|
||||
|
||||
// Implements the public methods of shortid module with nanoid and export them
|
||||
module.exports.generate = function() {
|
||||
return customnanoid();
|
||||
}
|
||||
|
||||
module.exports.isValid = function(id) {
|
||||
return re.test(id);
|
||||
}
|
|
@ -91,6 +91,7 @@
|
|||
"morgan": "^1.9.1",
|
||||
"multer": "^1.4.2",
|
||||
"mysql": "^2.17.1",
|
||||
"nanoid": "^3.1.12",
|
||||
"node-ipc": "^9.1.1",
|
||||
"node-mocks-http": "^1.8.1",
|
||||
"node-object-hash": "^1.4.1",
|
||||
|
|
Loading…
Reference in a new issue