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