mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
Merge branch 'master' into ELECTRON-261
This commit is contained in:
commit
ae7fd4edab
@ -115,11 +115,6 @@
|
|||||||
<p>Results:</p>
|
<p>Results:</p>
|
||||||
<p id="results"></p>
|
<p id="results"></p>
|
||||||
<table id="table" class="hidden" style="width:100%">
|
<table id="table" class="hidden" style="width:100%">
|
||||||
<tr>
|
|
||||||
<th>ThreadId</th>
|
|
||||||
<th>SenderId</th>
|
|
||||||
<th>Text</th>
|
|
||||||
</tr>
|
|
||||||
</table>
|
</table>
|
||||||
<br>
|
<br>
|
||||||
</div>
|
</div>
|
||||||
@ -189,24 +184,38 @@
|
|||||||
if (result.messages.length > 0) {
|
if (result.messages.length > 0) {
|
||||||
out = result;
|
out = result;
|
||||||
var th = document.createElement('tr');
|
var th = document.createElement('tr');
|
||||||
|
var avatarTh = document.createElement('td');
|
||||||
|
avatarTh.innerText = "Avatar";
|
||||||
|
var senderNameTh = document.createElement('td');
|
||||||
|
senderNameTh.innerText = "Sender Name";
|
||||||
var th1 = document.createElement('td');
|
var th1 = document.createElement('td');
|
||||||
th1.innerText = "ThreadId";
|
th1.innerText = "ThreadId";
|
||||||
var th2 = document.createElement('td');
|
var th2 = document.createElement('td');
|
||||||
th2.innerText = 'SenderId';
|
th2.innerText = 'SenderId';
|
||||||
var th3 = document.createElement('td');
|
var th3 = document.createElement('td');
|
||||||
th3.innerText = 'Text';
|
th3.innerText = 'Text';
|
||||||
|
th.appendChild(avatarTh);
|
||||||
|
th.appendChild(senderNameTh);
|
||||||
th.appendChild(th1);
|
th.appendChild(th1);
|
||||||
th.appendChild(th2);
|
th.appendChild(th2);
|
||||||
th.appendChild(th3);
|
th.appendChild(th3);
|
||||||
table.appendChild(th);
|
table.appendChild(th);
|
||||||
out.messages.forEach(function (msg) {
|
out.messages.forEach(function (msg) {
|
||||||
var tr = document.createElement('tr');
|
var tr = document.createElement('tr');
|
||||||
|
var avatar = document.createElement('img');
|
||||||
|
avatar.src = msg.senderAvatar;
|
||||||
|
avatar.style.maxWidth = '75px';
|
||||||
|
avatar.style.maxHeight = '75px';
|
||||||
|
var senderName = document.createElement('td');
|
||||||
|
senderName.innerText = msg.senderName;
|
||||||
var t1 = document.createElement('td');
|
var t1 = document.createElement('td');
|
||||||
t1.innerText = msg.threadId;
|
t1.innerText = msg.threadId;
|
||||||
var t2 = document.createElement('td');
|
var t2 = document.createElement('td');
|
||||||
t2.innerText = msg.senderId;
|
t2.innerText = msg.senderId;
|
||||||
var t3 = document.createElement('td');
|
var t3 = document.createElement('td');
|
||||||
t3.innerText = msg.text;
|
t3.innerText = msg.text;
|
||||||
|
tr.appendChild(avatar);
|
||||||
|
tr.appendChild(senderName);
|
||||||
tr.appendChild(t1);
|
tr.appendChild(t1);
|
||||||
tr.appendChild(t2);
|
tr.appendChild(t2);
|
||||||
tr.appendChild(t3);
|
tr.appendChild(t3);
|
||||||
@ -280,4 +289,4 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -8,14 +8,15 @@ const logLevels = require('./enums/logLevels.js');
|
|||||||
/**
|
/**
|
||||||
* Method that checks if user has enabled the bring to front feature
|
* Method that checks if user has enabled the bring to front feature
|
||||||
* if so then activates the main window
|
* if so then activates the main window
|
||||||
* @param windowName - Name of the window to activate
|
* @param {String} windowName - Name of the window to activate
|
||||||
|
* @param {String} reason - The reason for which the window is to be activated
|
||||||
*/
|
*/
|
||||||
function bringToFront(windowName) {
|
function bringToFront(windowName, reason) {
|
||||||
|
|
||||||
getConfigField('bringToFront')
|
getConfigField('bringToFront')
|
||||||
.then((bringToFrontSetting) => {
|
.then((bringToFrontSetting) => {
|
||||||
if (typeof bringToFrontSetting === 'boolean' && bringToFrontSetting) {
|
if (typeof bringToFrontSetting === 'boolean' && bringToFrontSetting) {
|
||||||
log.send(logLevels.INFO, 'Window has been activated for: bringToFront');
|
log.send(logLevels.INFO, 'Window has been activated for: ' + reason);
|
||||||
windowMgr.activate(windowName || 'main');
|
windowMgr.activate(windowName || 'main');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -18,13 +18,8 @@ class Crypto {
|
|||||||
* @param key
|
* @param key
|
||||||
*/
|
*/
|
||||||
constructor(userId, key) {
|
constructor(userId, key) {
|
||||||
this.indexDataFolder = `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${userId}`;
|
this.userId = userId;
|
||||||
this.permanentIndexName = `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${userId}`;
|
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.encryptedIndex = `${DUMP_PATH}/${this.permanentIndexName}.enc`;
|
|
||||||
this.dataFolder = searchConfig.FOLDERS_CONSTANTS.INDEX_PATH;
|
|
||||||
this.lz4Temp = `${DUMP_PATH}/${this.permanentIndexName}${searchConfig.TAR_LZ4_EXT}`;
|
|
||||||
this.decryptedTemp = `${DUMP_PATH}/decrypted${searchConfig.TAR_LZ4_EXT}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,14 +30,14 @@ class Crypto {
|
|||||||
encryption(key) {
|
encryption(key) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
if (!fs.existsSync(this.indexDataFolder)){
|
if (!fs.existsSync(`${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${this.userId}`)){
|
||||||
log.send(logLevels.ERROR, 'Crypto: User index folder not found');
|
log.send(logLevels.ERROR, 'Crypto: User index folder not found');
|
||||||
reject();
|
reject();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lz4.compression(`${searchConfig.FOLDERS_CONSTANTS.INDEX_FOLDER_NAME}/${this.permanentIndexName}`,
|
lz4.compression(`${searchConfig.FOLDERS_CONSTANTS.INDEX_FOLDER_NAME}/${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${this.userId}`,
|
||||||
`${this.permanentIndexName}`, (error, response) => {
|
`${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${this.userId}`, (error, response) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
log.send(logLevels.ERROR, 'Crypto: Error while compressing to lz4: ' + error);
|
log.send(logLevels.ERROR, 'Crypto: Error while compressing to lz4: ' + error);
|
||||||
reject(error);
|
reject(error);
|
||||||
@ -52,8 +47,8 @@ class Crypto {
|
|||||||
if (response && response.stderr) {
|
if (response && response.stderr) {
|
||||||
log.send(logLevels.WARN, 'Crypto: Child process stderr while compression, ' + response.stderr);
|
log.send(logLevels.WARN, 'Crypto: Child process stderr while compression, ' + response.stderr);
|
||||||
}
|
}
|
||||||
const input = fs.createReadStream(this.lz4Temp);
|
const input = fs.createReadStream(`${DUMP_PATH}/${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${this.userId}${searchConfig.TAR_LZ4_EXT}`);
|
||||||
const outputEncryption = fs.createWriteStream(this.encryptedIndex);
|
const outputEncryption = fs.createWriteStream(`${DUMP_PATH}/${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${this.userId}.enc`);
|
||||||
let config = {
|
let config = {
|
||||||
key: key
|
key: key
|
||||||
};
|
};
|
||||||
@ -62,8 +57,8 @@ class Crypto {
|
|||||||
encrypt = crypto.encrypt(config);
|
encrypt = crypto.encrypt(config);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.send(logLevels.ERROR, 'Error encrypting : ' + e);
|
log.send(logLevels.ERROR, 'Error encrypting : ' + e);
|
||||||
if (fs.existsSync(this.lz4Temp)) {
|
if (fs.existsSync(`${DUMP_PATH}/${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${this.userId}${searchConfig.TAR_LZ4_EXT}`)) {
|
||||||
fs.unlinkSync(this.lz4Temp);
|
fs.unlinkSync(`${DUMP_PATH}/${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${this.userId}${searchConfig.TAR_LZ4_EXT}`);
|
||||||
}
|
}
|
||||||
reject();
|
reject();
|
||||||
return;
|
return;
|
||||||
@ -74,14 +69,14 @@ class Crypto {
|
|||||||
encryptionProcess.on('finish', (err) => {
|
encryptionProcess.on('finish', (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
log.send(logLevels.ERROR, 'Crypto: Error while encrypting the compressed file: ' + err);
|
log.send(logLevels.ERROR, 'Crypto: Error while encrypting the compressed file: ' + err);
|
||||||
if (fs.existsSync(this.lz4Temp)) {
|
if (fs.existsSync(`${DUMP_PATH}/${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${this.userId}${searchConfig.TAR_LZ4_EXT}`)) {
|
||||||
fs.unlinkSync(this.lz4Temp);
|
fs.unlinkSync(`${DUMP_PATH}/${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${this.userId}${searchConfig.TAR_LZ4_EXT}`);
|
||||||
}
|
}
|
||||||
reject(new Error(err));
|
reject(new Error(err));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (fs.existsSync(this.lz4Temp)) {
|
if (fs.existsSync(`${DUMP_PATH}/${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${this.userId}${searchConfig.TAR_LZ4_EXT}`)) {
|
||||||
fs.unlinkSync(this.lz4Temp);
|
fs.unlinkSync(`${DUMP_PATH}/${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${this.userId}${searchConfig.TAR_LZ4_EXT}`);
|
||||||
}
|
}
|
||||||
resolve('Success');
|
resolve('Success');
|
||||||
});
|
});
|
||||||
@ -97,14 +92,14 @@ class Crypto {
|
|||||||
decryption() {
|
decryption() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
if (!fs.existsSync(this.encryptedIndex)){
|
if (!fs.existsSync(`${DUMP_PATH}/${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${this.userId}.enc`)){
|
||||||
log.send(logLevels.ERROR, 'Crypto: Encrypted file not found');
|
log.send(logLevels.ERROR, 'Crypto: Encrypted file not found');
|
||||||
reject();
|
reject();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const input = fs.createReadStream(this.encryptedIndex);
|
const input = fs.createReadStream(`${DUMP_PATH}/${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${this.userId}.enc`);
|
||||||
const output = fs.createWriteStream(this.decryptedTemp);
|
const output = fs.createWriteStream(`${DUMP_PATH}/decrypted${searchConfig.TAR_LZ4_EXT}`);
|
||||||
let config = {
|
let config = {
|
||||||
key: this.key
|
key: this.key
|
||||||
};
|
};
|
||||||
@ -113,8 +108,8 @@ class Crypto {
|
|||||||
decrypt = crypto.decrypt(config);
|
decrypt = crypto.decrypt(config);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.send(logLevels.ERROR, 'Error decrypting : ' + e);
|
log.send(logLevels.ERROR, 'Error decrypting : ' + e);
|
||||||
if (fs.existsSync(this.decryptedTemp)) {
|
if (fs.existsSync(`${DUMP_PATH}/decrypted${searchConfig.TAR_LZ4_EXT}`)) {
|
||||||
fs.unlinkSync(this.decryptedTemp);
|
fs.unlinkSync(`${DUMP_PATH}/decrypted${searchConfig.TAR_LZ4_EXT}`);
|
||||||
}
|
}
|
||||||
reject();
|
reject();
|
||||||
return;
|
return;
|
||||||
@ -124,13 +119,13 @@ class Crypto {
|
|||||||
|
|
||||||
decryptionProcess.on('finish', () => {
|
decryptionProcess.on('finish', () => {
|
||||||
|
|
||||||
if (!fs.existsSync(this.decryptedTemp)){
|
if (!fs.existsSync(`${DUMP_PATH}/decrypted${searchConfig.TAR_LZ4_EXT}`)){
|
||||||
log.send(logLevels.ERROR, 'decrypted.tar.lz4 file not found');
|
log.send(logLevels.ERROR, 'decrypted.tar.lz4 file not found');
|
||||||
reject();
|
reject();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lz4.deCompression(this.decryptedTemp,(error, response) => {
|
lz4.deCompression(`${DUMP_PATH}/decrypted${searchConfig.TAR_LZ4_EXT}`,(error, response) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
log.send(logLevels.ERROR, 'Crypto: Error while deCompression, ' + error);
|
log.send(logLevels.ERROR, 'Crypto: Error while deCompression, ' + error);
|
||||||
// no return, need to unlink if error
|
// no return, need to unlink if error
|
||||||
@ -139,7 +134,7 @@ class Crypto {
|
|||||||
if (response && response.stderr) {
|
if (response && response.stderr) {
|
||||||
log.send(logLevels.WARN, 'Crypto: Child process stderr while deCompression, ' + response.stderr);
|
log.send(logLevels.WARN, 'Crypto: Child process stderr while deCompression, ' + response.stderr);
|
||||||
}
|
}
|
||||||
fs.unlink(this.decryptedTemp, () => {
|
fs.unlink(`${DUMP_PATH}/decrypted${searchConfig.TAR_LZ4_EXT}`, () => {
|
||||||
resolve('success');
|
resolve('success');
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -16,7 +16,8 @@ const cmds = keyMirror({
|
|||||||
registerProtocolHandler: null,
|
registerProtocolHandler: null,
|
||||||
registerActivityDetection: null,
|
registerActivityDetection: null,
|
||||||
showNotificationSettings: null,
|
showNotificationSettings: null,
|
||||||
sanitize: null
|
sanitize: null,
|
||||||
|
bringToFront: null
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -103,11 +103,6 @@ electron.ipcMain.on(apiName, (event, arg) => {
|
|||||||
break;
|
break;
|
||||||
case apiCmds.activate:
|
case apiCmds.activate:
|
||||||
if (typeof arg.windowName === 'string') {
|
if (typeof arg.windowName === 'string') {
|
||||||
// validates the user bring to front config and activates the wrapper
|
|
||||||
if (typeof arg.reason === 'string' && arg.reason === 'bringToFront') {
|
|
||||||
bringToFront(arg.windowName);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
windowMgr.activate(arg.windowName);
|
windowMgr.activate(arg.windowName);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -134,6 +129,12 @@ electron.ipcMain.on(apiName, (event, arg) => {
|
|||||||
sanitize(arg.windowName);
|
sanitize(arg.windowName);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case apiCmds.bringToFront:
|
||||||
|
// validates the user bring to front config and activates the wrapper
|
||||||
|
if (typeof arg.reason === 'string' && arg.reason === 'notification') {
|
||||||
|
bringToFront(arg.windowName, arg.reason);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,11 +151,22 @@ function createAPI() {
|
|||||||
/**
|
/**
|
||||||
* Brings window forward and gives focus.
|
* Brings window forward and gives focus.
|
||||||
* @param {String} windowName Name of window. Note: main window name is 'main'
|
* @param {String} windowName Name of window. Note: main window name is 'main'
|
||||||
* @param {String} reason, The reason for which the window is to be activated
|
|
||||||
*/
|
*/
|
||||||
activate: function(windowName, reason) {
|
activate: function(windowName) {
|
||||||
local.ipcRenderer.send(apiName, {
|
local.ipcRenderer.send(apiName, {
|
||||||
cmd: apiCmds.activate,
|
cmd: apiCmds.activate,
|
||||||
|
windowName: windowName
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Brings window forward and gives focus.
|
||||||
|
* @param {String} windowName Name of window. Note: main window name is 'main'
|
||||||
|
* @param {String} reason, The reason for which the window is to be activated
|
||||||
|
*/
|
||||||
|
bringToFront: function(windowName, reason) {
|
||||||
|
local.ipcRenderer.send(apiName, {
|
||||||
|
cmd: apiCmds.bringToFront,
|
||||||
windowName: windowName,
|
windowName: windowName,
|
||||||
reason: reason
|
reason: reason
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const randomString = require('randomstring');
|
const { randomString } = require('../search/utils/randomString.js');
|
||||||
const childProcess = require('child_process');
|
const childProcess = require('child_process');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const isDevEnv = require('../utils/misc.js').isDevEnv;
|
const isDevEnv = require('../utils/misc.js').isDevEnv;
|
||||||
@ -31,10 +31,6 @@ class Search {
|
|||||||
this.isInitialized = false;
|
this.isInitialized = false;
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.indexFolderName = `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${this.userId}`;
|
|
||||||
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.messageData = [];
|
||||||
this.isRealTimeIndexing = false;
|
this.isRealTimeIndexing = false;
|
||||||
this.crypto = new Crypto(userId, key);
|
this.crypto = new Crypto(userId, key);
|
||||||
@ -70,14 +66,14 @@ class Search {
|
|||||||
*/
|
*/
|
||||||
init() {
|
init() {
|
||||||
libSymphonySearch.symSEInit();
|
libSymphonySearch.symSEInit();
|
||||||
libSymphonySearch.symSEEnsureFolderExists(this.dataFolder);
|
libSymphonySearch.symSEEnsureFolderExists(searchConfig.FOLDERS_CONSTANTS.INDEX_PATH);
|
||||||
Search.deleteIndexFolders(this.realTimeIndex);
|
Search.deleteIndexFolders(searchConfig.FOLDERS_CONSTANTS.TEMP_REAL_TIME_INDEX);
|
||||||
Search.deleteIndexFolders(this.batchIndex);
|
Search.deleteIndexFolders(searchConfig.FOLDERS_CONSTANTS.TEMP_BATCH_INDEX_FOLDER);
|
||||||
Search.indexValidator(this.indexFolderName);
|
Search.indexValidator(`${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${this.userId}`);
|
||||||
Search.indexValidator(this.realTimeIndex);
|
Search.indexValidator(searchConfig.FOLDERS_CONSTANTS.TEMP_REAL_TIME_INDEX);
|
||||||
let indexDateStartFrom = new Date().getTime() - searchConfig.SEARCH_PERIOD_SUBTRACTOR;
|
let indexDateStartFrom = new Date().getTime() - searchConfig.SEARCH_PERIOD_SUBTRACTOR;
|
||||||
// Deleting all the messages except 3 Months from now
|
// Deleting all the messages except 3 Months from now
|
||||||
libSymphonySearch.symSEDeleteMessages(this.indexFolderName, null,
|
libSymphonySearch.symSEDeleteMessages(`${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${this.userId}`, null,
|
||||||
searchConfig.MINIMUM_DATE, indexDateStartFrom.toString());
|
searchConfig.MINIMUM_DATE, indexDateStartFrom.toString());
|
||||||
this.isInitialized = true;
|
this.isInitialized = true;
|
||||||
}
|
}
|
||||||
@ -115,14 +111,14 @@ class Search {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fs.existsSync(this.dataFolder)) {
|
if (!fs.existsSync(searchConfig.FOLDERS_CONSTANTS.INDEX_PATH)) {
|
||||||
log.send(logLevels.ERROR, 'User index folder not found');
|
log.send(logLevels.ERROR, 'User index folder not found');
|
||||||
reject(new Error('User index folder not found'));
|
reject(new Error('User index folder not found'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const indexId = randomString.generate(searchConfig.BATCH_RANDOM_INDEX_PATH_LENGTH);
|
const indexId = randomString();
|
||||||
libSymphonySearch.symSECreatePartialIndexAsync(this.batchIndex, indexId, messages, (err, res) => {
|
libSymphonySearch.symSECreatePartialIndexAsync(searchConfig.FOLDERS_CONSTANTS.TEMP_BATCH_INDEX_FOLDER, indexId, messages, (err, res) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
log.send(logLevels.ERROR, 'Batch Indexing: error ->' + err);
|
log.send(logLevels.ERROR, 'Batch Indexing: error ->' + err);
|
||||||
reject(new Error(err));
|
reject(new Error(err));
|
||||||
@ -140,19 +136,19 @@ class Search {
|
|||||||
mergeIndexBatches() {
|
mergeIndexBatches() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
if (!fs.existsSync(this.dataFolder)) {
|
if (!fs.existsSync(searchConfig.FOLDERS_CONSTANTS.INDEX_PATH)) {
|
||||||
log.send(logLevels.ERROR, 'User index folder not found');
|
log.send(logLevels.ERROR, 'User index folder not found');
|
||||||
reject(new Error('User index folder not found'));
|
reject(new Error('User index folder not found'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
libSymphonySearch.symSEMergePartialIndexAsync(this.indexFolderName, this.batchIndex, (err, res) => {
|
libSymphonySearch.symSEMergePartialIndexAsync(`${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${this.userId}`, searchConfig.FOLDERS_CONSTANTS.TEMP_BATCH_INDEX_FOLDER, (err, res) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
log.send(logLevels.ERROR, 'Error merging the index ->' + err);
|
log.send(logLevels.ERROR, 'Error merging the index ->' + err);
|
||||||
reject(new Error(err));
|
reject(new Error(err));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Search.deleteIndexFolders(this.batchIndex);
|
Search.deleteIndexFolders(searchConfig.FOLDERS_CONSTANTS.TEMP_BATCH_INDEX_FOLDER);
|
||||||
resolve(res);
|
resolve(res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -199,13 +195,13 @@ class Search {
|
|||||||
throw new Error('Library not initialized');
|
throw new Error('Library not initialized');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fs.existsSync(this.dataFolder)) {
|
if (!fs.existsSync(searchConfig.FOLDERS_CONSTANTS.INDEX_PATH)) {
|
||||||
log.send(logLevels.ERROR, 'User index folder not found');
|
log.send(logLevels.ERROR, 'User index folder not found');
|
||||||
throw new Error('User index folder not found');
|
throw new Error('User index folder not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isRealTimeIndexing = true;
|
this.isRealTimeIndexing = true;
|
||||||
return libSymphonySearch.symSEIndexRealTimeAsync(this.realTimeIndex, message, (err, result) => {
|
return libSymphonySearch.symSEIndexRealTimeAsync(searchConfig.FOLDERS_CONSTANTS.TEMP_REAL_TIME_INDEX, message, (err, result) => {
|
||||||
this.isRealTimeIndexing = false;
|
this.isRealTimeIndexing = false;
|
||||||
if (err) {
|
if (err) {
|
||||||
log.send(logLevels.ERROR, 'RealTime Indexing: error -> ' + err);
|
log.send(logLevels.ERROR, 'RealTime Indexing: error -> ' + err);
|
||||||
@ -222,26 +218,7 @@ class Search {
|
|||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
readJson(batch) {
|
readJson(batch) {
|
||||||
return new Promise((resolve, reject) => {
|
return readFile.call(this, batch);
|
||||||
let dirPath = path.join(searchConfig.FOLDERS_CONSTANTS.EXEC_PATH, isMac ? '..' : '', 'msgsjson', batch);
|
|
||||||
let messageFolderPath = isDevEnv ? path.join('./msgsjson', batch) : dirPath;
|
|
||||||
let files = fs.readdirSync(messageFolderPath);
|
|
||||||
this.messageData = [];
|
|
||||||
files.forEach((file) => {
|
|
||||||
let tempPath = path.join(messageFolderPath, file);
|
|
||||||
let data = fs.readFileSync(tempPath, "utf8");
|
|
||||||
if (data) {
|
|
||||||
try {
|
|
||||||
this.messageData.push(JSON.parse(data));
|
|
||||||
} catch (err) {
|
|
||||||
reject(new Error(err))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
reject(new Error('Error reading batch'))
|
|
||||||
}
|
|
||||||
});
|
|
||||||
resolve(this.messageData);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -280,7 +257,7 @@ class Search {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fs.existsSync(this.indexFolderName) || !fs.existsSync(this.realTimeIndex)) {
|
if (!fs.existsSync(`${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${this.userId}`) || !fs.existsSync(searchConfig.FOLDERS_CONSTANTS.TEMP_REAL_TIME_INDEX)) {
|
||||||
log.send(logLevels.ERROR, 'Index folder does not exist.');
|
log.send(logLevels.ERROR, 'Index folder does not exist.');
|
||||||
reject(new Error('Index folder does not exist.'));
|
reject(new Error('Index folder does not exist.'));
|
||||||
return;
|
return;
|
||||||
@ -322,7 +299,7 @@ class Search {
|
|||||||
_sortOrder = searchConfig.SORT_BY_SCORE;
|
_sortOrder = searchConfig.SORT_BY_SCORE;
|
||||||
}
|
}
|
||||||
|
|
||||||
const returnedResult = libSymphonySearch.symSESearch(this.indexFolderName, this.realTimeIndex, q, startDateTime.toString(), endDateTime.toString(), _offset, _limit, _sortOrder);
|
const returnedResult = libSymphonySearch.symSESearch(`${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${this.userId}`, searchConfig.FOLDERS_CONSTANTS.TEMP_REAL_TIME_INDEX, q, startDateTime.toString(), endDateTime.toString(), _offset, _limit, _sortOrder);
|
||||||
try {
|
try {
|
||||||
let ret = returnedResult.readCString();
|
let ret = returnedResult.readCString();
|
||||||
resolve(JSON.parse(ret));
|
resolve(JSON.parse(ret));
|
||||||
@ -345,13 +322,13 @@ class Search {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fs.existsSync(this.indexFolderName)) {
|
if (!fs.existsSync(`${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${this.userId}`)) {
|
||||||
log.send(logLevels.ERROR, 'Index folder does not exist.');
|
log.send(logLevels.ERROR, 'Index folder does not exist.');
|
||||||
reject(new Error('Index folder does not exist.'));
|
reject(new Error('Index folder does not exist.'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
libSymphonySearch.symSEGetLastMessageTimestampAsync(this.indexFolderName, (err, res) => {
|
libSymphonySearch.symSEGetLastMessageTimestampAsync(`${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${this.userId}`, (err, res) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
log.send(logLevels.ERROR, 'Error getting the index timestamp ->' + err);
|
log.send(logLevels.ERROR, 'Error getting the index timestamp ->' + err);
|
||||||
reject(new Error(err));
|
reject(new Error(err));
|
||||||
@ -367,9 +344,10 @@ class Search {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*eslint class-methods-use-this: ["error", { "exceptMethods": ["deleteRealTimeFolder"] }] */
|
||||||
deleteRealTimeFolder() {
|
deleteRealTimeFolder() {
|
||||||
Search.deleteIndexFolders(this.realTimeIndex);
|
Search.deleteIndexFolders(searchConfig.FOLDERS_CONSTANTS.TEMP_REAL_TIME_INDEX);
|
||||||
Search.indexValidator(this.realTimeIndex);
|
Search.indexValidator(searchConfig.FOLDERS_CONSTANTS.TEMP_REAL_TIME_INDEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -587,6 +565,35 @@ function deleteIndexFolder() {
|
|||||||
Search.deleteIndexFolders(searchConfig.FOLDERS_CONSTANTS.INDEX_PATH);
|
Search.deleteIndexFolders(searchConfig.FOLDERS_CONSTANTS.INDEX_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the file from the msgjson
|
||||||
|
* this is only for the demo page
|
||||||
|
* @param batch
|
||||||
|
* @returns {Promise<Array>}
|
||||||
|
*/
|
||||||
|
function readFile(batch) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let dirPath = path.join(searchConfig.FOLDERS_CONSTANTS.EXEC_PATH, isMac ? '..' : '', 'msgsjson', batch);
|
||||||
|
let messageFolderPath = isDevEnv ? path.join('./msgsjson', batch) : dirPath;
|
||||||
|
let files = fs.readdirSync(messageFolderPath);
|
||||||
|
this.messageData = [];
|
||||||
|
files.forEach((file) => {
|
||||||
|
let tempPath = path.join(messageFolderPath, file);
|
||||||
|
let data = fs.readFileSync(tempPath, "utf8");
|
||||||
|
if (data) {
|
||||||
|
try {
|
||||||
|
this.messageData.push(JSON.parse(data));
|
||||||
|
} catch (err) {
|
||||||
|
reject(new Error(err))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reject(new Error('Error reading batch'))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
resolve(this.messageData);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exporting the search library
|
* Exporting the search library
|
||||||
* @type {{Search: Search}}
|
* @type {{Search: Search}}
|
||||||
|
@ -57,7 +57,11 @@ const searchConfig = {
|
|||||||
LIBRARY_CONSTANTS: libraryPaths,
|
LIBRARY_CONSTANTS: libraryPaths,
|
||||||
FOLDERS_CONSTANTS: folderPaths,
|
FOLDERS_CONSTANTS: folderPaths,
|
||||||
TAR_LZ4_EXT: '.tar.lz4',
|
TAR_LZ4_EXT: '.tar.lz4',
|
||||||
MINIMUM_DISK_SPACE: 300000000 // in bytes
|
RANDOM_STRING: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
||||||
|
MINIMUM_DISK_SPACE: 300000000, // in bytes
|
||||||
|
PERMISSION_ERROR: "The FSUTIL utility requires that you have administrative privileges.",
|
||||||
|
WIN_PATH_ERROR: "Error: The system cannot find the path specified.",
|
||||||
|
MAC_PATH_ERROR: "No such file or directory"
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = searchConfig;
|
module.exports = searchConfig;
|
||||||
|
@ -11,8 +11,8 @@ function checkDiskSpace(path, resolve, reject) {
|
|||||||
if (isMac) {
|
if (isMac) {
|
||||||
exec("df -k '" + path.replace(/'/g,"'\\''") + "'", (error, stdout, stderr) => {
|
exec("df -k '" + path.replace(/'/g,"'\\''") + "'", (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
if (stderr.indexOf("No such file or directory") !== -1) {
|
if (stderr.indexOf(searchConfig.MAC_PATH_ERROR) !== -1) {
|
||||||
return reject(new Error("No such file or directory : " + error))
|
return reject(new Error(`${searchConfig.MAC_PATH_ERROR} ${error}`))
|
||||||
}
|
}
|
||||||
return reject(new Error("Error : " + error));
|
return reject(new Error("Error : " + error));
|
||||||
}
|
}
|
||||||
@ -25,13 +25,21 @@ function checkDiskSpace(path, resolve, reject) {
|
|||||||
return resolve(space >= searchConfig.MINIMUM_DISK_SPACE);
|
return resolve(space >= searchConfig.MINIMUM_DISK_SPACE);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
exec(`fsutil volume diskfree ${path}`, (error, stdout, stderr) => {
|
exec(`fsutil volume diskfree ${path}`, (error, stdout) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
if (stderr.indexOf("No such file or directory") !== -1) {
|
if (stdout.indexOf(searchConfig.WIN_PATH_ERROR) !== -1) {
|
||||||
return reject(new Error("No such file or directory : " + error));
|
return reject(new Error(`${searchConfig.WIN_PATH_ERROR} ${error}`));
|
||||||
|
}
|
||||||
|
if (stdout.indexOf(searchConfig.PERMISSION_ERROR) !== -1) {
|
||||||
|
// this is temporary until we use the custom exe file.
|
||||||
|
return resolve(true);
|
||||||
}
|
}
|
||||||
return reject(new Error("Error : " + error));
|
return reject(new Error("Error : " + error));
|
||||||
}
|
}
|
||||||
|
if (stdout.indexOf(searchConfig.PERMISSION_ERROR) !== -1) {
|
||||||
|
// this is temporary until we use the custom exe file.
|
||||||
|
return resolve(true);
|
||||||
|
}
|
||||||
let data = stdout.trim().split("\n");
|
let data = stdout.trim().split("\n");
|
||||||
|
|
||||||
let disk_info_str = data[data.length - 1].split(':');
|
let disk_info_str = data[data.length - 1].split(':');
|
||||||
|
15
js/search/utils/randomString.js
Normal file
15
js/search/utils/randomString.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
const searchConfig = require('../searchConfig.js');
|
||||||
|
|
||||||
|
function randomString() {
|
||||||
|
let text = "";
|
||||||
|
|
||||||
|
for (let i = 0; i < 7; i++) {
|
||||||
|
text += searchConfig.RANDOM_STRING.charAt(Math.floor(Math.random() * searchConfig.RANDOM_STRING.length));
|
||||||
|
}
|
||||||
|
let time = new Date().getTime();
|
||||||
|
return text + time;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
randomString: randomString
|
||||||
|
};
|
@ -84,7 +84,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"browserify": "^14.1.0",
|
"browserify": "^14.1.0",
|
||||||
"cross-env": "^3.2.4",
|
"cross-env": "^3.2.4",
|
||||||
"electron": "1.7.8",
|
"electron": "^1.8.2",
|
||||||
"electron-builder": "^13.9.0",
|
"electron-builder": "^13.9.0",
|
||||||
"electron-builder-squirrel-windows": "^12.3.0",
|
"electron-builder-squirrel-windows": "^12.3.0",
|
||||||
"electron-packager": "^8.5.2",
|
"electron-packager": "^8.5.2",
|
||||||
@ -117,7 +117,6 @@
|
|||||||
"lodash.omit": "^4.5.0",
|
"lodash.omit": "^4.5.0",
|
||||||
"lodash.pick": "^4.4.0",
|
"lodash.pick": "^4.4.0",
|
||||||
"parse-domain": "^2.0.0",
|
"parse-domain": "^2.0.0",
|
||||||
"randomstring": "^1.1.5",
|
|
||||||
"ref": "^1.3.4",
|
"ref": "^1.3.4",
|
||||||
"shell-path": "^2.1.0",
|
"shell-path": "^2.1.0",
|
||||||
"winreg": "^1.2.3"
|
"winreg": "^1.2.3"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
const childProcess = require('child_process');
|
const childProcess = require('child_process');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { isMac } = require('../js/utils/misc.js');
|
const { isWindowsOS } = require('../js/utils/misc.js');
|
||||||
|
|
||||||
let executionPath = null;
|
let executionPath = null;
|
||||||
let userConfigDir = null;
|
let userConfigDir = null;
|
||||||
@ -46,7 +46,7 @@ describe('Tests for Search', function() {
|
|||||||
key = 'jjjehdnctsjyieoalskcjdhsnahsadndfnusdfsdfsd=';
|
key = 'jjjehdnctsjyieoalskcjdhsnahsadndfnusdfsdfsd=';
|
||||||
|
|
||||||
executionPath = path.join(__dirname, 'library');
|
executionPath = path.join(__dirname, 'library');
|
||||||
if (!isMac) {
|
if (isWindowsOS) {
|
||||||
executionPath = path.join(__dirname, '..', 'library');
|
executionPath = path.join(__dirname, '..', 'library');
|
||||||
}
|
}
|
||||||
userConfigDir = path.join(__dirname, '..');
|
userConfigDir = path.join(__dirname, '..');
|
||||||
@ -59,7 +59,7 @@ describe('Tests for Search', function() {
|
|||||||
tempBatchPath = path.join(userConfigDir, 'data', 'temp_batch_indexes');
|
tempBatchPath = path.join(userConfigDir, 'data', 'temp_batch_indexes');
|
||||||
dataFolderPath = path.join(userConfigDir, 'data');
|
dataFolderPath = path.join(userConfigDir, 'data');
|
||||||
if (fs.existsSync(dataFolderPath)) {
|
if (fs.existsSync(dataFolderPath)) {
|
||||||
fs.unlinkSync(dataFolderPath)
|
deleteIndexFolders(dataFolderPath)
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -98,10 +98,6 @@ describe('Tests for Search', function() {
|
|||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
|
||||||
expect(SearchApi.isInitialized).toBe(true);
|
expect(SearchApi.isInitialized).toBe(true);
|
||||||
expect(SearchApi.indexFolderName).toBe(`${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME_PATH}_${userId}`);
|
|
||||||
expect(SearchApi.dataFolder).toBe(searchConfig.FOLDERS_CONSTANTS.INDEX_PATH);
|
|
||||||
expect(SearchApi.realTimeIndex).toBe(searchConfig.FOLDERS_CONSTANTS.TEMP_REAL_TIME_INDEX);
|
|
||||||
expect(SearchApi.batchIndex).toBe(searchConfig.FOLDERS_CONSTANTS.TEMP_BATCH_INDEX_FOLDER);
|
|
||||||
expect(SearchApi.messageData).toEqual([]);
|
expect(SearchApi.messageData).toEqual([]);
|
||||||
expect(SearchApi.isRealTimeIndexing).toBe(false);
|
expect(SearchApi.isRealTimeIndexing).toBe(false);
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { isMac } = require('../js/utils/misc.js');
|
const { isMac, isWindowsOS } = require('../js/utils/misc.js');
|
||||||
|
|
||||||
let executionPath = null;
|
let executionPath = null;
|
||||||
let userConfigDir = null;
|
let userConfigDir = null;
|
||||||
@ -33,6 +33,9 @@ describe('Tests for Search Utils', function() {
|
|||||||
|
|
||||||
beforeAll(function (done) {
|
beforeAll(function (done) {
|
||||||
executionPath = path.join(__dirname, 'library');
|
executionPath = path.join(__dirname, 'library');
|
||||||
|
if (isWindowsOS) {
|
||||||
|
executionPath = path.join(__dirname, '..', 'library');
|
||||||
|
}
|
||||||
userConfigDir = path.join(__dirname, '..');
|
userConfigDir = path.join(__dirname, '..');
|
||||||
searchConfig = require('../js/search/searchConfig.js');
|
searchConfig = require('../js/search/searchConfig.js');
|
||||||
const { SearchUtils } = require('../js/search/searchUtils.js');
|
const { SearchUtils } = require('../js/search/searchUtils.js');
|
||||||
@ -81,7 +84,7 @@ describe('Tests for Search Utils', function() {
|
|||||||
it('should return error invalid path', function (done) {
|
it('should return error invalid path', function (done) {
|
||||||
const checkFreeSpace = jest.spyOn(SearchUtilsAPI, 'checkFreeSpace');
|
const checkFreeSpace = jest.spyOn(SearchUtilsAPI, 'checkFreeSpace');
|
||||||
SearchUtilsAPI.path = './tp';
|
SearchUtilsAPI.path = './tp';
|
||||||
if (!isMac) {
|
if (isWindowsOS) {
|
||||||
SearchUtilsAPI.path = 'A://test';
|
SearchUtilsAPI.path = 'A://test';
|
||||||
}
|
}
|
||||||
SearchUtilsAPI.checkFreeSpace().catch(function (err) {
|
SearchUtilsAPI.checkFreeSpace().catch(function (err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user