mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-07-03 05:11:57 +08:00
feat: add sendBlockList (#198)
This commit is contained in:
@@ -303,9 +303,11 @@ api.post('/admin/auto_cleanup', cleanup_api.saveCleanup)
|
||||
|
||||
api.get('/admin/account_settings', async (c) => {
|
||||
try {
|
||||
const value = await getJsonSetting(c, CONSTANTS.ADDRESS_BLOCK_LIST_KEY);
|
||||
const blockList = await getJsonSetting(c, CONSTANTS.ADDRESS_BLOCK_LIST_KEY);
|
||||
const sendBlockList = await getJsonSetting(c, CONSTANTS.SEND_BLOCK_LIST_KEY);
|
||||
return c.json({
|
||||
blockList: value || []
|
||||
blockList: blockList || [],
|
||||
sendBlockList: sendBlockList || []
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -314,14 +316,18 @@ api.get('/admin/account_settings', async (c) => {
|
||||
})
|
||||
|
||||
api.post('/admin/account_settings', async (c) => {
|
||||
const { blockList } = await c.req.json();
|
||||
if (!blockList) {
|
||||
return c.text("Invalid blockList", 400)
|
||||
const { blockList, sendBlockList } = await c.req.json();
|
||||
if (!blockList || !sendBlockList) {
|
||||
return c.text("Invalid blockList or sendBlockList", 400)
|
||||
}
|
||||
await saveSetting(
|
||||
c, CONSTANTS.ADDRESS_BLOCK_LIST_KEY,
|
||||
JSON.stringify(blockList)
|
||||
);
|
||||
await saveSetting(
|
||||
c, CONSTANTS.SEND_BLOCK_LIST_KEY,
|
||||
JSON.stringify(sendBlockList)
|
||||
);
|
||||
return c.json({
|
||||
success: true
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export const CONSTANTS = {
|
||||
ADDRESS_BLOCK_LIST_KEY: 'address_block_list',
|
||||
SEND_BLOCK_LIST_KEY: 'send_block_list',
|
||||
AUTO_CLEANUP_KEY: 'auto_cleanup',
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { Hono } from 'hono'
|
||||
import { CONSTANTS } from './constants'
|
||||
import { getJsonSetting } from './utils';
|
||||
|
||||
const api = new Hono()
|
||||
|
||||
@@ -47,6 +49,11 @@ api.post('/api/send_mail', async (c) => {
|
||||
if (!to_mail) {
|
||||
return c.text("Invalid to mail", 400)
|
||||
}
|
||||
// check SEND_BLOCK_LIST_KEY
|
||||
const sendBlockList = await getJsonSetting(c, CONSTANTS.SEND_BLOCK_LIST_KEY);
|
||||
if (sendBlockList && sendBlockList.some((item) => to_mail.includes(item))) {
|
||||
return c.text("to_mail address is blocked", 400);
|
||||
}
|
||||
from_name = from_name || address;
|
||||
to_name = to_name || to_mail;
|
||||
if (!subject) {
|
||||
|
||||
Reference in New Issue
Block a user