diff --git a/js/cryptoLib/index.js b/js/cryptoLib/index.js index 6ecc61e5..e7e472c7 100644 --- a/js/cryptoLib/index.js +++ b/js/cryptoLib/index.js @@ -16,14 +16,12 @@ class Crypto { * Constructor * @param userId * @param key - * @param version */ - constructor(userId, key, version) { - this.indexDataFolder = `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${userId}`; - this.permanentIndexName = `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${userId}`; + constructor(userId, key) { + this.indexDataFolder = `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${userId}_${searchConfig.INDEX_VERSION}`; + this.permanentIndexName = `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${userId}_${searchConfig.INDEX_VERSION}`; this.dump = DUMP_PATH; this.key = key; - this.version = version; this.encryptedIndex = `${DUMP_PATH}/${this.permanentIndexName}`; this.dataFolder = searchConfig.FOLDERS_CONSTANTS.INDEX_PATH; } @@ -33,17 +31,17 @@ class Crypto { * encrypting it * @returns {Promise} */ - encryption(key, version) { + encryption(key) { return new Promise((resolve, reject) => { - if (!fs.existsSync(`${this.indexDataFolder}_${version}`)){ + if (!fs.existsSync(this.indexDataFolder)){ log.send(logLevels.ERROR, 'Crypto: User index folder not found'); reject(); return; } - lz4.compression(`${searchConfig.FOLDERS_CONSTANTS.INDEX_FOLDER_NAME}/${this.permanentIndexName}_${version}`, - `${this.permanentIndexName}_${version}`, (error, response) => { + lz4.compression(`${searchConfig.FOLDERS_CONSTANTS.INDEX_FOLDER_NAME}/${this.permanentIndexName}`, + `${this.permanentIndexName}`, (error, response) => { if (error) { log.send(logLevels.ERROR, 'Crypto: Error while compressing to lz4: ' + error); reject(error); @@ -53,8 +51,8 @@ class Crypto { if (response && response.stderr) { log.send(logLevels.WARN, 'Crypto: Child process stderr while compression, ' + response.stderr); } - const input = fs.createReadStream(`${this.dump}/${this.permanentIndexName}_${version}${searchConfig.TAR_LZ4_EXT}`); - const outputEncryption = fs.createWriteStream(`${this.encryptedIndex}_${version}.enc`); + const input = fs.createReadStream(`${this.dump}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`); + const outputEncryption = fs.createWriteStream(`${this.encryptedIndex}.enc`); let config = { key: key }; @@ -68,7 +66,7 @@ class Crypto { reject(new Error(err)); return; } - fs.unlinkSync(`${this.dump}/${this.permanentIndexName}_${version}${searchConfig.TAR_LZ4_EXT}`); + fs.unlinkSync(`${this.dump}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`); resolve('Success'); }); }); @@ -83,13 +81,13 @@ class Crypto { decryption() { return new Promise((resolve, reject) => { - if (!fs.existsSync(`${this.encryptedIndex}_${this.version}.enc`)){ + if (!fs.existsSync(`${this.encryptedIndex}.enc`)){ log.send(logLevels.ERROR, 'Crypto: Encrypted file not found'); reject(); return; } - const input = fs.createReadStream(`${this.encryptedIndex}_${this.version}.enc`); + const input = fs.createReadStream(`${this.encryptedIndex}.enc`); const output = fs.createWriteStream(`${this.dump}/decrypted${searchConfig.TAR_LZ4_EXT}`); let config = { key: this.key diff --git a/js/search/search.js b/js/search/search.js index 8d6acdf3..26306b66 100644 --- a/js/search/search.js +++ b/js/search/search.js @@ -26,19 +26,18 @@ class Search { * Constructor for the SymphonySearchEngine library * @param userId (for the index folder name) * @param key - * @param version */ - constructor(userId, key, version) { + constructor(userId, key) { this.isInitialized = false; this.userId = userId; this.key = key; - this.indexFolderName = `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${this.userId}_${version}`; + this.indexFolderName = `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${this.userId}_${searchConfig.INDEX_VERSION}`; this.dataFolder = searchConfig.FOLDERS_CONSTANTS.INDEX_PATH; this.realTimeIndex = searchConfig.FOLDERS_CONSTANTS.TEMP_REAL_TIME_INDEX; this.batchIndex = searchConfig.FOLDERS_CONSTANTS.TEMP_BATCH_INDEX_FOLDER; this.messageData = []; this.isRealTimeIndexing = false; - this.crypto = new Crypto(userId, key, version); + this.crypto = new Crypto(userId, key); this.decryptAndInit(); this.collector = makeBoundTimedCollector(this.checkIsRealTimeIndexing.bind(this), searchConfig.REAL_TIME_INDEXING_TIME, this.realTimeIndexing.bind(this)); @@ -235,8 +234,8 @@ class Search { * Encrypting the index after the merging the index * to the main user index */ - encryptIndex(key, version) { - return this.crypto.encryption(key, version).then(() => { + encryptIndex(key) { + return this.crypto.encryption(key).then(() => { return 'Success' }).catch((e) => { log.send(logLevels.ERROR, 'Encrypting the index folder failed ->' + e);