diff --git a/package.json b/package.json index 3c00da7e..6d8b4fac 100644 --- a/package.json +++ b/package.json @@ -186,6 +186,7 @@ "typescript": "4.7.3", "ioredis": "5.0.6", "webpack": "5.72.1", - "fastify-cors": "npm:@fastify/cors@7.0.0" + "fastify-cors": "npm:@fastify/cors@^7.0.0", + "fastify-formbody": "npm:@fastify/formbody@^6.0.0" } } \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e229bfb1..1bfc7af9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,7 +4,8 @@ overrides: typescript: 4.7.3 ioredis: 5.0.6 webpack: 5.72.1 - fastify-cors: npm:@fastify/cors@7.0.0 + fastify-cors: npm:@fastify/cors@^7.0.0 + fastify-formbody: npm:@fastify/formbody@^6.0.0 specifiers: '@algolia/client-search': '*' @@ -931,6 +932,12 @@ packages: resolution: {integrity: sha512-wI3fpfDT0t7p8E6dA2eTECzzOd+bZsZCJ2Hcv+Onn2b7ZwK3RwD27uW2QDaMtQhAfWQQP+WNK7nKf0twLsBf9w==} dev: false + /@fastify/formbody/6.0.1: + resolution: {integrity: sha512-yIwCitoES4Sh0tPc6v+uHBqZEKw3CooSZ4kUvO9NC8Y7oRBCW+aC+pTgUZ8M3r2DOzRkNO+Pq0jMQkyL2k8jZQ==} + dependencies: + fastify-plugin: 3.0.1 + dev: false + /@fastify/multipart/6.0.0: resolution: {integrity: sha512-TwxPH9jE3bEaCdMD1Xqm2YS1aelgJxcNmA/uYAPCzqnVEylDiKCmxCstGulb1W5WdMoyqD5LBGm7AoqDwWTCWQ==} dependencies: @@ -1485,7 +1492,7 @@ packages: '@nestjs/core': 8.4.6_vuwl3up5f332jd7oemx5cxyyz4 fastify: 3.29.0 fastify-cors: /@fastify/cors/7.0.0 - fastify-formbody: 5.3.0 + fastify-formbody: /@fastify/formbody/6.0.1 light-my-request: 5.0.0 middie: 6.1.0 path-to-regexp: 3.2.0 @@ -4102,19 +4109,6 @@ packages: strnum: 1.0.5 dev: false - /fastify-formbody/5.2.0: - resolution: {integrity: sha512-d8Y5hCL82akPyoFiXh2wYOm3es0pV9jqoPo3pO9OV2cNF0cQx39J5WAVXzCh4MSt9Z2qF4Fy5gHlvlyESwjtvg==} - dependencies: - fastify-plugin: 3.0.1 - dev: false - - /fastify-formbody/5.3.0: - resolution: {integrity: sha512-7cjFV2HE/doojyfTwCLToIFD6Hmbw2jVTbfqZ2lbUZznQWlSXu+MBQgqBU8T2nHcMfqSi9vx6PyX0LwTehuKkg==} - dependencies: - fastify-formbody-deprecated: /fastify-formbody/5.2.0 - process-warning: 1.0.0 - dev: false - /fastify-plugin/3.0.1: resolution: {integrity: sha512-qKcDXmuZadJqdTm6vlCqioEbyewF60b/0LOFCcYN1B6BIZGlYJumWWOYs70SFYLDAH4YqdE1cxH/RKMG7rFxgA==} dev: false @@ -4309,7 +4303,7 @@ packages: dev: false /fresh/0.5.2: - resolution: {integrity: sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==} + resolution: {integrity: sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=} engines: {node: '>= 0.6'} dev: false @@ -5073,7 +5067,7 @@ packages: dev: false /javascript-natural-sort/0.7.1: - resolution: {integrity: sha512-nO6jcEfZWQXDhOiBtG2KvKyEptz7RVbpGP4vTD2hLBdmNQSsCiicO2Ioinv6UI4y9ukqnBpy+XZ9H6uLNgJTlw==} + resolution: {integrity: sha1-+eIwPUUH9tdDVac2ZNFED7Wg71k=} dev: true /jest-changed-files/28.0.2: diff --git a/src/modules/configs/configs.dto.ts b/src/modules/configs/configs.dto.ts index 00b7cfa2..906db811 100644 --- a/src/modules/configs/configs.dto.ts +++ b/src/modules/configs/configs.dto.ts @@ -24,6 +24,7 @@ import { JSONSchemaPasswordField, JSONSchemaPlainField, JSONSchemaToggleField, + halfFieldOption, } from './configs.jsonschema.decorator' @JSONSchema({ title: 'SEO 优化' }) @@ -77,9 +78,7 @@ class MailOption { @IsInt() @Transform(({ value: val }) => parseInt(val)) @IsOptional() - @JSONSchemaNumberField('发件邮箱端口', { - 'ui:options': { halfGrid: true }, - }) + @JSONSchemaNumberField('发件邮箱端口', halfFieldOption) port: number @IsUrl({ require_protocol: false }) @IsOptional() @@ -100,9 +99,7 @@ export class MailOptionsDto { @IsNotEmpty() @IsOptional() @Exclude({ toPlainOnly: true }) - @JSONSchemaPasswordField('发件邮箱密码', { - 'ui:options': { halfGrid: true }, - }) + @JSONSchemaPasswordField('发件邮箱密码', halfFieldOption) pass: string @ValidateNested() @@ -147,23 +144,23 @@ export class BackupOptionsDto { @IsString() @IsOptional() - @JSONSchemaPlainField('SecretId') + @JSONSchemaHalfGirdPlainField('SecretId') secretId?: string @IsOptional() @IsString() @Exclude({ toPlainOnly: true }) - @JSONSchemaPasswordField('SecretKey') + @JSONSchemaPasswordField('SecretKey', halfFieldOption) secretKey?: string @IsOptional() @IsString() - @JSONSchemaPlainField('Bucket') + @JSONSchemaHalfGirdPlainField('Bucket') bucket?: string @IsString() @IsOptional() - @JSONSchemaPlainField('地域 Region') + @JSONSchemaHalfGirdPlainField('地域 Region') region: string } @@ -208,28 +205,31 @@ export class AlgoliaSearchOptionsDto { @JSONSchema({ title: '后台附加设置' }) export class AdminExtraDto { + @IsBoolean() + @IsOptional() + @JSONSchemaToggleField('开启后台管理反代', { + description: '是否可以通过 API 访问后台', + }) + /** + * 是否开启后台反代访问 + */ + enableAdminProxy?: boolean + @IsString() @IsOptional() @JSONSchemaPlainField('登录页面背景') background?: string - @IsString() - @IsOptional() - @Exclude({ toPlainOnly: true }) - @JSONSchemaPasswordField('高德查询 API Key', { description: '日记地点定位' }) - gaodemapKey?: string @IsString() @IsOptional() @JSONSchemaPlainField('中后台标题') title?: string - @IsBoolean() + @IsString() @IsOptional() - @JSONSchemaToggleField('开启后台管理反代') - /** - * 是否开启后台反代访问 - */ - enableAdminProxy?: boolean + @Exclude({ toPlainOnly: true }) + @JSONSchemaPasswordField('高德查询 API Key', { description: '日记地点定位' }) + gaodemapKey?: string } @JSONSchema({ title: '终端设定' }) @@ -252,7 +252,11 @@ export class TerminalOptionsDto { @IsOptional() @IsString() - @JSONSchemaPlainField('前置脚本') + @JSONSchemaPlainField('前置脚本', { + 'ui:option': { + type: 'textarea', + }, + }) script?: string } diff --git a/src/modules/configs/configs.jsonschema.decorator.ts b/src/modules/configs/configs.jsonschema.decorator.ts index ebc3b759..14a35b42 100644 --- a/src/modules/configs/configs.jsonschema.decorator.ts +++ b/src/modules/configs/configs.jsonschema.decorator.ts @@ -1,6 +1,10 @@ import { JSONSchema } from 'class-validator-jsonschema' import { DecoratorSchema } from 'class-validator-jsonschema/build/decorators' +export const halfFieldOption = { + 'ui:options': { halfGrid: true }, +} + export const JSONSchemaPasswordField = ( title: string, schema?: DecoratorSchema, @@ -20,8 +24,7 @@ export const JSONSchemaPlainField = (title: string, schema?: DecoratorSchema) => export const JSONSchemaHalfGirdPlainField: typeof JSONSchemaPlainField = ( ...rest -) => - JSONSchemaPlainField.call(null, ...rest, { 'ui:options': { halfGrid: true } }) +) => JSONSchemaPlainField.call(null, ...rest, halfFieldOption) export const JSONSchemaArrayField = (title: string, schema?: DecoratorSchema) => JSONSchema({