chore: More linting
This commit is contained in:
parent
8e187a947a
commit
a416b8b860
134 changed files with 1041 additions and 1055 deletions
|
@ -7,7 +7,7 @@ import sendEmailWith from './relays'
|
|||
const deliver = sendEmailWith(config.sendEmailWith)
|
||||
const email = {}
|
||||
|
||||
const loadTemplate = (type, format, language='en') => {
|
||||
const loadTemplate = (type, format, language = 'en') => {
|
||||
let template = templates.header[format] + templates[type][format] + templates.footer[format]
|
||||
let toTranslate = templates[type].i18n.concat(templates.footer.i18n)
|
||||
let from = []
|
||||
|
@ -22,7 +22,7 @@ const loadTemplate = (type, format, language='en') => {
|
|||
}
|
||||
|
||||
const replace = (text, from, to) => {
|
||||
for (let id=0; id < from.length; id++) text = text.split(from[id]).join(to[id] || from[id])
|
||||
for (let id = 0; id < from.length; id++) text = text.split(from[id]).join(to[id] || from[id])
|
||||
|
||||
return text
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ email.signup = (recipient, language, id) => {
|
|||
link,
|
||||
i18n[language]['email.signupHeaderOpeningLine'],
|
||||
i18n[language]['email.signupHiddenIntro'],
|
||||
i18n[language]['email.signupWhy']
|
||||
i18n[language]['email.signupWhy'],
|
||||
]
|
||||
html = replace(html, from, to)
|
||||
text = replace(text, from, to)
|
||||
|
@ -45,10 +45,10 @@ email.signup = (recipient, language, id) => {
|
|||
to: recipient,
|
||||
subject: i18n[language]['email.signupSubject'],
|
||||
headers: {
|
||||
'X-Freesewing-Confirmation-ID': '' + id
|
||||
'X-Freesewing-Confirmation-ID': '' + id,
|
||||
},
|
||||
text,
|
||||
html
|
||||
html,
|
||||
}
|
||||
deliver(options, (error, info) => {
|
||||
if (error) return console.log(error)
|
||||
|
@ -68,7 +68,7 @@ email.emailchange = (newAddress, currentAddress, language, id) => {
|
|||
'__hiddenIntro__',
|
||||
'__footerWhy__',
|
||||
'__questionsJustReply__',
|
||||
'__signature__'
|
||||
'__signature__',
|
||||
]
|
||||
let to = [
|
||||
createUrl(language, `/confirm/email/${id}`),
|
||||
|
@ -90,10 +90,10 @@ email.emailchange = (newAddress, currentAddress, language, id) => {
|
|||
cc: currentAddress,
|
||||
subject: i18n[language]['email.emailchangeSubject'],
|
||||
headers: {
|
||||
'X-Freesewing-Confirmation-ID': '' + id
|
||||
'X-Freesewing-Confirmation-ID': '' + id,
|
||||
},
|
||||
text,
|
||||
html
|
||||
html,
|
||||
}
|
||||
deliver(options, (error, info) => {
|
||||
if (error) return console.log(error)
|
||||
|
@ -108,13 +108,13 @@ email.passwordreset = (recipient, language, id) => {
|
|||
'__passwordresetActionLink__',
|
||||
'__headerOpeningLine__',
|
||||
'__hiddenIntro__',
|
||||
'__footerWhy__'
|
||||
'__footerWhy__',
|
||||
]
|
||||
let to = [
|
||||
createUrl(language, `/confirm/reset/${id}`),
|
||||
i18n[language]['email.passwordresetHeaderOpeningLine'],
|
||||
i18n[language]['email.passwordresetHiddenIntro'],
|
||||
i18n[language]['email.passwordresetWhy']
|
||||
i18n[language]['email.passwordresetWhy'],
|
||||
]
|
||||
html = replace(html, from, to)
|
||||
text = replace(text, from, to)
|
||||
|
@ -124,10 +124,10 @@ email.passwordreset = (recipient, language, id) => {
|
|||
to: recipient,
|
||||
subject: i18n[language]['email.passwordresetSubject'],
|
||||
headers: {
|
||||
'X-Freesewing-Confirmation-ID': '' + id
|
||||
'X-Freesewing-Confirmation-ID': '' + id,
|
||||
},
|
||||
text,
|
||||
html
|
||||
html,
|
||||
}
|
||||
deliver(options, (error, info) => {
|
||||
if (error) return console.log(error)
|
||||
|
@ -142,7 +142,7 @@ email.goodbye = async (recipient, language) => {
|
|||
let to = [
|
||||
i18n[language]['email.goodbyeHeaderOpeningLine'],
|
||||
i18n[language]['email.goodbyeHiddenIntro'],
|
||||
i18n[language]['email.goodbyeWhy']
|
||||
i18n[language]['email.goodbyeWhy'],
|
||||
]
|
||||
html = replace(html, from, to)
|
||||
text = replace(text, from, to)
|
||||
|
@ -152,7 +152,7 @@ email.goodbye = async (recipient, language) => {
|
|||
to: recipient,
|
||||
subject: i18n[language]['email.goodbyeSubject'],
|
||||
text,
|
||||
html
|
||||
html,
|
||||
}
|
||||
deliver(options, (error, info) => {
|
||||
if (error) return console.log(error)
|
||||
|
@ -163,12 +163,17 @@ email.goodbye = async (recipient, language) => {
|
|||
email.subscribe = async (recipient, token) => {
|
||||
let html = loadTemplate('newsletterSubscribe', 'html', 'en')
|
||||
let text = loadTemplate('newsletterSubscribe', 'text', 'en')
|
||||
let from = ['__hiddenIntro__', '__headerOpeningLine__', '__newsletterConfirmationLink__', '__footerWhy__']
|
||||
let from = [
|
||||
'__hiddenIntro__',
|
||||
'__headerOpeningLine__',
|
||||
'__newsletterConfirmationLink__',
|
||||
'__footerWhy__',
|
||||
]
|
||||
let to = [
|
||||
'Confirm your subscription to the FreeSewing newsletter',
|
||||
'Please confirm it was you who requested this',
|
||||
`https://backend.freesewing.org/newsletter/confirm/${token}`,
|
||||
`You received this email because somebody tried to subscribe ${recipient} to the FreeSewing newsletter`
|
||||
`You received this email because somebody tried to subscribe ${recipient} to the FreeSewing newsletter`,
|
||||
]
|
||||
html = replace(html, from, to)
|
||||
text = replace(text, from, to)
|
||||
|
@ -178,7 +183,7 @@ email.subscribe = async (recipient, token) => {
|
|||
to: recipient,
|
||||
subject: 'Confirm your subscription to the FreeSewing newsletter',
|
||||
text,
|
||||
html
|
||||
html,
|
||||
}
|
||||
deliver(options, (error, info) => {
|
||||
if (error) return console.log(error)
|
||||
|
@ -189,12 +194,17 @@ email.subscribe = async (recipient, token) => {
|
|||
email.newsletterWelcome = async (recipient, ehash) => {
|
||||
let html = loadTemplate('newsletterWelcome', 'html', 'en')
|
||||
let text = loadTemplate('newsletterWelcome', 'text', 'en')
|
||||
let from = ['__hiddenIntro__', '__headerOpeningLine__', '__newsletterUnsubscribeLink__', '__footerWhy__']
|
||||
let from = [
|
||||
'__hiddenIntro__',
|
||||
'__headerOpeningLine__',
|
||||
'__newsletterUnsubscribeLink__',
|
||||
'__footerWhy__',
|
||||
]
|
||||
let to = [
|
||||
'No action required; This is just an FYI',
|
||||
"You're in. Now what?",
|
||||
`https://backend.freesewing.org/newsletter/unsubscribe/${ehash}`,
|
||||
`You received this email because you subscribed to the FreeSewing newsletter`
|
||||
`You received this email because you subscribed to the FreeSewing newsletter`,
|
||||
]
|
||||
html = replace(html, from, to)
|
||||
text = replace(text, from, to)
|
||||
|
@ -204,7 +214,7 @@ email.newsletterWelcome = async (recipient, ehash) => {
|
|||
to: recipient,
|
||||
subject: 'Welcome to the FreeSewing newsletter',
|
||||
text,
|
||||
html
|
||||
html,
|
||||
}
|
||||
deliver(options, (error, info) => {
|
||||
if (error) return console.log(error)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import smtp from './smtp'
|
||||
//import sendgrid from './sendgrid'
|
||||
|
||||
const sendEmailWith = type => {
|
||||
const sendEmailWith = (type) => {
|
||||
const types = {
|
||||
smtp
|
||||
smtp,
|
||||
//sendgrid,
|
||||
}
|
||||
return types[type]
|
||||
|
|
|
@ -4,13 +4,13 @@ import config from '../../config'
|
|||
sendgrid.setApiKey(config.sendgrid)
|
||||
|
||||
const deliver = (data, callback) => {
|
||||
sendgrid.send(data).then(result => {
|
||||
sendgrid.send(data).then((result) => {
|
||||
// FIXME: This is obviously nonsense
|
||||
if (result[0].statusCode === 202)
|
||||
callback(false, {
|
||||
from: data.from,
|
||||
to: data.to,
|
||||
subject: data.subject
|
||||
subject: data.subject,
|
||||
})
|
||||
else callback(true, 'Sending via SendGridfailed')
|
||||
})
|
||||
|
|
|
@ -7,8 +7,8 @@ const transporter = nodemailer.createTransport({
|
|||
secure: false, // Only needed or SSL, not for TLS
|
||||
auth: {
|
||||
user: config.smtp.user,
|
||||
pass: config.smtp.pass
|
||||
}
|
||||
pass: config.smtp.pass,
|
||||
},
|
||||
})
|
||||
|
||||
const deliver = (data, callback) => {
|
||||
|
|
|
@ -12,7 +12,7 @@ import avatar from '../templates/avatar'
|
|||
export const email = mailer
|
||||
export const log = logger
|
||||
|
||||
export const capitalize = string => string.charAt(0).toUpperCase() + string.slice(1)
|
||||
export const capitalize = (string) => string.charAt(0).toUpperCase() + string.slice(1)
|
||||
|
||||
export const createUrl = (language, path) => {
|
||||
// Handle development mode
|
||||
|
@ -20,27 +20,27 @@ export const createUrl = (language, path) => {
|
|||
else return config.website.scheme + '://' + language + '.' + config.website.domain + path
|
||||
}
|
||||
|
||||
export const getHash = email => {
|
||||
export const getHash = (email) => {
|
||||
let hash = crypto.createHash('sha256')
|
||||
hash.update(clean(email))
|
||||
return hash.digest('hex')
|
||||
}
|
||||
|
||||
export const clean = email => email.toLowerCase().trim()
|
||||
export const clean = (email) => email.toLowerCase().trim()
|
||||
|
||||
export const getToken = account => {
|
||||
export const getToken = (account) => {
|
||||
return jwt.sign(
|
||||
{
|
||||
_id: account._id,
|
||||
handle: account.handle,
|
||||
aud: config.jwt.audience,
|
||||
iss: config.jwt.issuer
|
||||
iss: config.jwt.issuer,
|
||||
},
|
||||
config.jwt.secretOrKey
|
||||
)
|
||||
}
|
||||
|
||||
export const getHandle = type => {
|
||||
export const getHandle = (type) => {
|
||||
let go, handle, exists
|
||||
if (type === 'person') go = Person
|
||||
else if (type === 'pattern') go = Pattern
|
||||
|
@ -65,7 +65,7 @@ export const createHandle = (length = 5) => {
|
|||
return handle
|
||||
}
|
||||
|
||||
export const imageType = contentType => {
|
||||
export const imageType = (contentType) => {
|
||||
if (contentType === 'image/png') return 'png'
|
||||
if (contentType === 'image/jpeg') return 'jpg'
|
||||
if (contentType === 'image/gif') return 'gif'
|
||||
|
@ -74,7 +74,7 @@ export const imageType = contentType => {
|
|||
}
|
||||
|
||||
export const saveAvatarFromBase64 = (data, handle, type) => {
|
||||
fs.mkdir(userStoragePath(handle), { recursive: true }, err => {
|
||||
fs.mkdir(userStoragePath(handle), { recursive: true }, (err) => {
|
||||
if (err) log.error('mkdirFailed', err)
|
||||
let imgBuffer = Buffer.from(data, 'base64')
|
||||
for (let size of Object.keys(config.avatar.sizes)) {
|
||||
|
@ -98,7 +98,7 @@ export const randomColor = () => (0x1000000 + Math.random() * 0xffffff).toString
|
|||
export const randomAvatar = () =>
|
||||
avatar.replace('000000', randomColor()).replace('FFFFFF', randomColor())
|
||||
|
||||
export const ehash = email => {
|
||||
export const ehash = (email) => {
|
||||
let hash = crypto.createHash('sha256')
|
||||
hash.update(clean(email))
|
||||
return hash.digest('hex')
|
||||
|
@ -126,14 +126,14 @@ export const uniqueHandle = () => {
|
|||
return handle
|
||||
}
|
||||
|
||||
export const userStoragePath = handle =>
|
||||
export const userStoragePath = (handle) =>
|
||||
path.join(config.storage, 'users', handle.substring(0, 1), handle)
|
||||
|
||||
export const createAvatar = handle => {
|
||||
export const createAvatar = (handle) => {
|
||||
let dir = userStoragePath(handle)
|
||||
fs.mkdir(dir, { recursive: true }, err => {
|
||||
fs.mkdir(dir, { recursive: true }, (err) => {
|
||||
if (err) console.log('mkdirFailed', dir, err)
|
||||
fs.writeFile(path.join(dir, handle) + '.svg', randomAvatar(), err => {
|
||||
fs.writeFile(path.join(dir, handle) + '.svg', randomAvatar(), (err) => {
|
||||
if (err) console.log('writeFileFailed', dir, err)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue