From 40c74406c92d3371477efcff5127642844dfd287 Mon Sep 17 00:00:00 2001 From: Shigma Date: Sun, 31 Jul 2022 01:23:43 +0800 Subject: [PATCH] feat(core): enhance some config schema --- packages/core/package.json | 2 +- packages/core/src/context.ts | 4 ++-- packages/koishi/package.json | 2 +- packages/koishi/src/assets.ts | 4 +++- packages/koishi/src/index.ts | 7 +++---- plugins/assets/local/src/index.ts | 2 +- plugins/assets/remote/src/index.ts | 2 +- plugins/assets/s3/src/index.ts | 2 +- 8 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index 71cf8aa889..fa9faf3c44 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -31,7 +31,7 @@ }, "dependencies": { "@koishijs/utils": "^6.0.0", - "@satorijs/core": "^1.0.4", + "@satorijs/core": "^1.0.6", "cordis": "^2.0.6", "fastest-levenshtein": "^1.0.12", "minato": "^1.2.3" diff --git a/packages/core/src/context.ts b/packages/core/src/context.ts index f8692725fe..c7eb24d0de 100644 --- a/packages/core/src/context.ts +++ b/packages/core/src/context.ts @@ -82,11 +82,11 @@ export namespace Context { prefix: Schema.union([ Schema.array(String), Schema.transform(String, (prefix) => [prefix]), - ] as const).default(['']).description('指令前缀字符,可以是字符串或字符串数组。将用于指令前缀的匹配。'), + ] as const).default(['']).description('指令前缀字符构成的数组。将被用于指令的匹配。'), nickname: Schema.union([ Schema.array(String), Schema.transform(String, (nickname) => [nickname]), - ] as const).description('机器人的昵称,可以是字符串或字符串数组。将用于指令前缀的匹配。'), + ] as const).description('机器人昵称构成的数组。将被用于指令的匹配。'), autoAssign: Schema.union([Boolean, Function]).default(true).description('当获取不到频道数据时,是否使用接受者作为代理者。'), autoAuthorize: Schema.union([Schema.natural(), Function]).default(1).description('当获取不到用户数据时默认使用的权限等级。'), }).description('基础设置')) diff --git a/packages/koishi/package.json b/packages/koishi/package.json index bd18ab3381..a26114883c 100644 --- a/packages/koishi/package.json +++ b/packages/koishi/package.json @@ -36,7 +36,7 @@ "dependencies": { "@koishijs/core": "^4.8.2", "@koishijs/utils": "^6.0.0", - "@satorijs/satori": "^1.0.4", + "@satorijs/satori": "^1.0.6", "file-type": "^16.5.3", "ns-require": "^1.1.4" } diff --git a/packages/koishi/src/assets.ts b/packages/koishi/src/assets.ts index 6f06e48c99..20438a9792 100644 --- a/packages/koishi/src/assets.ts +++ b/packages/koishi/src/assets.ts @@ -22,8 +22,10 @@ declare module '@koishijs/core' { } } +Context.service('assets') + defineProperty(Context.Config, 'Assets', Schema.object({ - whitelist: Schema.array(Schema.string().required().role('url')).description('不处理的白名单 URL 列表。'), + whitelist: Schema.array(Schema.string().required().role('link')).description('不处理的白名单 URL 列表。'), }).description('资源设置')) const PROTOCOL_BASE64 = 'base64://' diff --git a/packages/koishi/src/index.ts b/packages/koishi/src/index.ts index 33ced8e0ff..8343ad05d3 100644 --- a/packages/koishi/src/index.ts +++ b/packages/koishi/src/index.ts @@ -35,7 +35,6 @@ Context.Config.list.push(Schema.object({ assets: Context.Config.Assets, })) -Context.Config.list.push(Quester.Config) - -Context.service('assets') -Context.service('cache') +Context.Config.list.push(Schema.object({ + request: Quester.Config, +})) diff --git a/plugins/assets/local/src/index.ts b/plugins/assets/local/src/index.ts index 64aac895c4..79d767a708 100644 --- a/plugins/assets/local/src/index.ts +++ b/plugins/assets/local/src/index.ts @@ -105,7 +105,7 @@ namespace LocalAssets { export const Config: Schema = Schema.object({ root: Schema.string().description('本地存储资源文件的绝对路径。'), path: Schema.string().default('/files').description('静态图片暴露在服务器的路径。'), - selfUrl: Schema.string().role('url').description('Koishi 服务暴露在公网的地址。缺省时将使用全局配置。'), + selfUrl: Schema.string().role('link').description('Koishi 服务暴露在公网的地址。缺省时将使用全局配置。'), secret: Schema.string().description('用于验证上传者的密钥,配合 assets-remote 使用。').role('secret'), }) } diff --git a/plugins/assets/remote/src/index.ts b/plugins/assets/remote/src/index.ts index 2e1e0bb134..eba1a53841 100644 --- a/plugins/assets/remote/src/index.ts +++ b/plugins/assets/remote/src/index.ts @@ -37,7 +37,7 @@ namespace RemoteAssets { } export const Config: Schema = Schema.object({ - endpoint: Schema.string().role('url').description('远程服务器地址。').required(), + endpoint: Schema.string().role('link').description('远程服务器地址。').required(), secret: Schema.string().description('服务器设置的密钥,配合 assets-local 使用。').role('secret'), }) } diff --git a/plugins/assets/s3/src/index.ts b/plugins/assets/s3/src/index.ts index dcaa766225..709e5b6935 100644 --- a/plugins/assets/s3/src/index.ts +++ b/plugins/assets/s3/src/index.ts @@ -93,7 +93,7 @@ namespace S3Assets { export const Config: Schema = Schema.object({ region: Schema.string().default('none'), - endpoint: Schema.string().role('url'), + endpoint: Schema.string().role('link'), credentials: Credentials, bucket: Schema.string().required(), pathPrefix: Schema.string().default(''),