WebWorker.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. const os = require('os');
  2. const path = require('path');
  3. const fs = require('fs-extra');
  4. const _ = require('lodash');
  5. const iconv = require('iconv-lite');
  6. const ZipReader = require('./ZipReader');
  7. const WorkerState = require('./WorkerState');//singleton
  8. const { JembaDb, JembaDbThread } = require('jembadb');
  9. const DbCreator = require('./DbCreator');
  10. const DbSearcher = require('./DbSearcher');
  11. const InpxHashCreator = require('./InpxHashCreator');
  12. const RemoteLib = require('./RemoteLib');//singleton
  13. const FileDownloader = require('./FileDownloader');
  14. const asyncExit = new (require('./AsyncExit'))();
  15. const log = new (require('./AppLogger'))().log;//singleton
  16. const utils = require('./utils');
  17. const genreTree = require('./genres');
  18. const Fb2Helper = require('./fb2/Fb2Helper');
  19. //server states
  20. const ssNormal = 'normal';
  21. const ssDbLoading = 'db_loading';
  22. const ssDbCreating = 'db_creating';
  23. const stateToText = {
  24. [ssNormal]: '',
  25. [ssDbLoading]: 'Загрузка поисковой базы',
  26. [ssDbCreating]: 'Создание поисковой базы',
  27. };
  28. const cleanDirInterval = 60*60*1000;//каждый час
  29. const checkReleaseInterval = 7*60*60*1000;//каждые 7 часов
  30. //singleton
  31. let instance = null;
  32. class WebWorker {
  33. constructor(config) {
  34. if (!instance) {
  35. this.config = config;
  36. this.workerState = new WorkerState();
  37. this.remoteLib = null;
  38. if (config.remoteLib) {
  39. this.remoteLib = new RemoteLib(config);
  40. }
  41. this.inpxHashCreator = new InpxHashCreator(config);
  42. this.fb2Helper = new Fb2Helper();
  43. this.inpxFileHash = '';
  44. this.wState = this.workerState.getControl('server_state');
  45. this.myState = '';
  46. this.db = null;
  47. this.dbSearcher = null;
  48. asyncExit.add(this.closeDb.bind(this));
  49. this.loadOrCreateDb();//no await
  50. this.periodicLogServerStats();//no await
  51. const dirConfig = [
  52. {
  53. dir: config.bookDir,
  54. maxSize: config.maxFilesDirSize,
  55. },
  56. ];
  57. this.periodicCleanDir(dirConfig);//no await
  58. this.periodicCheckInpx();//no await
  59. this.periodicCheckNewRelease();//no await
  60. instance = this;
  61. }
  62. return instance;
  63. }
  64. checkMyState() {
  65. if (this.myState != ssNormal)
  66. throw new Error('server_busy');
  67. }
  68. setMyState(newState, workerState = {}) {
  69. this.myState = newState;
  70. this.wState.set(Object.assign({}, workerState, {
  71. state: newState,
  72. serverMessage: stateToText[newState]
  73. }));
  74. }
  75. async closeDb() {
  76. if (this.db) {
  77. await this.db.unlock();
  78. this.db = null;
  79. }
  80. }
  81. async createDb(dbPath) {
  82. this.setMyState(ssDbCreating);
  83. log('Searcher DB create start');
  84. const config = this.config;
  85. if (await fs.pathExists(dbPath))
  86. throw new Error(`createDb.pathExists: ${dbPath}`);
  87. const db = new JembaDbThread();
  88. await db.lock({
  89. dbPath,
  90. create: true,
  91. softLock: true,
  92. tableDefaults: {
  93. cacheSize: config.dbCacheSize,
  94. },
  95. });
  96. try {
  97. const dbCreator = new DbCreator(config);
  98. await dbCreator.run(db, (state) => {
  99. this.setMyState(ssDbCreating, state);
  100. if (state.fileName)
  101. log(` load ${state.fileName}`);
  102. if (state.recsLoaded)
  103. log(` processed ${state.recsLoaded} records`);
  104. if (state.job)
  105. log(` ${state.job}`);
  106. });
  107. log('Searcher DB successfully created');
  108. } finally {
  109. await db.unlock();
  110. }
  111. }
  112. async loadOrCreateDb(recreate = false, iteration = 0) {
  113. this.setMyState(ssDbLoading);
  114. try {
  115. const config = this.config;
  116. const dbPath = `${config.dataDir}/db`;
  117. this.inpxFileHash = await this.inpxHashCreator.getInpxFileHash();
  118. //проверим полный InxpHash (включая фильтр и версию БД)
  119. //для этого заглянем в конфиг внутри БД, если он есть
  120. if (!(config.recreateDb || recreate) && await fs.pathExists(dbPath)) {
  121. const newInpxHash = await this.inpxHashCreator.getHash();
  122. const tmpDb = new JembaDb();
  123. await tmpDb.lock({dbPath, softLock: true});
  124. try {
  125. await tmpDb.open({table: 'config'});
  126. const rows = await tmpDb.select({table: 'config', where: `@@id('inpxHash')`});
  127. if (!rows.length || newInpxHash !== rows[0].value)
  128. throw new Error('inpx file: changes found on start, recreating DB');
  129. } catch (e) {
  130. log(LM_WARN, e.message);
  131. recreate = true;
  132. } finally {
  133. await tmpDb.unlock();
  134. }
  135. }
  136. //удалим БД если нужно
  137. if (config.recreateDb || recreate)
  138. await fs.remove(dbPath);
  139. //пересоздаем БД из INPX если нужно
  140. if (!await fs.pathExists(dbPath)) {
  141. await this.createDb(dbPath);
  142. utils.freeMemory();
  143. }
  144. //загружаем БД
  145. this.setMyState(ssDbLoading);
  146. log('Searcher DB loading');
  147. const db = new JembaDbThread();//в отдельном потоке
  148. await db.lock({
  149. dbPath,
  150. softLock: true,
  151. tableDefaults: {
  152. cacheSize: config.dbCacheSize,
  153. },
  154. });
  155. try {
  156. //открываем таблицы
  157. await db.openAll({exclude: ['author_id', 'series_id', 'title_id', 'book']});
  158. const bookCacheSize = 500;
  159. await db.open({
  160. table: 'book',
  161. cacheSize: (config.lowMemoryMode || config.dbCacheSize > bookCacheSize ? config.dbCacheSize : bookCacheSize)
  162. });
  163. } catch(e) {
  164. log(LM_ERR, `Database error: ${e.message}`);
  165. if (iteration < 1) {
  166. log('Recreating DB');
  167. await this.loadOrCreateDb(true, iteration + 1);
  168. } else
  169. throw e;
  170. return;
  171. }
  172. //поисковый движок
  173. this.dbSearcher = new DbSearcher(config, db);
  174. await this.dbSearcher.init();
  175. //stuff
  176. db.wwCache = {};
  177. this.db = db;
  178. this.setMyState(ssNormal);
  179. log('Searcher DB ready');
  180. this.logServerStats();
  181. } catch (e) {
  182. log(LM_FATAL, e.message);
  183. asyncExit.exit(1);
  184. }
  185. }
  186. async recreateDb() {
  187. this.setMyState(ssDbCreating);
  188. if (this.dbSearcher) {
  189. await this.dbSearcher.close();
  190. this.dbSearcher = null;
  191. }
  192. await this.closeDb();
  193. await this.loadOrCreateDb(true);
  194. }
  195. async dbConfig() {
  196. this.checkMyState();
  197. const db = this.db;
  198. if (!db.wwCache.config) {
  199. const rows = await db.select({table: 'config'});
  200. const config = {};
  201. for (const row of rows) {
  202. config[row.id] = row.value;
  203. }
  204. db.wwCache.config = config;
  205. }
  206. return db.wwCache.config;
  207. }
  208. async search(from, query) {
  209. this.checkMyState();
  210. const result = await this.dbSearcher.search(from, query);
  211. const config = await this.dbConfig();
  212. result.inpxHash = (config.inpxHash ? config.inpxHash : '');
  213. return result;
  214. }
  215. async bookSearch(query) {
  216. this.checkMyState();
  217. const result = await this.dbSearcher.bookSearch(query);
  218. const config = await this.dbConfig();
  219. result.inpxHash = (config.inpxHash ? config.inpxHash : '');
  220. return result;
  221. }
  222. async opdsQuery(from, query) {
  223. this.checkMyState();
  224. return await this.dbSearcher.opdsQuery(from, query);
  225. }
  226. async getAuthorBookList(authorId, author) {
  227. this.checkMyState();
  228. return await this.dbSearcher.getAuthorBookList(authorId, author);
  229. }
  230. async getAuthorSeriesList(authorId) {
  231. this.checkMyState();
  232. return await this.dbSearcher.getAuthorSeriesList(authorId);
  233. }
  234. async getSeriesBookList(series) {
  235. this.checkMyState();
  236. return await this.dbSearcher.getSeriesBookList(series);
  237. }
  238. async getGenreTree() {
  239. this.checkMyState();
  240. const config = await this.dbConfig();
  241. let result;
  242. const db = this.db;
  243. if (!db.wwCache.genreTree) {
  244. const genres = _.cloneDeep(genreTree);
  245. const last = genres[genres.length - 1];
  246. const genreValues = new Set();
  247. for (const section of genres) {
  248. for (const g of section.value)
  249. genreValues.add(g.value);
  250. }
  251. //добавим к жанрам те, что нашлись при парсинге
  252. const genreParsed = new Set();
  253. let rows = await db.select({table: 'genre', map: `(r) => ({value: r.value})`});
  254. for (const row of rows) {
  255. genreParsed.add(row.value);
  256. if (!genreValues.has(row.value))
  257. last.value.push({name: row.value, value: row.value});
  258. }
  259. //уберем те, которые не нашлись при парсинге
  260. for (let j = 0; j < genres.length; j++) {
  261. const section = genres[j];
  262. for (let i = 0; i < section.value.length; i++) {
  263. const g = section.value[i];
  264. if (!genreParsed.has(g.value))
  265. section.value.splice(i--, 1);
  266. }
  267. if (!section.value.length)
  268. genres.splice(j--, 1);
  269. }
  270. // langs
  271. rows = await db.select({table: 'lang', map: `(r) => ({value: r.value})`});
  272. const langs = rows.map(r => r.value);
  273. // exts
  274. rows = await db.select({table: 'ext', map: `(r) => ({value: r.value})`});
  275. const exts = rows.map(r => r.value);
  276. result = {
  277. genreTree: genres,
  278. langList: langs,
  279. extList: exts,
  280. inpxHash: (config.inpxHash ? config.inpxHash : ''),
  281. };
  282. db.wwCache.genreTree = result;
  283. } else {
  284. result = db.wwCache.genreTree;
  285. }
  286. return result;
  287. }
  288. async getGenreMap() {
  289. this.checkMyState();
  290. let result;
  291. const db = this.db;
  292. if (!db.wwCache.genreMap) {
  293. const genreTree = await this.getGenreTree();
  294. result = new Map();
  295. for (const section of genreTree.genreTree) {
  296. for (const g of section.value)
  297. result.set(g.value, g.name);
  298. }
  299. db.wwCache.genreMap = result;
  300. } else {
  301. result = db.wwCache.genreMap;
  302. }
  303. return result;
  304. }
  305. async extractBook(libFolder, libFile) {
  306. const outFile = `${this.config.tempDir}/${utils.randomHexString(30)}`;
  307. libFolder = libFolder.replace(/\\/g, '/').replace(/\/\//g, '/');
  308. const folder = `${this.config.libDir}/${libFolder}`;
  309. const file = libFile;
  310. const fullPath = `${folder}/${file}`;
  311. if (!file || await fs.pathExists(fullPath)) {// файл есть на диске
  312. await fs.copy(fullPath, outFile);
  313. return outFile;
  314. } else {// файл в zip-архиве
  315. const zipReader = new ZipReader();
  316. await zipReader.open(folder);
  317. try {
  318. await zipReader.extractToFile(file, outFile);
  319. if (!await fs.pathExists(outFile)) {//не удалось найти в архиве, попробуем имя файла в кодировке cp866
  320. await zipReader.extractToFile(iconv.encode(file, 'cp866').toString(), outFile);
  321. }
  322. return outFile;
  323. } finally {
  324. await zipReader.close();
  325. }
  326. }
  327. }
  328. async restoreBook(bookUid, libFolder, libFile, downFileName) {
  329. const db = this.db;
  330. let extractedFile = '';
  331. let hash = '';
  332. if (!this.remoteLib) {
  333. extractedFile = await this.extractBook(libFolder, libFile);
  334. hash = await utils.getFileHash(extractedFile, 'sha256', 'hex');
  335. } else {
  336. hash = await this.remoteLib.downloadBook(bookUid);
  337. }
  338. const link = `${this.config.bookPathStatic}/${hash}`;
  339. const bookFile = `${this.config.bookDir}/${hash}`;
  340. const bookFileDesc = `${bookFile}.d.json`;
  341. if (!await fs.pathExists(bookFile) || !await fs.pathExists(bookFileDesc)) {
  342. if (!await fs.pathExists(bookFile) && extractedFile) {
  343. const tmpFile = `${this.config.tempDir}/${utils.randomHexString(30)}`;
  344. await utils.gzipFile(extractedFile, tmpFile, 4);
  345. await fs.remove(extractedFile);
  346. await fs.move(tmpFile, bookFile, {overwrite: true});
  347. } else {
  348. await utils.touchFile(bookFile);
  349. }
  350. await fs.writeFile(bookFileDesc, JSON.stringify({libFolder, libFile, downFileName}));
  351. } else {
  352. if (extractedFile)
  353. await fs.remove(extractedFile);
  354. await utils.touchFile(bookFile);
  355. await utils.touchFile(bookFileDesc);
  356. }
  357. await db.insert({
  358. table: 'file_hash',
  359. replace: true,
  360. rows: [
  361. {id: bookUid, hash},
  362. ]
  363. });
  364. return link;
  365. }
  366. async getBookLink(bookUid) {
  367. this.checkMyState();
  368. try {
  369. const db = this.db;
  370. let link = '';
  371. //найдем downFileName, libFolder, libFile
  372. let rows = await db.select({table: 'book', where: `@@hash('_uid', ${db.esc(bookUid)})`});
  373. if (!rows.length)
  374. throw new Error('404 Файл не найден');
  375. const book = rows[0];
  376. let downFileName = book.file;
  377. const authors = book.author.split(',');
  378. let author = authors[0];
  379. author = author.split(' ').filter(r => r.trim());
  380. for (let i = 1; i < author.length; i++)
  381. author[i] = `${(i === 1 ? ' ' : '')}${author[i][0]}.`;
  382. if (authors.length > 1)
  383. author.push(' и др.');
  384. const at = [author.join(''), (book.title ? `_${book.title}` : '')];
  385. downFileName = utils.makeValidFileNameOrEmpty(at.filter(r => r).join(''))
  386. || utils.makeValidFileNameOrEmpty(at[0])
  387. || utils.makeValidFileNameOrEmpty(at[1])
  388. || downFileName;
  389. if (downFileName.length > 50)
  390. downFileName = `${downFileName.substring(0, 50)}_`;
  391. const ext = `.${book.ext}`;
  392. if (downFileName.substring(downFileName.length - ext.length) != ext)
  393. downFileName += ext;
  394. const libFolder = book.folder;
  395. const libFile = `${book.file}${ext}`;
  396. //найдем хеш
  397. rows = await db.select({table: 'file_hash', where: `@@id(${db.esc(bookUid)})`});
  398. if (rows.length) {//хеш найден по bookUid
  399. const hash = rows[0].hash;
  400. const bookFile = `${this.config.bookDir}/${hash}`;
  401. const bookFileDesc = `${bookFile}.d.json`;
  402. if (await fs.pathExists(bookFile) && await fs.pathExists(bookFileDesc)) {
  403. link = `${this.config.bookPathStatic}/${hash}`;
  404. }
  405. }
  406. if (!link) {
  407. link = await this.restoreBook(bookUid, libFolder, libFile, downFileName);
  408. }
  409. if (!link)
  410. throw new Error('404 Файл не найден');
  411. return {link, libFolder, libFile, downFileName};
  412. } catch(e) {
  413. log(LM_ERR, `getBookLink error: ${e.message}`);
  414. if (e.message.indexOf('ENOENT') >= 0)
  415. throw new Error('404 Файл не найден');
  416. throw e;
  417. }
  418. }
  419. async getBookInfo(bookUid) {
  420. this.checkMyState();
  421. try {
  422. const db = this.db;
  423. let bookInfo = await this.getBookLink(bookUid);
  424. const hash = path.basename(bookInfo.link);
  425. const bookFile = `${this.config.bookDir}/${hash}`;
  426. const bookFileInfo = `${bookFile}.i.json`;
  427. let rows = await db.select({table: 'book', where: `@@hash('_uid', ${db.esc(bookUid)})`});
  428. if (!rows.length)
  429. throw new Error('404 Файл не найден');
  430. const book = rows[0];
  431. const restoreBookInfo = async(info) => {
  432. const result = {};
  433. result.book = book;
  434. result.cover = '';
  435. result.fb2 = false;
  436. let parser = null;
  437. if (book.ext == 'fb2') {
  438. const {fb2, cover, coverExt} = await this.fb2Helper.getDescAndCover(bookFile);
  439. parser = fb2;
  440. result.fb2 = fb2.rawNodes;
  441. if (cover) {
  442. result.cover = `${this.config.bookPathStatic}/${hash}${coverExt}`;
  443. await fs.writeFile(`${bookFile}${coverExt}`, cover);
  444. }
  445. }
  446. Object.assign(info, result);
  447. await fs.writeFile(bookFileInfo, JSON.stringify(info));
  448. if (this.config.branch === 'development') {
  449. await fs.writeFile(`${bookFile}.dev`, `${JSON.stringify(info, null, 2)}\n\n${parser ? parser.toString({format: true}) : ''}`);
  450. }
  451. };
  452. if (!await fs.pathExists(bookFileInfo)) {
  453. await restoreBookInfo(bookInfo);
  454. } else {
  455. await utils.touchFile(bookFileInfo);
  456. const info = await fs.readFile(bookFileInfo, 'utf-8');
  457. const tmpInfo = JSON.parse(info);
  458. //проверим существование файла обложки, восстановим если нету
  459. let coverFile = '';
  460. if (tmpInfo.cover)
  461. coverFile = `${this.config.publicFilesDir}${tmpInfo.cover}`;
  462. if (book.id != tmpInfo.book.id || (coverFile && !await fs.pathExists(coverFile))) {
  463. await restoreBookInfo(bookInfo);
  464. } else {
  465. bookInfo = tmpInfo;
  466. }
  467. }
  468. return {bookInfo};
  469. } catch(e) {
  470. log(LM_ERR, `getBookInfo error: ${e.message}`);
  471. if (e.message.indexOf('ENOENT') >= 0)
  472. throw new Error('404 Файл не найден');
  473. throw e;
  474. }
  475. }
  476. async getInpxFile(params) {
  477. let data = null;
  478. if (params.inpxFileHash && this.inpxFileHash && params.inpxFileHash === this.inpxFileHash) {
  479. data = false;
  480. }
  481. if (data === null)
  482. data = await fs.readFile(this.config.inpxFile, 'base64');
  483. return {data};
  484. }
  485. logServerStats() {
  486. try {
  487. const memUsage = process.memoryUsage().rss/(1024*1024);//Mb
  488. let loadAvg = os.loadavg();
  489. loadAvg = loadAvg.map(v => v.toFixed(2));
  490. log(`Server stats [ memUsage: ${memUsage.toFixed(2)}MB, loadAvg: (${loadAvg.join(', ')}) ]`);
  491. } catch (e) {
  492. log(LM_ERR, e.message);
  493. }
  494. }
  495. async periodicLogServerStats() {
  496. if (!this.config.logServerStats)
  497. return;
  498. while (1) {// eslint-disable-line
  499. this.logServerStats();
  500. await utils.sleep(60*1000);
  501. }
  502. }
  503. async cleanDir(config) {
  504. const {dir, maxSize} = config;
  505. const list = await fs.readdir(dir);
  506. let size = 0;
  507. let files = [];
  508. //формируем список
  509. for (const filename of list) {
  510. const filePath = `${dir}/${filename}`;
  511. const stat = await fs.stat(filePath);
  512. if (!stat.isDirectory()) {
  513. size += stat.size;
  514. files.push({name: filePath, stat});
  515. }
  516. }
  517. files.sort((a, b) => a.stat.mtimeMs - b.stat.mtimeMs);
  518. let i = 0;
  519. //удаляем
  520. while (i < files.length && size > maxSize) {
  521. const file = files[i];
  522. const oldFile = file.name;
  523. await fs.remove(oldFile);
  524. size -= file.stat.size;
  525. i++;
  526. }
  527. if (i) {
  528. log(LM_WARN, `clean dir ${dir}, maxSize=${maxSize}, found ${files.length} files, total size=${size}`);
  529. log(LM_WARN, `removed ${i} files`);
  530. }
  531. }
  532. async periodicCleanDir(dirConfig) {
  533. try {
  534. for (const config of dirConfig)
  535. await fs.ensureDir(config.dir);
  536. let lastCleanDirTime = 0;
  537. while (1) {// eslint-disable-line no-constant-condition
  538. //чистка папок
  539. if (Date.now() - lastCleanDirTime >= cleanDirInterval) {
  540. for (const config of dirConfig) {
  541. try {
  542. await this.cleanDir(config);
  543. } catch(e) {
  544. log(LM_ERR, e.stack);
  545. }
  546. }
  547. lastCleanDirTime = Date.now();
  548. }
  549. await utils.sleep(60*1000);//интервал проверки 1 минута
  550. }
  551. } catch (e) {
  552. log(LM_FATAL, e.message);
  553. asyncExit.exit(1);
  554. }
  555. }
  556. async periodicCheckInpx() {
  557. const inpxCheckInterval = this.config.inpxCheckInterval;
  558. if (!inpxCheckInterval)
  559. return;
  560. while (1) {// eslint-disable-line no-constant-condition
  561. try {
  562. while (this.myState != ssNormal)
  563. await utils.sleep(1000);
  564. if (this.remoteLib) {
  565. await this.remoteLib.downloadInpxFile();
  566. }
  567. const newInpxHash = await this.inpxHashCreator.getHash();
  568. const dbConfig = await this.dbConfig();
  569. const currentInpxHash = (dbConfig.inpxHash ? dbConfig.inpxHash : '');
  570. if (newInpxHash !== currentInpxHash) {
  571. log('inpx file: changes found, recreating DB');
  572. await this.recreateDb();
  573. } else {
  574. //log('inpx file: no changes');
  575. }
  576. } catch(e) {
  577. log(LM_ERR, `periodicCheckInpx: ${e.message}`);
  578. }
  579. await utils.sleep(inpxCheckInterval*60*1000);
  580. }
  581. }
  582. async periodicCheckNewRelease() {
  583. const checkReleaseLink = this.config.checkReleaseLink;
  584. if (!checkReleaseLink)
  585. return;
  586. const down = new FileDownloader(1024*1024);
  587. while (1) {// eslint-disable-line no-constant-condition
  588. try {
  589. let release = await down.load(checkReleaseLink);
  590. release = JSON.parse(release.toString());
  591. if (release.tag_name)
  592. this.config.latestVersion = release.tag_name;
  593. } catch(e) {
  594. log(LM_ERR, `periodicCheckNewRelease: ${e.message}`);
  595. }
  596. await utils.sleep(checkReleaseInterval);
  597. }
  598. }
  599. }
  600. module.exports = WebWorker;