diff --git a/app.js b/app.js index 1405200..929fe52 100644 --- a/app.js +++ b/app.js @@ -93,9 +93,9 @@ const wss = new WebSocket.Server({ clientTracking: false, noServer: true }) // Rate limits const emlLimiter = rateLimit({ - windowMs: 1000 * 60 * 60 * 24, - max: 5, - message: 'Too many subscription attempts from this IP address. Try again in 24 hours.' + windowMs: 1000 * 60 * 60, + max: 16, + message: 'Too many subscription attempts from this IP address. Try again in an hour.' }) // Authentication @@ -132,23 +132,23 @@ async function sendEmailPush(channel) { return } const db = await dbPromise - const { name } = await db.get('SELECT name FROM channels WHERE user_uuid = ?', channel) - if (!name) { + const data = await db.get('SELECT name FROM channels WHERE user_uuid = ?', channel) + if (!data) { return; } const subs = await db.all('SELECT email,unsubkey FROM emailsub WHERE uuid = ? AND active = 1', channel); for (const sub of subs) { const unsubURL = config.Email.baseURL + 'unsubscribe/' + sub.unsubkey - const watchURL = config.Email.baseURL + 'watch/' + name + const watchURL = config.Email.baseURL + 'watch/' + data.name emailTransport.sendMail({ from: config.Email.from, to: sub.email, - subject: `🔴 ${name} has gone LIVE on IcyTV!`, - text: `${name} has gone LIVE on IcyTV!\nWatch now: ${watchURL}` - + `\n\nUnsubscribe from ${name}: ${unsubURL}`, - html: `

${name} has gone LIVE on IcyTV!

Watch now: ` + subject: `🔴 ${data.name} has gone LIVE on IcyTV!`, + text: `${data.name} has gone LIVE on IcyTV!\nWatch now: ${watchURL}` + + `\n\nUnsubscribe from ${data.name}: ${unsubURL}`, + html: `

${data.name} has gone LIVE on IcyTV!

Watch now: ` + `${watchURL}` - + `


Unsubscribe from ${name}: ` + + `


Unsubscribe from ${data.name}: ` + `${unsubURL}

`, }).catch(e => console.error(e)) } @@ -160,12 +160,12 @@ async function subscribeToChannel(channel, email) { } const db = await dbPromise - const { user_uuid } = await db.get('SELECT user_uuid FROM channels WHERE name = ?', channel) - if (!user_uuid) { + const data = await db.get('SELECT user_uuid FROM channels WHERE name = ?', channel) + if (!data) { throw new Error('Invalid channel!') } - const exists = await db.get('SELECT * FROM emailsub WHERE email = ? AND uuid = ?', [email, user_uuid]) + const exists = await db.get('SELECT * FROM emailsub WHERE email = ? AND uuid = ?', [email, data.user_uuid]) if (exists) { throw new Error('A subscription already exists for this email address.') } @@ -175,7 +175,7 @@ async function subscribeToChannel(channel, email) { const unsubKey = key() const activateURL = config.Email.baseURL + 'email/' + activateKey await db.run('INSERT INTO emailsub (unsubkey, activatekey, email, uuid, active, created_at) VALUES ' - + '(?, ?, ?, ?, 0, ?)', [unsubKey, activateKey, email, user_uuid, now()]) + + '(?, ?, ?, ?, 0, ?)', [unsubKey, activateKey, email, data.user_uuid, now()]) await emailTransport.sendMail({ from: config.Email.from,