mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	fix initial document setup
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								db/demo.tar
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								db/demo.tar
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -96,19 +96,6 @@ CREATE TABLE attributes | |||||||
|   hash         TEXT default "" not null, isInheritable int DEFAULT 0 NULL); |   hash         TEXT default "" not null, isInheritable int DEFAULT 0 NULL); | ||||||
| CREATE INDEX IDX_attributes_name_value | CREATE INDEX IDX_attributes_name_value | ||||||
|   on attributes (name, value); |   on attributes (name, value); | ||||||
| CREATE TABLE IF NOT EXISTS "notes" ( |  | ||||||
|   `noteId`	TEXT NOT NULL, |  | ||||||
|   `title`	TEXT NOT NULL DEFAULT "note", |  | ||||||
|   `content`	TEXT NULL DEFAULT NULL, |  | ||||||
|   `isProtected`	INT NOT NULL DEFAULT 0, |  | ||||||
|   `type` TEXT NOT NULL DEFAULT 'text', |  | ||||||
|   `mime` TEXT NOT NULL DEFAULT 'text/html', |  | ||||||
|   `hash` TEXT DEFAULT "" NOT NULL, |  | ||||||
|   `isDeleted`	INT NOT NULL DEFAULT 0, |  | ||||||
|   `dateCreated`	TEXT NOT NULL, |  | ||||||
|   `dateModified`	TEXT NOT NULL, |  | ||||||
|   PRIMARY KEY(`noteId`) |  | ||||||
| ); |  | ||||||
| CREATE TABLE IF NOT EXISTS "links" ( | CREATE TABLE IF NOT EXISTS "links" ( | ||||||
|   `linkId`	TEXT NOT NULL, |   `linkId`	TEXT NOT NULL, | ||||||
|   `noteId`	TEXT NOT NULL, |   `noteId`	TEXT NOT NULL, | ||||||
| @@ -130,3 +117,26 @@ CREATE INDEX IDX_attributes_noteId_index | |||||||
|   on attributes (noteId); |   on attributes (noteId); | ||||||
| CREATE INDEX IDX_attributes_value_index | CREATE INDEX IDX_attributes_value_index | ||||||
|   on attributes (value); |   on attributes (value); | ||||||
|  | CREATE TABLE IF NOT EXISTS "note_contents" ( | ||||||
|  |   `noteContentId`	TEXT NOT NULL, | ||||||
|  |   `noteId`	TEXT NOT NULL, | ||||||
|  |   `isProtected`	INT NOT NULL DEFAULT 0, | ||||||
|  |   `content`	TEXT NULL DEFAULT NULL, | ||||||
|  |   `hash` TEXT DEFAULT "" NOT NULL, | ||||||
|  |   `dateCreated`	TEXT NOT NULL, | ||||||
|  |   `dateModified` TEXT NOT NULL, | ||||||
|  |   PRIMARY KEY(`noteContentId`) | ||||||
|  | ); | ||||||
|  | CREATE UNIQUE INDEX `IDX_note_contents_noteId` ON `note_contents` (`noteId`); | ||||||
|  | CREATE TABLE IF NOT EXISTS "notes" ( | ||||||
|  |   `noteId`	TEXT NOT NULL, | ||||||
|  |   `title`	TEXT NOT NULL DEFAULT "note", | ||||||
|  |   `isProtected`	INT NOT NULL DEFAULT 0, | ||||||
|  |   `type` TEXT NOT NULL DEFAULT 'text', | ||||||
|  |   `mime` TEXT NOT NULL DEFAULT 'text/html', | ||||||
|  |   `hash` TEXT DEFAULT "" NOT NULL, | ||||||
|  |   `isDeleted`	INT NOT NULL DEFAULT 0, | ||||||
|  |   `dateCreated`	TEXT NOT NULL, | ||||||
|  |   `dateModified`	TEXT NOT NULL, | ||||||
|  |   PRIMARY KEY(`noteId`) | ||||||
|  | ); | ||||||
|   | |||||||
| @@ -5,55 +5,11 @@ const enexImportService = require('../../services/import/enex'); | |||||||
| const opmlImportService = require('../../services/import/opml'); | const opmlImportService = require('../../services/import/opml'); | ||||||
| const tarImportService = require('../../services/import/tar'); | const tarImportService = require('../../services/import/tar'); | ||||||
| const singleImportService = require('../../services/import/single'); | const singleImportService = require('../../services/import/single'); | ||||||
| const messagingService = require('../../services/messaging'); |  | ||||||
| const cls = require('../../services/cls'); | const cls = require('../../services/cls'); | ||||||
| const path = require('path'); | const path = require('path'); | ||||||
| const noteCacheService = require('../../services/note_cache'); | const noteCacheService = require('../../services/note_cache'); | ||||||
| const log = require('../../services/log'); | const log = require('../../services/log'); | ||||||
|  | const ImportContext = require('../../services/import_context'); | ||||||
| class ImportContext { |  | ||||||
|     constructor(importId, safeImport) { |  | ||||||
|         // importId is to distinguish between different import events - it is possible (though not recommended) |  | ||||||
|         // to have multiple imports going at the same time |  | ||||||
|         this.importId = importId; |  | ||||||
|  |  | ||||||
|         this.safeImport = safeImport; |  | ||||||
|  |  | ||||||
|         // // count is mean to represent count of exported notes where practical, otherwise it's just some measure of progress |  | ||||||
|         this.progressCount = 0; |  | ||||||
|         this.lastSentCountTs = Date.now(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     async increaseProgressCount() { |  | ||||||
|         this.progressCount++; |  | ||||||
|  |  | ||||||
|         if (Date.now() - this.lastSentCountTs >= 500) { |  | ||||||
|             this.lastSentCountTs = Date.now(); |  | ||||||
|  |  | ||||||
|             await messagingService.sendMessageToAllClients({ |  | ||||||
|                 importId: this.importId, |  | ||||||
|                 type: 'import-progress-count', |  | ||||||
|                 progressCount: this.progressCount |  | ||||||
|             }); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     async importFinished(noteId) { |  | ||||||
|         await messagingService.sendMessageToAllClients({ |  | ||||||
|             importId: this.importId, |  | ||||||
|             type: 'import-finished', |  | ||||||
|             noteId: noteId |  | ||||||
|         }); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     // must remaing non-static |  | ||||||
|     async reportError(message) { |  | ||||||
|         await messagingService.sendMessageToAllClients({ |  | ||||||
|             type: 'import-error', |  | ||||||
|             message: message |  | ||||||
|         }); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| async function importToBranch(req) { | async function importToBranch(req) { | ||||||
|     let {parentNoteId, importId, safeImport} = req.params; |     let {parentNoteId, importId, safeImport} = req.params; | ||||||
|   | |||||||
| @@ -13,9 +13,7 @@ const stream = require('stream'); | |||||||
| const path = require('path'); | const path = require('path'); | ||||||
| const commonmark = require('commonmark'); | const commonmark = require('commonmark'); | ||||||
| const mimeTypes = require('mime-types'); | const mimeTypes = require('mime-types'); | ||||||
|  | const ImportContext = require('../import_context'); | ||||||
| let importNoteCount; |  | ||||||
| let lastSentCountTs = Date.now(); |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * @param {ImportContext} importContext |  * @param {ImportContext} importContext | ||||||
| @@ -24,7 +22,8 @@ let lastSentCountTs = Date.now(); | |||||||
|  * @return {Promise<*>} |  * @return {Promise<*>} | ||||||
|  */ |  */ | ||||||
| async function importTar(importContext, fileBuffer, importRootNote) { | async function importTar(importContext, fileBuffer, importRootNote) { | ||||||
|     importNoteCount = 0; |     importContext = importContext || new ImportContext("1", false); | ||||||
|  |  | ||||||
|     // maps from original noteId (in tar file) to newly generated noteId |     // maps from original noteId (in tar file) to newly generated noteId | ||||||
|     const noteIdMap = {}; |     const noteIdMap = {}; | ||||||
|     const attributes = []; |     const attributes = []; | ||||||
|   | |||||||
							
								
								
									
										49
									
								
								src/services/import_context.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								src/services/import_context.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,49 @@ | |||||||
|  | "use strict"; | ||||||
|  |  | ||||||
|  | const messagingService = require('./messaging'); | ||||||
|  |  | ||||||
|  | class ImportContext { | ||||||
|  |     constructor(importId, safeImport) { | ||||||
|  |         // importId is to distinguish between different import events - it is possible (though not recommended) | ||||||
|  |         // to have multiple imports going at the same time | ||||||
|  |         this.importId = importId; | ||||||
|  |  | ||||||
|  |         this.safeImport = safeImport; | ||||||
|  |  | ||||||
|  |         // // count is mean to represent count of exported notes where practical, otherwise it's just some measure of progress | ||||||
|  |         this.progressCount = 0; | ||||||
|  |         this.lastSentCountTs = Date.now(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     async increaseProgressCount() { | ||||||
|  |         this.progressCount++; | ||||||
|  |  | ||||||
|  |         if (Date.now() - this.lastSentCountTs >= 500) { | ||||||
|  |             this.lastSentCountTs = Date.now(); | ||||||
|  |  | ||||||
|  |             await messagingService.sendMessageToAllClients({ | ||||||
|  |                 importId: this.importId, | ||||||
|  |                 type: 'import-progress-count', | ||||||
|  |                 progressCount: this.progressCount | ||||||
|  |             }); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     async importFinished(noteId) { | ||||||
|  |         await messagingService.sendMessageToAllClients({ | ||||||
|  |             importId: this.importId, | ||||||
|  |             type: 'import-finished', | ||||||
|  |             noteId: noteId | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     // must remaing non-static | ||||||
|  |     async reportError(message) { | ||||||
|  |         await messagingService.sendMessageToAllClients({ | ||||||
|  |             type: 'import-error', | ||||||
|  |             message: message | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | module.exports = ImportContext; | ||||||
| @@ -77,16 +77,21 @@ async function createInitialDatabase(username, password) { | |||||||
|         await sql.executeScript(schema); |         await sql.executeScript(schema); | ||||||
|  |  | ||||||
|         const Note = require("../entities/note"); |         const Note = require("../entities/note"); | ||||||
|  |         const NoteContent = require("../entities/note_content"); | ||||||
|         const Branch = require("../entities/branch"); |         const Branch = require("../entities/branch"); | ||||||
|  |  | ||||||
|         const rootNote = await new Note({ |         const rootNote = await new Note({ | ||||||
|             noteId: 'root', |             noteId: 'root', | ||||||
|             title: 'root', |             title: 'root', | ||||||
|             content: '', |  | ||||||
|             type: 'text', |             type: 'text', | ||||||
|             mime: 'text/html' |             mime: 'text/html' | ||||||
|         }).save(); |         }).save(); | ||||||
|  |  | ||||||
|  |         const rootNoteContent = await new NoteContent({ | ||||||
|  |             noteId: rootNote.noteId, | ||||||
|  |             content: '' | ||||||
|  |         }).save(); | ||||||
|  |  | ||||||
|         await new Branch({ |         await new Branch({ | ||||||
|             branchId: 'root', |             branchId: 'root', | ||||||
|             noteId: 'root', |             noteId: 'root', | ||||||
| @@ -96,7 +101,7 @@ async function createInitialDatabase(username, password) { | |||||||
|         }).save(); |         }).save(); | ||||||
|  |  | ||||||
|         const tarImportService = require("./import/tar"); |         const tarImportService = require("./import/tar"); | ||||||
|         await tarImportService.importTar(demoFile, rootNote); |         await tarImportService.importTar(null, demoFile, rootNote); | ||||||
|  |  | ||||||
|         const startNoteId = await sql.getValue("SELECT noteId FROM branches WHERE parentNoteId = 'root' AND isDeleted = 0 ORDER BY notePosition"); |         const startNoteId = await sql.getValue("SELECT noteId FROM branches WHERE parentNoteId = 'root' AND isDeleted = 0 ORDER BY notePosition"); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user