Commit 8e76a55f authored by nanahira's avatar nanahira

add constructor in config schema

parent 9ee11ba0
...@@ -3,6 +3,7 @@ import { DefineSchema, RegisterSchema } from 'schemastery-gen'; ...@@ -3,6 +3,7 @@ import { DefineSchema, RegisterSchema } from 'schemastery-gen';
@RegisterSchema() @RegisterSchema()
export class MyPluginConfig { export class MyPluginConfig {
constructor(config: Partial<MyPluginConfig>) {}
@DefineSchema({ @DefineSchema({
description: '词库本地路径或 URL。', description: '词库本地路径或 URL。',
default: default:
......
...@@ -147,7 +147,8 @@ export class MyPlugin { ...@@ -147,7 +147,8 @@ export class MyPlugin {
this.ctx = ctx; this.ctx = ctx;
this.config = config; this.config = config;
ctx.on('service', (name) => { ctx.on('service', (name) => {
if (this.config.useDatabase && name === 'database') this.useDatabase = !!ctx.database; if (this.config.useDatabase && name === 'database')
this.useDatabase = !!ctx.database;
}); });
ctx.on('service', (name) => { ctx.on('service', (name) => {
if (!ctx.cache || name !== 'cache') { if (!ctx.cache || name !== 'cache') {
...@@ -156,7 +157,7 @@ export class MyPlugin { ...@@ -156,7 +157,7 @@ export class MyPlugin {
ctx.cache.table('thesaurusChatSession', { ctx.cache.table('thesaurusChatSession', {
maxAge: this.config.chatTimeout, maxAge: this.config.chatTimeout,
}); });
}) });
await this.loadWords(); await this.loadWords();
ctx.middleware(async (session, next) => { ctx.middleware(async (session, next) => {
const sessionId = `${session.platform}.${session.selfId}.${session.userId}`; const sessionId = `${session.platform}.${session.selfId}.${session.userId}`;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment