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

@@ -1,5 +1,11 @@
# CHANGE LOG
## main branch
- 修复 Admin 删除邮件报错
- UI: 回复邮件按钮, 引用原始邮件文本
- 添加发送邮件地址黑名单
## v0.3.2
## What's Changed

View File

@@ -16,22 +16,26 @@ const { t } = useI18n({
successTip: 'Save Success',
address_block_list: 'Address Block Keywords for Users(Admin can skip)',
address_block_list_placeholder: 'Please enter the keywords you want to block',
send_address_block_list: 'Address Block Keywords for send email',
},
zh: {
save: '保存',
successTip: '保存成功',
address_block_list: '用户地址屏蔽关键词(管理员可跳过检查)',
address_block_list_placeholder: '请输入您想要屏蔽的关键词',
send_address_block_list: '发送邮件地址屏蔽关键词',
}
}
});
const addressBlockList = ref([])
const sendAddressBlockList = ref([])
const fetchData = async () => {
try {
const res = await api.fetch(`/admin/account_settings`)
addressBlockList.value = res.blockList || []
sendAddressBlockList.value = res.sendBlockList || []
} catch (error) {
message.error(error.message || "error");
}
@@ -42,7 +46,8 @@ const save = async () => {
await api.fetch(`/admin/account_settings`, {
method: 'POST',
body: JSON.stringify({
blockList: addressBlockList.value || []
blockList: addressBlockList.value || [],
sendBlockList: sendAddressBlockList.value || []
})
})
message.success(t('successTip'))
@@ -64,6 +69,10 @@ onMounted(async () => {
<n-select v-model:value="addressBlockList" filterable multiple tag
:placeholder="t('address_block_list_placeholder')" />
</n-form-item-row>
<n-form-item-row :label="t('send_address_block_list')">
<n-select v-model:value="sendAddressBlockList" filterable multiple tag
:placeholder="t('address_block_list_placeholder')" />
</n-form-item-row>
<n-button @click="save" type="primary" block :loading="loading">
{{ t('save') }}
</n-button>

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