feat: friend link options
This commit is contained in:
@@ -244,3 +244,11 @@ export class TerminalOptionsDto {
|
||||
@JSONSchemaPlainField('前置脚本')
|
||||
script?: string
|
||||
}
|
||||
|
||||
@JSONSchema({ title: '友链设定' })
|
||||
export class FriendLinkOptionsDto {
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@JSONSchemaToggleField('允许申请友链')
|
||||
allowApply: boolean
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
BackupOptionsDto,
|
||||
BaiduSearchOptionsDto,
|
||||
CommentOptionsDto,
|
||||
FriendLinkOptionsDto,
|
||||
MailOptionsDto,
|
||||
SeoDto,
|
||||
TerminalOptionsDto,
|
||||
@@ -28,6 +29,9 @@ export abstract class IConfig {
|
||||
@Type(() => CommentOptionsDto)
|
||||
@ValidateNested()
|
||||
commentOptions: CommentOptionsDto
|
||||
@Type(() => FriendLinkOptionsDto)
|
||||
@ValidateNested()
|
||||
friendLinkOptions: FriendLinkOptionsDto
|
||||
@Type(() => BackupOptionsDto)
|
||||
@ValidateNested()
|
||||
backupOptions: BackupOptionsDto
|
||||
|
||||
@@ -57,6 +57,7 @@ const generateDefaultConfig: () => IConfig = () => ({
|
||||
},
|
||||
mailOptions: {} as MailOptionsDto,
|
||||
commentOptions: { antiSpam: false },
|
||||
friendLinkOptions: { allowApply: true },
|
||||
backupOptions: { enable: true } as BackupOptionsDto,
|
||||
baiduSearchOptions: { enable: false },
|
||||
algoliaSearchOptions: { enable: false, apiKey: '', appId: '', indexName: '' },
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
ForbiddenException,
|
||||
Get,
|
||||
HttpCode,
|
||||
Param,
|
||||
@@ -9,6 +10,7 @@ import {
|
||||
Query,
|
||||
} from '@nestjs/common'
|
||||
import type mongoose from 'mongoose'
|
||||
import { get } from 'lodash'
|
||||
import { LinkQueryDto } from './link.dto'
|
||||
import { LinkModel, LinkState } from './link.model'
|
||||
import { LinkService } from './link.service'
|
||||
@@ -57,6 +59,13 @@ export class LinkControllerCrud extends BaseCrudFactory({
|
||||
export class LinkController {
|
||||
constructor(private readonly linkService: LinkService) {}
|
||||
|
||||
@Get('/audit')
|
||||
async canApplyLink() {
|
||||
return {
|
||||
can: await this.linkService.canApplyLink(),
|
||||
}
|
||||
}
|
||||
|
||||
@Get('/state')
|
||||
@Auth()
|
||||
async getLinkCount() {
|
||||
@@ -67,6 +76,9 @@ export class LinkController {
|
||||
@Post('/audit')
|
||||
@HttpCode(204)
|
||||
async applyForLink(@Body() body: LinkModel, @Query() query: LinkQueryDto) {
|
||||
if (!(await this.linkService.canApplyLink())) {
|
||||
throw new ForbiddenException('主人目前不允许申请友链了!')
|
||||
}
|
||||
await this.linkService.applyForLink(body)
|
||||
process.nextTick(async () => {
|
||||
await this.linkService.sendToMaster(query.author, body)
|
||||
|
||||
@@ -161,4 +161,10 @@ export class LinkService {
|
||||
|
||||
return health
|
||||
}
|
||||
|
||||
async canApplyLink() {
|
||||
const configs = await this.configs.get('friendLinkOptions')
|
||||
const can = configs.allowApply
|
||||
return can
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user