mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	becca conversion WIP
This commit is contained in:
		| @@ -66,7 +66,7 @@ function note(title, extraParams = {}) { | ||||
|         mime: 'text/html' | ||||
|     }, extraParams); | ||||
|  | ||||
|     const note = new Note(becca, row); | ||||
|     const note = new Note(row); | ||||
|  | ||||
|     return new NoteBuilder(note); | ||||
| } | ||||
|   | ||||
| @@ -12,7 +12,7 @@ describe("Search", () => { | ||||
|     beforeEach(() => { | ||||
|         becca.reset(); | ||||
|  | ||||
|         rootNote = new NoteBuilder(new Note(becca, {noteId: 'root', title: 'root', type: 'text'})); | ||||
|         rootNote = new NoteBuilder(new Note({noteId: 'root', title: 'root', type: 'text'})); | ||||
|         new Branch(becca, {branchId: 'root', noteId: 'root', parentNoteId: 'none', notePosition: 10}); | ||||
|     }); | ||||
|  | ||||
|   | ||||
| @@ -1,34 +0,0 @@ | ||||
| "use strict"; | ||||
|  | ||||
| const Entity = require('./entity'); | ||||
| const dateUtils = require('../services/date_utils'); | ||||
|  | ||||
| /** | ||||
|  * ApiToken is an entity representing token used to authenticate against Trilium API from client applications. Currently used only by Trilium Sender. | ||||
|  * | ||||
|  * @property {string} apiTokenId - primary key | ||||
|  * @property {string} token | ||||
|  * @property {boolean} isDeleted - true if API token is deleted | ||||
|  * @property {string} utcDateCreated | ||||
|  * | ||||
|  * @extends Entity | ||||
|  */ | ||||
| class ApiToken extends Entity { | ||||
|     static get entityName() { return "api_tokens"; } | ||||
|     static get primaryKeyName() { return "apiTokenId"; } | ||||
|     static get hashedProperties() { return ["apiTokenId", "token", "utcDateCreated", "isDeleted"]; } | ||||
|  | ||||
|     beforeSaving() { | ||||
|         if (!this.isDeleted) { | ||||
|             this.isDeleted = false; | ||||
|         } | ||||
|  | ||||
|         if (!this.utcDateCreated) { | ||||
|             this.utcDateCreated = dateUtils.utcNowDateTime(); | ||||
|         } | ||||
|  | ||||
|         super.beforeSaving(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| module.exports = ApiToken; | ||||
| @@ -4,7 +4,7 @@ const NoteRevision = require('../services/becca/entities/note_revision.js'); | ||||
| const Branch = require('../entities/branch'); | ||||
| const Attribute = require('../entities/attribute'); | ||||
| const RecentNote = require('../services/becca/entities/recent_note.js'); | ||||
| const ApiToken = require('../entities/api_token'); | ||||
| const ApiToken = require('../services/becca/entities/api_token.js'); | ||||
| const cls = require('../services/cls'); | ||||
|  | ||||
| const ENTITY_NAME_TO_ENTITY = { | ||||
|   | ||||
| @@ -4,7 +4,7 @@ const sql = require('../../services/sql'); | ||||
| const log = require('../../services/log'); | ||||
| const attributeService = require('../../services/attributes'); | ||||
| const repository = require('../../services/repository'); | ||||
| const Attribute = require('../../entities/attribute'); | ||||
| const Attribute = require('../../services/becca/entities/attribute'); | ||||
| const becca = require("../../services/becca/becca"); | ||||
|  | ||||
| function getEffectiveNoteAttributes(req) { | ||||
| @@ -56,7 +56,6 @@ function updateNoteAttribute(req) { | ||||
|  | ||||
|     if (attribute.type === 'label' || body.value.trim()) { | ||||
|         attribute.value = body.value; | ||||
|         attribute.isDeleted = false; | ||||
|     } | ||||
|     else { | ||||
|         // relations should never have empty target | ||||
|   | ||||
| @@ -10,7 +10,7 @@ const ws = require('../../services/ws.js'); | ||||
| const log = require('../../services/log'); | ||||
| const utils = require('../../services/utils'); | ||||
| const path = require('path'); | ||||
| const Attribute = require('../../entities/attribute'); | ||||
| const Attribute = require('../../services/becca/entities/attribute'); | ||||
| const htmlSanitizer = require('../../services/html_sanitizer'); | ||||
|  | ||||
| function findClippingNote(todayNote, pageUrl) { | ||||
|   | ||||
| @@ -12,7 +12,7 @@ const cls = require('../../services/cls'); | ||||
| const sqlInit = require('../../services/sql_init'); | ||||
| const sql = require('../../services/sql'); | ||||
| const optionService = require('../../services/options'); | ||||
| const ApiToken = require('../../entities/api_token'); | ||||
| const ApiToken = require('../../services/becca/entities/api_token.js'); | ||||
|  | ||||
| function loginSync(req) { | ||||
|     if (!sqlInit.schemaExists()) { | ||||
|   | ||||
| @@ -3,7 +3,7 @@ | ||||
| const searchService = require('./search/services/search'); | ||||
| const sql = require('./sql'); | ||||
| const becca = require('./becca/becca.js'); | ||||
| const Attribute = require('../entities/attribute'); | ||||
| const Attribute = require('./becca/entities/attribute'); | ||||
| const {formatAttrForSearch} = require("./attribute_formatter.js"); | ||||
|  | ||||
| const ATTRIBUTE_TYPES = [ 'label', 'relation' ]; | ||||
|   | ||||
| @@ -63,6 +63,7 @@ function checkAppNotInitialized(req, res, next) { | ||||
| function checkToken(req, res, next) { | ||||
|     const token = req.headers.authorization; | ||||
|  | ||||
|     // TODO: put all tokens into becca memory to avoid these requests | ||||
|     if (sql.getValue("SELECT COUNT(*) FROM api_tokens WHERE isDeleted = 0 AND token = ?", [token]) === 0) { | ||||
|         reject(req, res, "Token not found"); | ||||
|     } | ||||
|   | ||||
							
								
								
									
										23
									
								
								src/services/becca/entities/api_token.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/services/becca/entities/api_token.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | ||||
| "use strict"; | ||||
|  | ||||
| const dateUtils = require('../../date_utils.js'); | ||||
| const AbstractEntity = require("./abstract_entity.js"); | ||||
|  | ||||
| /** | ||||
|  * ApiToken is an entity representing token used to authenticate against Trilium API from client applications. Currently used only by Trilium Sender. | ||||
|  */ | ||||
| class ApiToken extends AbstractEntity { | ||||
|     static get entityName() { return "api_tokens"; } | ||||
|     static get primaryKeyName() { return "apiTokenId"; } | ||||
|     static get hashedProperties() { return ["apiTokenId", "token", "utcDateCreated"]; } | ||||
|  | ||||
|     constructor(row) { | ||||
|         super(); | ||||
|  | ||||
|         this.apiTokenId = row.apiTokenId; | ||||
|         this.token = row.token; | ||||
|         this.utcDateCreated = row.utcDateCreated || dateUtils.utcNowDateTime(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| module.exports = ApiToken; | ||||
| @@ -33,7 +33,7 @@ class Attribute extends AbstractEntity { | ||||
|  | ||||
|         if (!(this.noteId in this.becca.notes)) { | ||||
|             // entities can come out of order in sync, create skeleton which will be filled later | ||||
|             this.becca.notes[this.noteId] = new Note(this.becca, {noteId: this.noteId}); | ||||
|             this.becca.notes[this.noteId] = new Note({noteId: this.noteId}); | ||||
|         } | ||||
|  | ||||
|         this.becca.notes[this.noteId].ownedAttributes.push(this); | ||||
|   | ||||
| @@ -47,7 +47,7 @@ class Branch extends AbstractEntity { | ||||
|     get childNote() { | ||||
|         if (!(this.noteId in this.becca.notes)) { | ||||
|             // entities can come out of order in sync, create skeleton which will be filled later | ||||
|             this.becca.notes[this.noteId] = new Note(this.becca, {noteId: this.noteId}); | ||||
|             this.becca.notes[this.noteId] = new Note({noteId: this.noteId}); | ||||
|         } | ||||
|  | ||||
|         return this.becca.notes[this.noteId]; | ||||
| @@ -61,7 +61,7 @@ class Branch extends AbstractEntity { | ||||
|     get parentNote() { | ||||
|         if (!(this.parentNoteId in this.becca.notes)) { | ||||
|             // entities can come out of order in sync, create skeleton which will be filled later | ||||
|             this.becca.notes[this.parentNoteId] = new Note(this.becca, {noteId: this.parentNoteId}); | ||||
|             this.becca.notes[this.parentNoteId] = new Note({noteId: this.parentNoteId}); | ||||
|         } | ||||
|  | ||||
|         return this.becca.notes[this.parentNoteId]; | ||||
|   | ||||
| @@ -5,7 +5,7 @@ const eventChangesService = require('./entity_changes.js'); | ||||
| const treeService = require('./tree'); | ||||
| const noteService = require('./notes'); | ||||
| const repository = require('./repository'); | ||||
| const Branch = require('../entities/branch'); | ||||
| const Branch = require('../services/becca/entities/branch'); | ||||
| const TaskContext = require("./task_context.js"); | ||||
| const utils = require('./utils'); | ||||
| const becca = require("./becca/becca"); | ||||
|   | ||||
| @@ -9,7 +9,7 @@ const repository = require('./repository'); | ||||
| const cls = require('./cls'); | ||||
| const entityChangesService = require('./entity_changes.js'); | ||||
| const optionsService = require('./options'); | ||||
| const Branch = require('../entities/branch'); | ||||
| const Branch = require('../services/becca/entities/branch'); | ||||
| const dateUtils = require('./date_utils'); | ||||
| const attributeService = require('./attributes'); | ||||
| const noteRevisionService = require('./note_revisions'); | ||||
|   | ||||
| @@ -2,9 +2,8 @@ const eventService = require('./events'); | ||||
| const scriptService = require('./script'); | ||||
| const treeService = require('./tree'); | ||||
| const noteService = require('./notes'); | ||||
| const repository = require('./repository'); | ||||
| const becca = require('./becca/becca.js'); | ||||
| const Attribute = require('../entities/attribute'); | ||||
| const Attribute = require('./becca/entities/attribute'); | ||||
|  | ||||
| function runAttachedRelations(note, relationName, originEntity) { | ||||
|     // same script note can get here with multiple ways, but execute only once | ||||
|   | ||||
| @@ -1,12 +1,11 @@ | ||||
| "use strict"; | ||||
|  | ||||
| const Attribute = require('../../entities/attribute'); | ||||
| const Attribute = require('../../services/becca/entities/attribute'); | ||||
| const utils = require('../../services/utils'); | ||||
| const log = require('../../services/log'); | ||||
| const repository = require('../../services/repository'); | ||||
| const noteService = require('../../services/notes'); | ||||
| const attributeService = require('../../services/attributes'); | ||||
| const Branch = require('../../entities/branch'); | ||||
| const Branch = require('../../services/becca/entities/branch'); | ||||
| const path = require('path'); | ||||
| const commonmark = require('commonmark'); | ||||
| const protectedSessionService = require('../protected_session'); | ||||
|   | ||||
| @@ -3,7 +3,7 @@ | ||||
| const sql = require('./sql'); | ||||
| const log = require('./log'); | ||||
| const repository = require('./repository'); | ||||
| const Branch = require('../entities/branch'); | ||||
| const Branch = require('../services/becca/entities/branch'); | ||||
| const entityChangesService = require('./entity_changes.js'); | ||||
| const protectedSessionService = require('./protected_session'); | ||||
| const becca = require('./becca/becca.js'); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user