Skip to content

Commit 35b8522

Browse files
committed
feat: update
1 parent 48e5b94 commit 35b8522

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

server/src/queues/mail.queue.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,37 @@ export class SendMailQueue extends Queue {
1313
})
1414
}
1515

16-
async addJob(data: Parameters<typeof sendMail>[0]) {
17-
const lastSubmissionTime = await redis.get(`send-email:${data.to}`)
18-
const currentTime = new Date().getTime()
19-
if (
20-
lastSubmissionTime &&
21-
currentTime - parseInt(lastSubmissionTime) < 60 * 1000
22-
) {
23-
throw new HttpException(429, 'You can only send email once per minute')
16+
async addJob({
17+
isPreventSpam = true,
18+
...data
19+
}: Parameters<typeof sendMail>[0] & {
20+
isPreventSpam?: boolean
21+
}) {
22+
if (isPreventSpam) {
23+
const lastSubmissionTime = await redis.get(`send-email:${data.to}`)
24+
const currentTime = new Date().getTime()
25+
if (
26+
lastSubmissionTime &&
27+
currentTime - parseInt(lastSubmissionTime) < 60 * 1000
28+
) {
29+
throw new HttpException(429, 'You can only send email once per minute')
30+
}
2431
}
2532

2633
const job = await this.add('send-mail', data, {
27-
attempts: 3,
34+
attempts: 1,
2835
backoff: {
2936
type: 'exponential',
3037
delay: 1000,
3138
},
32-
removeOnComplete: true,
33-
removeOnFail: true,
3439
})
3540

36-
await redis.set(`send-email:${data.to}`, currentTime.toString(), 'EX', 60)
41+
await redis.set(
42+
`send-email:${data.to}`,
43+
new Date().getTime().toString(),
44+
'EX',
45+
60,
46+
)
3747

3848
return job
3949
}

server/src/services/bot-mail.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export class BotMailService {
4141
template: template as any,
4242
pass: password,
4343
user: email,
44+
isPreventSpam: false,
4445
})
4546
}
4647
}

0 commit comments

Comments
 (0)