@@ -5,14 +5,15 @@ import bodyParser from 'body-parser';
55import http from 'http' ;
66import { Server } from 'socket.io' ;
77import { BrowserWindow , shell } from 'electron' ;
8- import './ormconfig' ;
8+ import { sequelize } from './ormconfig' ;
99import { StrategyServiceStatusEnum } from './types' ;
1010import { ConfigController } from './controllers/configController' ;
1111import { MessageController } from './controllers/messageController' ;
1212import { KeywordReplyController } from './controllers/keywordReplyController' ;
1313import { MessageService } from './services/messageService' ;
1414import { DispatchService } from './services/dispatchService' ;
1515import { PluginService } from './services/pluginService' ;
16+ import { AppService } from './services/appService' ;
1617
1718const configController = new ConfigController ( ) ;
1819const messageController = new MessageController ( ) ;
@@ -33,6 +34,8 @@ class BKServer {
3334
3435 private dispatchService : DispatchService ;
3536
37+ private appService : AppService ;
38+
3639 constructor ( port : number , mainWindow : BrowserWindow ) {
3740 this . app = express ( ) ;
3841 this . app . use ( bodyParser . json ( ) ) ;
@@ -72,8 +75,14 @@ class BKServer {
7275 this . pluginService ,
7376 ) ;
7477
78+ this . appService = new AppService ( this . dispatchService , sequelize ) ;
79+
7580 this . configureSocketIO ( ) ;
7681 this . setupRoutes ( ) ;
82+ // 开启定时任务
83+ setInterval ( ( ) => {
84+ this . appService . initTasks ( ) ;
85+ } , 5 * 1000 ) ;
7786 }
7887
7988 private configureSocketIO ( ) : void {
@@ -383,10 +392,31 @@ class BKServer {
383392 // }
384393 } ) ;
385394
395+ // 检查插件是否正常工作
396+ this . app . post ( '/api/v1/base/plugin/check' , async ( req , res ) => {
397+ try {
398+ const { code, message, ctx } = req . body ;
399+ const ctxMap = new Map ( Object . entries ( ctx ) ) ;
400+ const resp = await this . pluginService . checkPlugin (
401+ code ,
402+ // @ts -ignore
403+ ctxMap ,
404+ message ,
405+ ) ;
406+ res . json ( resp ) ;
407+ } catch ( error ) {
408+ res . json ( {
409+ success : false ,
410+ error : error instanceof Error ? error . message : String ( error ) ,
411+ message : error instanceof Error ? error . message : String ( error ) ,
412+ } ) ;
413+ }
414+ } ) ;
415+
386416 // 获取任务列表
387417 this . app . get ( '/api/v1/strategy/tasks' , async ( req , res ) => {
388418 try {
389- const tasks = await this . dispatchService . getTasks ( ) ;
419+ const tasks = await this . appService . getTasks ( ) ;
390420 res . json ( {
391421 success : true ,
392422 data : tasks ,
@@ -404,7 +434,7 @@ class BKServer {
404434 this . app . post ( '/api/v1/strategy/tasks' , async ( req , res ) => {
405435 const { appId } = req . body ;
406436 try {
407- const task = await this . dispatchService . addTask ( String ( appId ) ) ;
437+ const task = await this . appService . addTask ( String ( appId ) ) ;
408438 res . json ( {
409439 success : true ,
410440 data : task ,
@@ -422,7 +452,7 @@ class BKServer {
422452 this . app . post ( '/api/v1/strategy/task/remove' , async ( req , res ) => {
423453 const { taskId } = req . body ;
424454 try {
425- await this . dispatchService . removeTask ( String ( taskId ) ) ;
455+ await this . appService . removeTask ( String ( taskId ) ) ;
426456 res . json ( {
427457 success : true ,
428458 } ) ;
0 commit comments