wip(backend): Working on migration of user data
This commit is contained in:
parent
0b441eed58
commit
550830310c
18 changed files with 734 additions and 79 deletions
56
scripts/email-lib.mjs
Normal file
56
scripts/email-lib.mjs
Normal file
|
@ -0,0 +1,56 @@
|
|||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import { SESv2Client, SendEmailCommand } from '@aws-sdk/client-sesv2'
|
||||
|
||||
// Current working directory
|
||||
const cwd = path.dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
export const send = async ({
|
||||
to = ['joost@joost.at'],
|
||||
bcc = [],
|
||||
subject = false,
|
||||
html = false,
|
||||
text = false,
|
||||
}) => {
|
||||
if (!subject || !html || !text) return console.log('No subject, html, or text provided')
|
||||
|
||||
const us = 'Joost from FreeSewing <info@freesewing.org>'
|
||||
|
||||
// Oh AWS your APIs are such a clusterfuck
|
||||
const client = new SESv2Client({ region: 'us-east-1' })
|
||||
|
||||
// Via API
|
||||
const command = new SendEmailCommand({
|
||||
ConfigurationSetName: 'backend',
|
||||
Content: {
|
||||
Simple: {
|
||||
Body: {
|
||||
Text: {
|
||||
Charset: 'utf-8',
|
||||
Data: text,
|
||||
},
|
||||
Html: {
|
||||
Charset: 'utf-8',
|
||||
Data: html,
|
||||
},
|
||||
},
|
||||
Subject: {
|
||||
Charset: 'utf-8',
|
||||
Data: subject,
|
||||
},
|
||||
},
|
||||
},
|
||||
Destination: {
|
||||
ToAddresses: to,
|
||||
BccAddresses: to,
|
||||
},
|
||||
FromEmailAddress: us,
|
||||
})
|
||||
try {
|
||||
const result = await client.send(command)
|
||||
console.log(result)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
return false
|
||||
}
|
||||
}
|
96
scripts/send-real-email.mjs
Normal file
96
scripts/send-real-email.mjs
Normal file
|
@ -0,0 +1,96 @@
|
|||
import 'dotenv/config'
|
||||
import mustache from 'mustache'
|
||||
import { send } from './email-lib.mjs'
|
||||
import {
|
||||
buttonRow,
|
||||
newsletterClosingRow,
|
||||
headingRow,
|
||||
lead1Row,
|
||||
wrap,
|
||||
} from '../sites/backend/src/templates/email/shared/blocks.mjs'
|
||||
import users from '../sites/backend/dump/inactive.json' assert { type: 'json' }
|
||||
|
||||
const splitArray = (split, batchSize) =>
|
||||
split.reduce((result, item, index) => {
|
||||
const batchIndex = Math.floor(index / batchSize)
|
||||
if (!result[batchIndex]) result[batchIndex] = []
|
||||
result[batchIndex].push(item)
|
||||
|
||||
return result
|
||||
}, [])
|
||||
|
||||
const text = `
|
||||
Dear FreeSewing user,
|
||||
|
||||
Your account on FreeSewing.org has been inactive an scheduled for removal.
|
||||
|
||||
If you want to keep your account, please login on FreeSewing.org within the next 2 weeks.
|
||||
|
||||
If your account stays dormant, it will at one point become unavailable.
|
||||
That does not have to be a disaster, you can always create a new one, but you will loose all data stored in your account.
|
||||
|
||||
This will be the only email I sent you about this.
|
||||
If you have questions, you can reply to this message.
|
||||
|
||||
love,
|
||||
joost
|
||||
`
|
||||
const html = mustache.render(
|
||||
wrap.html(`
|
||||
${headingRow.html}
|
||||
${lead1Row.html}
|
||||
${buttonRow.html}
|
||||
${newsletterClosingRow.html}
|
||||
`),
|
||||
{
|
||||
intro: 'Your account is inactive. Login now to revive it.',
|
||||
heading: 'Your FreeSewing account is inactive and marked for removal',
|
||||
lead: `
|
||||
Due to inactivity, your account on FreeSewing.org has been marked for removal.
|
||||
<br><br>
|
||||
If you want to keep your account, please login on FreeSewing.org within the next 2 weeks.`,
|
||||
button: 'Go to FreeSewing.org',
|
||||
actionUrl: 'https://freesewing.org/login',
|
||||
closing: `
|
||||
If your account stays dormant, it will at one point become unavailable.
|
||||
<br><br>
|
||||
That does not have to be a disaster, you can always create a new one, but you will loose all data stored in your account.
|
||||
<br><br>
|
||||
This will be the only email I sent you about this.
|
||||
<br>
|
||||
If you have questions, you can reply to this message.`,
|
||||
|
||||
greeting: `love,`,
|
||||
website: 'FreeSewing.org',
|
||||
seeWhy: 'You received this email because removing inactive accounts is in line with our',
|
||||
urlWhy: 'https://freesewing.org/docs/various/privacy/account/',
|
||||
whyDidIGetThis: 'Privacy Notice',
|
||||
notMarketing: 'This is not marketing, but a transactional email about your FreeSewing account.',
|
||||
}
|
||||
)
|
||||
|
||||
/*
|
||||
* AWS limit is 50 recipients.
|
||||
* So rather than send a bunch of individual emails,
|
||||
* let's send it to ourselves * and put 45 people in BCC
|
||||
*/
|
||||
const batches = splitArray(users, 45)
|
||||
|
||||
let i = 0
|
||||
const total = batches.length
|
||||
batches.forEach((batch, i) => {
|
||||
/*
|
||||
* Maximum email rate is 14 messages per second
|
||||
* So we can't go too fast
|
||||
*/
|
||||
setTimeout(() => {
|
||||
console.log(`Sending ${i}/${total}`)
|
||||
send({
|
||||
to: ['info@freesewing.org'],
|
||||
bcc: batch,
|
||||
subject: '[FreeSewing] Your account is inactive and marked for removal',
|
||||
html,
|
||||
text,
|
||||
})
|
||||
}, i * 100)
|
||||
})
|
68
scripts/send-test-email.mjs
Normal file
68
scripts/send-test-email.mjs
Normal file
|
@ -0,0 +1,68 @@
|
|||
import 'dotenv/config'
|
||||
import mustache from 'mustache'
|
||||
import { send } from './email-lib.mjs'
|
||||
import {
|
||||
buttonRow,
|
||||
newsletterClosingRow,
|
||||
headingRow,
|
||||
lead1Row,
|
||||
wrap,
|
||||
} from '../sites/backend/src/templates/email/shared/blocks.mjs'
|
||||
|
||||
const text = `
|
||||
Dear FreeSewing user,
|
||||
|
||||
Your account on FreeSewing.org has been inactive an scheduled for removal.
|
||||
|
||||
If you want to keep your account, please login on FreeSewing.org within the next 2 weeks.
|
||||
|
||||
If your account stays dormant, it will at one point become unavailable.
|
||||
That does not have to be a disaster, you can always create a new one, but you will loose all data stored in your account.
|
||||
|
||||
This will be the only email I sent you about this.
|
||||
If you have questions, you can reply to this message.
|
||||
|
||||
love,
|
||||
joost
|
||||
`
|
||||
const html = mustache.render(
|
||||
wrap.html(`
|
||||
${headingRow.html}
|
||||
${lead1Row.html}
|
||||
${buttonRow.html}
|
||||
${newsletterClosingRow.html}
|
||||
`),
|
||||
{
|
||||
intro: 'Your account is inactive. Login now to revive it.',
|
||||
heading: 'Your FreeSewing account is inactive and marked for removal',
|
||||
lead: `
|
||||
Due to inactivity, your account on FreeSewing.org has been marked for removal.
|
||||
<br><br>
|
||||
If you want to keep your account, please login on FreeSewing.org within the next 2 weeks.`,
|
||||
button: 'Go to FreeSewing.org',
|
||||
actionUrl: 'https://freesewing.org/login',
|
||||
closing: `
|
||||
If your account stays dormant, it will at one point become unavailable.
|
||||
<br><br>
|
||||
That does not have to be a disaster, you can always create a new one, but you will loose all data stored in your account.
|
||||
<br><br>
|
||||
This will be the only email I sent you about this.
|
||||
<br>
|
||||
If you have questions, you can reply to this message.`,
|
||||
|
||||
greeting: `love,`,
|
||||
website: 'FreeSewing.org',
|
||||
seeWhy: 'You received this email because removing inactive accounts is in line with our',
|
||||
urlWhy: 'https://freesewing.org/docs/various/privacy/account/',
|
||||
whyDidIGetThis: 'Privacy Notice',
|
||||
notMarketing: 'This is not marketing, but a transactional email about your FreeSewing account.',
|
||||
}
|
||||
)
|
||||
|
||||
send({
|
||||
to: ['nidhubhs@gmail.com'],
|
||||
bcc: ['joost@joost.at', 'joost@decock.org'],
|
||||
subject: '[FreeSewing] Your account is inactive and marked for removal',
|
||||
html,
|
||||
text,
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue