Работа над BookUpdateChecker
This commit is contained in:
@@ -14,7 +14,6 @@ class BookUpdateCheckerController {
|
||||
this.isDevelopment = (config.branch == 'development');
|
||||
|
||||
this.bucServer = new BUCServer(config);
|
||||
this.bucServer.main(); //no await
|
||||
|
||||
this.wss = wss;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ const _ = require('lodash');
|
||||
const ReaderWorker = require('../core/Reader/ReaderWorker');//singleton
|
||||
const JembaReaderStorage = require('../core/Reader/JembaReaderStorage');//singleton
|
||||
const WorkerState = require('../core/WorkerState');//singleton
|
||||
const BUCClient = require('../core/BookUpdateChecker/BUCClient');//singleton
|
||||
const log = new (require('../core/AppLogger'))().log;//singleton
|
||||
const utils = require('../core/utils');
|
||||
|
||||
@@ -19,6 +20,10 @@ class WebSocketController {
|
||||
this.readerWorker = new ReaderWorker(config);
|
||||
this.workerState = new WorkerState();
|
||||
|
||||
if (config.bucEnabled) {
|
||||
this.bucClient = new BUCClient(config);
|
||||
}
|
||||
|
||||
this.wss = wss;
|
||||
|
||||
wss.on('connection', (ws) => {
|
||||
@@ -76,6 +81,8 @@ class WebSocketController {
|
||||
await this.uploadFileBuf(req, ws); break;
|
||||
case 'upload-file-touch':
|
||||
await this.uploadFileTouch(req, ws); break;
|
||||
case 'check-buc':
|
||||
await this.checkBuc(req, ws); break;
|
||||
|
||||
default:
|
||||
throw new Error(`Action not found: ${req.action}`);
|
||||
@@ -179,6 +186,21 @@ class WebSocketController {
|
||||
|
||||
this.send({url: await this.readerWorker.uploadFileTouch(req.url)}, req, ws);
|
||||
}
|
||||
|
||||
async checkBuc(req, ws) {
|
||||
if (!this.config.bucEnabled)
|
||||
throw new Error('BookUpdateChecker disabled');
|
||||
|
||||
if (!req.bookUrls)
|
||||
throw new Error(`key 'bookUrls' is empty`);
|
||||
|
||||
if (!Array.isArray(req.bookUrls))
|
||||
throw new Error(`key 'bookUrls' must be array`);
|
||||
|
||||
const data = await this.bucClient.checkBuc(req.bookUrls);
|
||||
|
||||
this.send({state: 'success', data}, req, ws);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WebSocketController;
|
||||
|
||||
Reference in New Issue
Block a user