Work in progress on subscriptions
This commit is contained in:
parent
eecb3cd067
commit
b22a87e712
18 changed files with 1729 additions and 884 deletions
41
lib/tools.js
41
lib/tools.js
|
@ -18,9 +18,6 @@ let htmlToText = require('html-to-text');
|
|||
let blockedUsers = ['abuse', 'admin', 'billing', 'compliance', 'devnull', 'dns', 'ftp', 'hostmaster', 'inoc', 'ispfeedback', 'ispsupport', 'listrequest', 'list', 'maildaemon', 'noc', 'noreply', 'noreply', 'null', 'phish', 'phishing', 'postmaster', 'privacy', 'registrar', 'root', 'security', 'spam', 'support', 'sysadmin', 'tech', 'undisclosedrecipients', 'unsubscribe', 'usenet', 'uucp', 'webmaster', 'www'];
|
||||
|
||||
module.exports = {
|
||||
toDbKey,
|
||||
fromDbKey,
|
||||
convertKeys,
|
||||
queryParams,
|
||||
createSlug,
|
||||
updateMenu,
|
||||
|
@ -33,42 +30,6 @@ module.exports = {
|
|||
workers: new Set()
|
||||
};
|
||||
|
||||
function toDbKey(key) {
|
||||
return key.
|
||||
replace(/[^a-z0-9\-_]/gi, '').
|
||||
replace(/-+/g, '_').
|
||||
replace(/[A-Z]/g, c => '_' + c.toLowerCase()).
|
||||
replace(/^_+|_+$/g, '').
|
||||
replace(/_+/g, '_').
|
||||
trim();
|
||||
}
|
||||
|
||||
function fromDbKey(key) {
|
||||
let prefix = '';
|
||||
if (key.startsWith('_')) {
|
||||
key = key.substring(1);
|
||||
prefix = '_';
|
||||
|
||||
}
|
||||
return prefix + key.replace(/[_-]([a-z])/g, (m, c) => c.toUpperCase());
|
||||
}
|
||||
|
||||
function convertKeys(obj, options) {
|
||||
options = options || {};
|
||||
let response = {};
|
||||
Object.keys(obj || {}).forEach(key => {
|
||||
let lKey = fromDbKey(key);
|
||||
if (options.skip && options.skip.indexOf(lKey) >= 0) {
|
||||
return;
|
||||
}
|
||||
if (options.keep && options.keep.indexOf(lKey) < 0) {
|
||||
return;
|
||||
}
|
||||
response[lKey] = obj[key];
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
function queryParams(obj) {
|
||||
return Object.keys(obj).
|
||||
filter(key => key !== '_csrf').
|
||||
|
@ -116,6 +77,7 @@ function createSlug(table, name, callback) {
|
|||
});
|
||||
}
|
||||
|
||||
// FIXME - remove once we fully manage the menu in the client
|
||||
function updateMenu(res) {
|
||||
if (!res.locals.menu) {
|
||||
res.locals.menu = [];
|
||||
|
@ -148,6 +110,7 @@ function updateMenu(res) {
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME - either remove of delegate to validateEmail in tools-async (or vice-versa)
|
||||
function validateEmail(address, checkBlocked, callback) {
|
||||
let user = (address || '').toString().split('@').shift().toLowerCase().replace(/[^a-z0-9]/g, '');
|
||||
if (checkBlocked && blockedUsers.indexOf(user) >= 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue