Fixed DbExpire with NeDB.

Ylian Saint-Hilaire committed Jul 8, 2020 at 14:29 UTC 3079f0185c1871b5c0a61790b49c8366bee02fcf
3 files changed +23 -18
db.js
+3 -3
@@ -681,13 +681,13 @@ module.exports.CreateDB = function (parent, func) {
681 obj.eventsfile.persistence.setAutocompactionInterval(86400000); // Compact once a day
682 obj.eventsfile.ensureIndex({ fieldName: 'ids' }); // TODO: Not sure if this is a good index, this is a array field.
683 obj.eventsfile.ensureIndex({ fieldName: 'nodeid', sparse: true });
684 - obj.eventsfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: 60 * 60 * 24 * 20 }); // Limit the power event log to 20 days (Seconds * Minutes * Hours * Days)
684 + obj.eventsfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: expireEventsSeconds });
685
686 // Setup the power collection and setup indexes
687 obj.powerfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-power.db'), autoload: true });
688 obj.powerfile.persistence.setAutocompactionInterval(86400000); // Compact once a day
689 obj.powerfile.ensureIndex({ fieldName: 'nodeid' });
690 - obj.powerfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: 60 * 60 * 24 * 10 }); // Limit the power event log to 10 days (Seconds * Minutes * Hours * Days)
690 + obj.powerfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: expirePowerEventsSeconds });
691
692 // Setup the SMBIOS collection
693 obj.smbiosfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-smbios.db'), autoload: true });
@@ -695,7 +695,7 @@ module.exports.CreateDB = function (parent, func) {
695 // Setup the server stats collection and setup indexes
696 obj.serverstatsfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-stats.db'), autoload: true });
697 obj.serverstatsfile.persistence.setAutocompactionInterval(86400000); // Compact once a day
698 - obj.serverstatsfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: 60 * 60 * 24 * 30 }); // Limit the server stats log to 30 days (Seconds * Minutes * Hours * Days)
698 + obj.serverstatsfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: expireServerStatsSeconds });
699 obj.serverstatsfile.ensureIndex({ fieldName: 'expire', expireAfterSeconds: 0 }); // Auto-expire events
700
701 // Setup plugin info collection
translate/translate.json
+12 -5
@@ -5284,7 +5284,7 @@
5284 "en": "ChatSession",
5285 "nl": "Chat sessie",
5286 "xloc": [
5287 - "messenger.handlebars->13->14"
5287 + "messenger.handlebars->13->16"
5288 ]
5289 },
5290 {
@@ -6522,7 +6522,7 @@
6522 "ru": "Подключено.",
6523 "zh-chs": "連接的。",
6524 "xloc": [
6525 - "messenger.handlebars->13->12"
6525 + "messenger.handlebars->13->14"
6526 ]
6527 },
6528 {
@@ -8999,7 +8999,7 @@
8999 "zh-chs": "下載",
9000 "xloc": [
9001 "download.handlebars->container->page_content->column_l->1",
9002 - "messenger.handlebars->13->10"
9002 + "messenger.handlebars->13->11"
9003 ]
9004 },
9005 {
@@ -10675,7 +10675,7 @@
10675 "ru": "Ошибка: Не указан ключ подключения.",
10676 "zh-chs": "錯誤:未指定連接密鑰。",
10677 "xloc": [
10678 - "messenger.handlebars->13->13"
10678 + "messenger.handlebars->13->15"
10679 ]
10680 },
10681 {
@@ -28593,7 +28593,7 @@
28593 "ru": "В ожидании другой стороны...",
28594 "zh-chs": "正在等待其他用戶...",
28595 "xloc": [
28596 - "messenger.handlebars->13->11"
28596 + "messenger.handlebars->13->13"
28597 ]
28598 },
28599 {
@@ -29942,6 +29942,13 @@
29942 "default.handlebars->27->454"
29943 ]
29944 },
29945 + {
29946 + "en": "bytes",
29947 + "xloc": [
29948 + "messenger.handlebars->13->10",
29949 + "messenger.handlebars->13->12"
29950 + ]
29951 + },
29952 {
29953 "cs": "klikněte zde",
29954 "de": "hier klicken",
views/messenger.handlebars
+8 -10
@@ -62,7 +62,7 @@
62 var webrtcconfiguration = '{{{webrtconfig}}}';
63 if (webrtcconfiguration == '') { webrtcconfiguration = null; } else { try { webrtcconfiguration = JSON.parse(decodeURIComponent(webrtcconfiguration)); } catch (ex) { console.log('Invalid WebRTC config: "' + webrtcconfiguration + '".'); webrtcconfiguration = null; } }
64 var windowFocus = true;
65 - var chatTestSession = new Date().toString() + '\r\n';
65 + var chatTextSession = new Date().toString() + '\r\n';
66
67 // File transfer state
68 var fileUploads = [];
@@ -121,7 +121,7 @@
121 }
122
123 function onUserInputFocus(x) { userInputFocus = x; }
124 - function displayClear() { chatTestSession = new Date().toString() + '\r\n'; QH('xmsg', ''); cancelAllFileTransfers(); fileUploads = [], fileDownloads = {}; }
124 + function displayClear() { chatTextSession = new Date().toString() + '\r\n'; QH('xmsg', ''); cancelAllFileTransfers(); fileUploads = [], fileDownloads = {}; }
125
126 // Polyfill FileReader if needed
127 if (!FileReader.prototype.readAsBinaryString) {
@@ -156,7 +156,7 @@
156
157 // Display a control message
158 function displayControl(msg) {
159 - chatTestSession += ("Control" + '> ' + msg + '\r\n');
159 + chatTextSession += ((new Date()).toLocaleTimeString() + ' - ' + "Control" + '> ' + msg + '\r\n');
160 QA('xmsg', '<div style="clear:both"><div style="color:gray;float:left;margin-bottom:2px">' + EscapeHtml(msg) + '</div><div></div></div>');
161 Q('xmsgparent').scrollTop = Q('xmsgparent').scrollHeight;//Q('xmsg').scrollHeight;
162 }
@@ -171,7 +171,7 @@
171
172 // Display a message from the remote user
173 function displayRemote(msg) {
174 - chatTestSession += ("Remote" + '> ' + msg + '\r\n');
174 + chatTextSession += ((new Date()).toLocaleTimeString() + ' - ' + "Remote" + '> ' + msg + '\r\n');
175 QA('xmsg', '<div style="clear:both"><div class="remoteBubble">' + EscapeHtml(msg) + '</div><div></div></div>');
176 Q('xmsgparent').scrollTop = Q('xmsgparent').scrollHeight;
177
@@ -194,7 +194,7 @@
194 var outtext = Q('xouttext').value;
195 if (outtext.length > 0) {
196 Q('xouttext').value = '';
197 - chatTestSession += ("Local" + '> ' + outtext + '\r\n');
197 + chatTextSession += ((new Date()).toLocaleTimeString() + ' - ' + "Local" + '> ' + outtext + '\r\n');
198 QA('xmsg', '<div style="clear:both"><div class="localBubble">' + EscapeHtml(outtext) + '</div><div></div></div>');
199 Q('xmsgparent').scrollTop = Q('xmsgparent').scrollHeight;
200 send({ action: 'chat', msg: outtext });
@@ -429,8 +429,7 @@
429 if (state != 2) return;
430 file.id = Math.random();
431 fileUploads.push(file);
432 - console.log(file);
433 - chatTestSession += ("Upload" + '> ' + file.name + '\r\n');
432 + chatTextSession += ((new Date()).toLocaleTimeString() + ' - ' + "Upload" + '> ' + file.name + ' (' + file.size + ' ' + "bytes" + ')\r\n');
433 QA('xmsg', '<div style="clear:both"></div><div id="FILEUP-' + file.id + '" class="localBubble" style="width:240px;cursor:pointer" onclick="cancelFileTransfer(\'' + file.id + '\')"><div id="FILEUP-ICON-' + file.id + '" class="fileicon" style="float:left;width:32px;height:32px"></div><div><div id="FILEUP-NAME-' + file.id + '" style="height:16px;overflow:hidden;white-space:nowrap;" title="' + file.name + '">' + file.name + '</div><div style="width:200px;background-color:lightgray;margin-left:32px;border-radius:3px;margin-top:3px;height:11px"><div id="FILEUP-PROGRESS-' + file.id + '" style="width:0px;background-color:green;border-radius:3px;height:11px">&nbsp;</div></div></div></div>');
434 Q('xmsgparent').scrollTop = Q('xmsgparent').scrollHeight;
435 send({ action: 'file', size: file.size, id: file.id, type: file.type, name: file.name });
@@ -440,8 +439,7 @@
439 function startFileDownload(file) {
440 if (state != 2) return;
441 fileDownloads[file.id] = file;
443 - console.log(file);
444 - chatTestSession += ("Download" + '> ' + file.name + '\r\n');
442 + chatTextSession += ((new Date()).toLocaleTimeString() + ' - ' + "Download" + '> ' + file.name + ' (' + file.size + ' ' + "bytes" + ')\r\n');
443 QA('xmsg', '<div style="clear:both"></div><div id="FILEUP-' + file.id + '" class="remoteBubble" style="width:240px;cursor:pointer" onclick="saveFileTransfer(\'' + file.id + '\')"><div id="FILEUP-ICON-' + file.id + '" class="fileicon" style="float:left;width:32px;height:32px"></div><div><div id="FILEUP-NAME-' + file.id + '" style="height:16px;overflow:hidden;white-space:nowrap;" title="' + file.name + '">' + file.name + '</div><div style="width:200px;background-color:lightgray;margin-left:32px;border-radius:3px;margin-top:3px;height:11px"><div id="FILEUP-PROGRESS-' + file.id + '" style="width:0px;background-color:green;border-radius:3px;height:11px">&nbsp;</div></div></div></div>');
444 Q('xmsgparent').scrollTop = Q('xmsgparent').scrollHeight;
445 }
@@ -646,7 +644,7 @@
644 }
645
646 function saveChatSession() {
649 - saveAs(data2blob(chatTestSession), "ChatSession");
647 + saveAs(data2blob(chatTextSession), "ChatSession");
648 }
649
650 start();