mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	added option for help sha256
This commit is contained in:
		| @@ -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 | ||||
| }; | ||||
|   | ||||
| @@ -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() { | ||||
|   | ||||
| @@ -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 | ||||
|     ELECTRON_APP_ROOT_DIR, | ||||
|     HELP_ZIP_DIR | ||||
| }; | ||||
| @@ -55,7 +55,7 @@ sqlInit.dbReady.then(() => { | ||||
|     cls.init(() => { | ||||
|         hiddenSubtreeService.checkHiddenSubtree(); | ||||
|  | ||||
|         helpImportService.importHelp(); | ||||
|         helpImportService.importHelpIfNeeded(); | ||||
|     }); | ||||
|  | ||||
|     if (!process.env.TRILIUM_SAFE_MODE) { | ||||
|   | ||||
| @@ -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 = []; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user