InpxHashCreator.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. const fs = require('fs-extra');
  2. const utils = require('./utils');
  3. //поправить в случае, если были критические изменения в DbCreator
  4. //иначе будет рассинхронизация между сервером и клиентом на уровне БД
  5. const dbCreatorVersion = '2';
  6. class InpxHashCreator {
  7. constructor(config) {
  8. this.config = config;
  9. }
  10. async getHash() {
  11. const config = this.config;
  12. let inpxFilterHash = '';
  13. if (await fs.pathExists(config.inpxFilterFile))
  14. inpxFilterHash = await utils.getFileHash(config.inpxFilterFile, 'sha256', 'hex');
  15. const joinedHash = dbCreatorVersion + inpxFilterHash +
  16. await utils.getFileHash(config.inpxFile, 'sha256', 'hex');
  17. return utils.getBufHash(joinedHash, 'sha256', 'hex');
  18. }
  19. async getInpxFileHash() {
  20. return (
  21. await fs.pathExists(this.config.inpxFile) ?
  22. await utils.getFileHash(this.config.inpxFile, 'sha256', 'hex') :
  23. ''
  24. );
  25. }
  26. }
  27. module.exports = InpxHashCreator;