feat: add bark push settings

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei
2024-05-07 14:40:02 +08:00
parent 3f2f36ae2f
commit 784c6cd780
3 changed files with 14 additions and 2 deletions

View File

@@ -38,6 +38,7 @@ export const generateDefaultConfig: () => IConfig = () => ({
key: '',
serverUrl: 'https://api.day.app',
enableComment: true,
enableThrottleGuard: false,
},
friendLinkOptions: { allowApply: true },
backupOptions: {

View File

@@ -295,6 +295,13 @@ export class BarkOptionsDto {
@IsBoolean()
@JSONSchemaToggleField('开启评论通知')
enableComment: boolean
@IsOptional()
@IsBoolean()
@JSONSchemaToggleField('开启请求被限流时通知', {
description: '当请求被限流会通知,或许可以一定程度上预警被攻击',
})
enableThrottleGuard: boolean
}
/**

View File

@@ -31,8 +31,12 @@ export class BarkPushService {
) {}
async push(options: BarkPushOptions) {
const { key, serverUrl = 'https://day.app' } =
await this.config.get('barkOptions')
const {
key,
serverUrl = 'https://day.app',
enableThrottleGuard,
} = await this.config.get('barkOptions')
if (!enableThrottleGuard) return
const { title: siteTitle } = await this.config.get('seo')
if (!key) {
throw new Error('Bark key is not configured')