Skip to content

Build your personal knowledge base with Trilium Notes

added option for help sha256

zadamdf47679c7ff2
diff --git a/src/services/help_import.js b/src/services/help_import.js
index 23eb20d228..959b7ad9f1 100644
--- a/src/services/help_import.js
+++ b/src/services/help_import.js
@@ -1,8 +1,6 @@
"use strict"
-const cls = require("./cls");
const becca = require("../becca/becca");
-const beccaLoader = require("../becca/becca_loader");
const fs = require("fs").promises;
const Attribute = require('../becca/entities/attribute');
const utils = require('./utils');
@@ -14,14 +12,30 @@ const path = require('path');
const yauzl = require("yauzl");
const htmlSanitizer = require('./html_sanitizer');
const sql = require('./sql');
+const options = require('./options');
+const {HELP_ZIP_DIR} = require('./resource_dir');
-const HELP_FILE_PATH = '/home/adam/Downloads/Help4.zip';
+async function importHelpIfNeeded() {
+ const helpSha256HashInDb = options.getOption('helpSha256Hash');
+ let helpSha256HashInFile = await fs.readFile(HELP_ZIP_DIR + "/help.zip.sha256");
+
+ if (!helpSha256HashInFile || helpSha256HashInFile.byteLength < 64) {
+ return;
+ }
+
+ helpSha256HashInFile = helpSha256HashInFile.toString().substr(0, 64);
+
+ if (helpSha256HashInDb === helpSha256HashInFile) {
+ // help file has been already imported and is up to date
+ return;
+ }
-async function importHelp() {
const hiddenRoot = becca.getNote("_hidden");
- const data = await fs.readFile(HELP_FILE_PATH, "binary");
+ const data = await fs.readFile(HELP_ZIP_DIR + "/" + "help.zip", "binary");
await importZip(Buffer.from(data, 'binary'), hiddenRoot);
+
+ options.setOption('helpSha256Hash', helpSha256HashInFile);
}
async function importZip(fileBuffer, importRootNote) {
@@ -477,5 +491,5 @@ function readZipFile(buffer, processEntryCallback) {
}
module.exports = {
- importHelp
-}
+ importHelpIfNeeded
+};
diff --git a/src/services/options_init.js b/src/services/options_init.js
index fd66718f8c..630c5ea2f8 100644
--- a/src/services/options_init.js
+++ b/src/services/options_init.js
@@ -89,6 +89,7 @@ const defaultOptions = [
{ name: 'minTocHeadings', value: '5', isSynced: true },
{ name: 'checkForUpdates', value: 'true', isSynced: true },
{ name: 'disableTray', value: 'false', isSynced: false },
+ { name: 'helpSha256Hash', value: '', isSynced: true },
];
function initStartupOptions() {
diff --git a/src/services/resource_dir.js b/src/services/resource_dir.js
index ba05b70e7a..fd98be4c32 100644
--- a/src/services/resource_dir.js
+++ b/src/services/resource_dir.js
@@ -20,9 +20,12 @@ if (!fs.existsSync(MIGRATIONS_DIR)) {
process.exit(1);
}
+const HELP_ZIP_DIR = path.resolve(RESOURCE_DIR, "tmp");
+
module.exports = {
RESOURCE_DIR,
MIGRATIONS_DIR,
DB_INIT_DIR,
- ELECTRON_APP_ROOT_DIR
-};
\ No newline at end of file
+ ELECTRON_APP_ROOT_DIR,
+ HELP_ZIP_DIR
+};
diff --git a/src/services/scheduler.js b/src/services/scheduler.js
index 82b17dd4d3..25a769d21c 100644
--- a/src/services/scheduler.js
+++ b/src/services/scheduler.js
@@ -55,7 +55,7 @@ sqlInit.dbReady.then(() => {
cls.init(() => {
hiddenSubtreeService.checkHiddenSubtree();
- helpImportService.importHelp();
+ helpImportService.importHelpIfNeeded();
});
if (!process.env.TRILIUM_SAFE_MODE) {
diff --git a/src/services/search/expressions/note_flat_text.js b/src/services/search/expressions/note_flat_text.js
index 002992a511..670b34d4b7 100644
--- a/src/services/search/expressions/note_flat_text.js
+++ b/src/services/search/expressions/note_flat_text.js
@@ -123,7 +123,7 @@ class NoteFlatTextExp extends Expression {
* Returns noteIds which have at least one matching tokens
*
* @param {NoteSet} noteSet
- * @return {String[]}
+ * @return {Note[]}
*/
getCandidateNotes(noteSet) {
const candidateNotes = [];