feat: add sendBlockList (#198)

This commit is contained in:
Dream Hunter
2024-05-04 18:37:28 +08:00
committed by GitHub
parent 7f456078ea
commit 4d6c4e2d10
5 changed files with 35 additions and 6 deletions

View File

@@ -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
})

View File

@@ -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',
}

View File

@@ -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) {