fix: config patch
This commit is contained in:
59
src/modules/configs/configs.default.ts
Normal file
59
src/modules/configs/configs.default.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { isInDemoMode } from '~/app.config'
|
||||
|
||||
import { IConfig } from './configs.interface'
|
||||
|
||||
export const generateDefaultConfig: () => IConfig = () => ({
|
||||
seo: {
|
||||
title: '我的小世界呀',
|
||||
description: '哈喽~欢迎光临',
|
||||
keywords: [],
|
||||
},
|
||||
url: {
|
||||
wsUrl: '', // todo
|
||||
adminUrl: '',
|
||||
serverUrl: '',
|
||||
webUrl: '',
|
||||
},
|
||||
mailOptions: {
|
||||
enable: false,
|
||||
|
||||
user: '',
|
||||
pass: '',
|
||||
options: {
|
||||
host: '',
|
||||
port: 465,
|
||||
},
|
||||
},
|
||||
commentOptions: {
|
||||
antiSpam: false,
|
||||
blockIps: [],
|
||||
disableNoChinese: false,
|
||||
fetchLocationTimeout: 3000,
|
||||
recordIpLocation: true,
|
||||
spamKeywords: [],
|
||||
},
|
||||
friendLinkOptions: { allowApply: true },
|
||||
backupOptions: {
|
||||
enable: isInDemoMode ? false : true,
|
||||
region: null!,
|
||||
bucket: null!,
|
||||
secretId: null!,
|
||||
secretKey: null!,
|
||||
},
|
||||
baiduSearchOptions: { enable: false, token: null! },
|
||||
algoliaSearchOptions: { enable: false, apiKey: '', appId: '', indexName: '' },
|
||||
adminExtra: {
|
||||
enableAdminProxy: true,
|
||||
title: 'おかえり~',
|
||||
background: '',
|
||||
gaodemapKey: null!,
|
||||
},
|
||||
terminalOptions: {
|
||||
enable: false,
|
||||
password: null!,
|
||||
script: null!,
|
||||
},
|
||||
textOptions: {
|
||||
macros: true,
|
||||
},
|
||||
})
|
||||
@@ -127,10 +127,23 @@ export class CommentOptionsDto {
|
||||
@IsOptional()
|
||||
@JSONSchemaArrayField('自定义屏蔽 IP')
|
||||
blockIps?: string[]
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@JSONSchemaToggleField('禁止非中文评论')
|
||||
disableNoChinese?: boolean
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@JSONSchemaToggleField('评论公开归属地')
|
||||
recordIpLocation?: boolean
|
||||
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@JSONSchemaNumberField('超时时间', {
|
||||
description: '获取 IP 归属地的超时时间。单位: 毫秒。如获取超时则不记录',
|
||||
})
|
||||
fetchLocationTimeout?: number
|
||||
}
|
||||
|
||||
@JSONSchema({ title: '备份' })
|
||||
@@ -253,7 +266,7 @@ export class TerminalOptionsDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@JSONSchemaPlainField('前置脚本', {
|
||||
'ui:option': {
|
||||
'ui:options': {
|
||||
type: 'textarea',
|
||||
},
|
||||
})
|
||||
|
||||
@@ -23,45 +23,45 @@ import {
|
||||
export abstract class IConfig {
|
||||
@Type(() => UrlDto)
|
||||
@ValidateNested()
|
||||
url: UrlDto
|
||||
url: Required<UrlDto>
|
||||
|
||||
@Type(() => SeoDto)
|
||||
@ValidateNested()
|
||||
seo: SeoDto
|
||||
seo: Required<SeoDto>
|
||||
|
||||
@ValidateNested()
|
||||
@Type(() => AdminExtraDto)
|
||||
adminExtra: AdminExtraDto
|
||||
adminExtra: Required<AdminExtraDto>
|
||||
|
||||
@Type(() => TextOptionsDto)
|
||||
@ValidateNested()
|
||||
textOptions: TextOptionsDto
|
||||
textOptions: Required<TextOptionsDto>
|
||||
|
||||
@Type(() => MailOptionsDto)
|
||||
@ValidateNested()
|
||||
mailOptions: MailOptionsDto
|
||||
mailOptions: Required<MailOptionsDto>
|
||||
|
||||
@Type(() => CommentOptionsDto)
|
||||
@ValidateNested()
|
||||
commentOptions: CommentOptionsDto
|
||||
commentOptions: Required<CommentOptionsDto>
|
||||
|
||||
@Type(() => FriendLinkOptionsDto)
|
||||
@ValidateNested()
|
||||
friendLinkOptions: FriendLinkOptionsDto
|
||||
friendLinkOptions: Required<FriendLinkOptionsDto>
|
||||
|
||||
@Type(() => BackupOptionsDto)
|
||||
@ValidateNested()
|
||||
backupOptions: BackupOptionsDto
|
||||
backupOptions: Required<BackupOptionsDto>
|
||||
@Type(() => BaiduSearchOptionsDto)
|
||||
@ValidateNested()
|
||||
baiduSearchOptions: BaiduSearchOptionsDto
|
||||
baiduSearchOptions: Required<BaiduSearchOptionsDto>
|
||||
@ValidateNested()
|
||||
@Type(() => AlgoliaSearchOptionsDto)
|
||||
algoliaSearchOptions: AlgoliaSearchOptionsDto
|
||||
algoliaSearchOptions: Required<AlgoliaSearchOptionsDto>
|
||||
|
||||
@Type(() => TerminalOptionsDto)
|
||||
@ValidateNested()
|
||||
terminalOptions: TerminalOptionsDto
|
||||
terminalOptions: Required<TerminalOptionsDto>
|
||||
}
|
||||
|
||||
export type IConfigKeys = keyof IConfig
|
||||
|
||||
@@ -12,7 +12,7 @@ export const JSONSchemaPasswordField = (
|
||||
return JSONSchema({
|
||||
title,
|
||||
...schema,
|
||||
'ui:options': { showPassword: true, ...schema?.['ui:options'] },
|
||||
'ui:options': { type: 'password', ...schema?.['ui:options'] },
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ import { EventEmitter2 } from '@nestjs/event-emitter'
|
||||
import { DocumentType, ReturnModelType } from '@typegoose/typegoose'
|
||||
import { BeAnObject } from '@typegoose/typegoose/lib/types'
|
||||
|
||||
import { isInDemoMode } from '~/app.config'
|
||||
import { RedisKeys } from '~/constants/cache.constant'
|
||||
import { EventBusEvents } from '~/constants/event-bus.constant'
|
||||
import { CacheService } from '~/processors/cache/cache.service'
|
||||
@@ -26,11 +25,8 @@ import { getRedisKey } from '~/utils/redis.util'
|
||||
import * as optionDtos from '../configs/configs.dto'
|
||||
import { UserModel } from '../user/user.model'
|
||||
import { UserService } from '../user/user.service'
|
||||
import {
|
||||
AlgoliaSearchOptionsDto,
|
||||
BackupOptionsDto,
|
||||
MailOptionsDto,
|
||||
} from './configs.dto'
|
||||
import { generateDefaultConfig } from './configs.default'
|
||||
import { AlgoliaSearchOptionsDto, MailOptionsDto } from './configs.dto'
|
||||
import { IConfig, IConfigKeys } from './configs.interface'
|
||||
import { OptionModel } from './configs.model'
|
||||
|
||||
@@ -48,37 +44,6 @@ const map: Record<string, any> = Object.entries(optionDtos).reduce(
|
||||
{},
|
||||
)
|
||||
|
||||
const generateDefaultConfig: () => IConfig = () => ({
|
||||
seo: {
|
||||
title: '我的小世界呀',
|
||||
description: '哈喽~欢迎光临',
|
||||
},
|
||||
url: {
|
||||
wsUrl: '', // todo
|
||||
adminUrl: '',
|
||||
serverUrl: '',
|
||||
webUrl: '',
|
||||
},
|
||||
mailOptions: {} as MailOptionsDto,
|
||||
commentOptions: { antiSpam: false },
|
||||
friendLinkOptions: { allowApply: true },
|
||||
backupOptions: { enable: isInDemoMode ? false : true } as BackupOptionsDto,
|
||||
baiduSearchOptions: { enable: false },
|
||||
algoliaSearchOptions: { enable: false, apiKey: '', appId: '', indexName: '' },
|
||||
adminExtra: {
|
||||
enableAdminProxy: true,
|
||||
title: 'おかえり~',
|
||||
background: '',
|
||||
gaodemapKey: null!,
|
||||
},
|
||||
terminalOptions: {
|
||||
enable: false,
|
||||
},
|
||||
textOptions: {
|
||||
macros: true,
|
||||
},
|
||||
})
|
||||
|
||||
@Injectable()
|
||||
export class ConfigsService {
|
||||
private logger: Logger
|
||||
@@ -134,7 +99,7 @@ export class ConfigsService {
|
||||
return
|
||||
}
|
||||
const value = field.value
|
||||
mergedConfig[name] = value
|
||||
mergedConfig[name] = { ...mergedConfig[name], ...value }
|
||||
})
|
||||
await this.setConfig(mergedConfig)
|
||||
this.configInitd = true
|
||||
|
||||
@@ -33,7 +33,9 @@ export class BaseOptionController {
|
||||
@HTTPDecorators.Bypass
|
||||
@Get('/jsonschema')
|
||||
getJsonSchema() {
|
||||
return classToJsonSchema(IConfig)
|
||||
return Object.assign(classToJsonSchema(IConfig), {
|
||||
default: this.configs.defaultConfig,
|
||||
})
|
||||
}
|
||||
|
||||
@Get('/:key')
|
||||
|
||||
@@ -21,7 +21,7 @@ export class ToolService {
|
||||
private readonly configs: ConfigsService,
|
||||
) {}
|
||||
|
||||
async getIp(ip: string): Promise<IP> {
|
||||
async getIp(ip: string, timeout = 3000): Promise<IP> {
|
||||
const isV4 = isIPv4(ip)
|
||||
const isV6 = isIPv6(ip)
|
||||
if (!isV4 && !isV6) {
|
||||
@@ -32,7 +32,7 @@ export class ToolService {
|
||||
const { data } = await this.httpService.axiosRef.get(
|
||||
`https://api.i-meto.com/ip/v1/qqwry/${ip}`,
|
||||
{
|
||||
timeout: 2000,
|
||||
timeout,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -41,7 +41,7 @@ export class ToolService {
|
||||
const { data } = (await this.httpService.axiosRef.get(
|
||||
`http://ip-api.com/json/${ip}`,
|
||||
{
|
||||
timeout: 2000,
|
||||
timeout,
|
||||
},
|
||||
)) as any
|
||||
|
||||
|
||||
Reference in New Issue
Block a user