ReaderWorker.js 761 B

1234567891011121314151617181920212223242526272829
  1. const workerState = require('./workerState');
  2. const fs = require('fs-extra');
  3. class ReaderWorker {
  4. constructor(config) {
  5. this.config = Object.assign({}, config);
  6. this.config.tempDownloadDir = `${config.tempDir}/download`;
  7. fs.ensureDirSync(this.config.tempDownloadDir);
  8. }
  9. async loadBook(url, wState) {
  10. const loader = require('./readerLoader');
  11. loader(url, this.config, (state) => {
  12. wState.set(state)
  13. });
  14. }
  15. loadBookUrl(url) {
  16. const workerId = workerState.generateWorkerId();
  17. const wState = workerState.getControl(workerId);
  18. wState.set({state: 'start'});
  19. this.loadBook(url, wState);
  20. return workerId;
  21. }
  22. }
  23. module.exports = ReaderWorker;