@@ -18,6 +18,7 @@ import { HTTP_REQUEST_TIME } from '~/constants/meta.constant'
|
||||
import { LOG_DIR } from '~/constants/path.constant'
|
||||
import { REFLECTOR } from '~/constants/system.constant'
|
||||
import { isDev } from '~/global/env.global'
|
||||
import { ConfigsService } from '~/modules/configs/configs.service'
|
||||
import { BarkPushService } from '~/processors/helper/helper.bark.service'
|
||||
import { EventManagerService } from '~/processors/helper/helper.event.service'
|
||||
|
||||
@@ -41,6 +42,7 @@ export class AllExceptionsFilter implements ExceptionFilter {
|
||||
@Inject(REFLECTOR) private reflector: Reflector,
|
||||
private readonly eventManager: EventManagerService,
|
||||
private readonly barkService: BarkPushService,
|
||||
private readonly configService: ConfigsService,
|
||||
) {
|
||||
this.registerCatchAllExceptionsHook()
|
||||
}
|
||||
@@ -88,10 +90,14 @@ export class AllExceptionsFilter implements ExceptionFilter {
|
||||
const url = request.raw?.url || request.url || 'Unknown URL'
|
||||
if (status === HttpStatus.TOO_MANY_REQUESTS) {
|
||||
this.logger.warn(`IP: ${ip} 疑似遭到攻击 Path: ${decodeURI(url)}`)
|
||||
this.barkService.throttlePush({
|
||||
title: '疑似遭到攻击',
|
||||
body: `IP: ${ip} Path: ${decodeURI(url)}`,
|
||||
})
|
||||
|
||||
const { enableThrottleGuard } =
|
||||
await this.configService.get('barkOptions')
|
||||
if (enableThrottleGuard)
|
||||
this.barkService.throttlePush({
|
||||
title: '疑似遭到攻击',
|
||||
body: `IP: ${ip} Path: ${decodeURI(url)}`,
|
||||
})
|
||||
|
||||
return response.status(429).send({
|
||||
message: '请求过于频繁,请稍后再试',
|
||||
|
||||
@@ -590,10 +590,14 @@ export class CommentService implements OnModuleInit {
|
||||
// push comment
|
||||
@OnEvent(BusinessEvents.COMMENT_CREATE)
|
||||
async pushCommentEvent(comment: CommentModel) {
|
||||
const { enable } = await this.configsService.get('barkOptions')
|
||||
const { enable, enableComment } =
|
||||
await this.configsService.get('barkOptions')
|
||||
if (!enable) {
|
||||
return
|
||||
}
|
||||
if (!enableComment) {
|
||||
return
|
||||
}
|
||||
const master = await this.userService.getMaster()
|
||||
if (comment.author == master.name && comment.author == master.username) {
|
||||
return
|
||||
|
||||
@@ -31,12 +31,9 @@ export class BarkPushService {
|
||||
) {}
|
||||
|
||||
async push(options: BarkPushOptions) {
|
||||
const {
|
||||
key,
|
||||
serverUrl = 'https://day.app',
|
||||
enableThrottleGuard,
|
||||
} = await this.config.get('barkOptions')
|
||||
if (!enableThrottleGuard) return
|
||||
const { key, serverUrl = 'https://day.app' } =
|
||||
await this.config.get('barkOptions')
|
||||
|
||||
const { title: siteTitle } = await this.config.get('seo')
|
||||
if (!key) {
|
||||
throw new Error('Bark key is not configured')
|
||||
|
||||
Reference in New Issue
Block a user