mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 04:51:31 +08:00 
			
		
		
		
	script bugfixes
This commit is contained in:
		
							parent
							
								
									5217339209
								
							
						
					
					
						commit
						72bd2507fe
					
				| @ -40,7 +40,7 @@ class Note extends Entity { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     beforeSaving() { |     beforeSaving() { | ||||||
|         this.content = JSON.stringify(this.jsonContent, null, 4); |         this.content = JSON.stringify(this.jsonContent, null, '\t'); | ||||||
| 
 | 
 | ||||||
|         if (this.isProtected) { |         if (this.isProtected) { | ||||||
|             protected_session.encryptNote(this.dataKey, this); |             protected_session.encryptNote(this.dataKey, this); | ||||||
|  | |||||||
| @ -70,7 +70,7 @@ class Repository { | |||||||
|         delete clone.jsonContent; |         delete clone.jsonContent; | ||||||
|         delete clone.repository; |         delete clone.repository; | ||||||
| 
 | 
 | ||||||
|         await sql.replace(entity.constructor.tableName, entity); |         await sql.replace(entity.constructor.tableName, clone); | ||||||
| 
 | 
 | ||||||
|         const primaryKey = entity[entity.constructor.primaryKeyName]; |         const primaryKey = entity[entity.constructor.primaryKeyName]; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -15,8 +15,6 @@ async function executeScript(noteId, dataKey, script, params) { | |||||||
|         ret = await (function() { return eval(`(${script})(${paramsStr})`); }.call(ctx)); |         ret = await (function() { return eval(`(${script})(${paramsStr})`); }.call(ctx)); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     log.info('Execution result: ' + ret); |  | ||||||
| 
 |  | ||||||
|     return ret; |     return ret; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -3,8 +3,6 @@ const protected_session = require('./protected_session'); | |||||||
| const notes = require('./notes'); | const notes = require('./notes'); | ||||||
| const attributes = require('./attributes'); | const attributes = require('./attributes'); | ||||||
| const date_notes = require('./date_notes'); | const date_notes = require('./date_notes'); | ||||||
| const sql = require('./sql'); |  | ||||||
| const sync_table = require('./sync_table'); |  | ||||||
| const Repository = require('./repository'); | const Repository = require('./repository'); | ||||||
| 
 | 
 | ||||||
| function ScriptContext(noteId, dataKey) { | function ScriptContext(noteId, dataKey) { | ||||||
| @ -12,10 +10,6 @@ function ScriptContext(noteId, dataKey) { | |||||||
|     this.dataKey = protected_session.getDataKey(dataKey); |     this.dataKey = protected_session.getDataKey(dataKey); | ||||||
|     this.repository = new Repository(dataKey); |     this.repository = new Repository(dataKey); | ||||||
| 
 | 
 | ||||||
|     function serializePayload(payload) { |  | ||||||
|         return JSON.stringify(payload, null, '\t'); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     this.getNoteById = async function(noteId) { |     this.getNoteById = async function(noteId) { | ||||||
|         return this.repository.getNote(noteId); |         return this.repository.getNote(noteId); | ||||||
|     }; |     }; | ||||||
| @ -25,15 +19,15 @@ function ScriptContext(noteId, dataKey) { | |||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     this.getNoteWithAttribute = async function (attrName, attrValue) { |     this.getNoteWithAttribute = async function (attrName, attrValue) { | ||||||
|         const notes = this.getNotesWithAttribute(attrName, attrValue); |         const notes = await this.getNotesWithAttribute(attrName, attrValue); | ||||||
| 
 | 
 | ||||||
|         return notes.length > 0 ? notes[0] : null; |         return notes.length > 0 ? notes[0] : null; | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     this.createNote = async function (parentNoteId, name, payload, extraOptions = {}) { |     this.createNote = async function (parentNoteId, name, jsonContent, extraOptions = {}) { | ||||||
|         const note = { |         const note = { | ||||||
|             title: name, |             title: name, | ||||||
|             content: extraOptions.json ? serializePayload(payload) : payload, |             content: extraOptions.json ? JSON.stringify(jsonContent, null, '\t') : jsonContent, | ||||||
|             target: 'into', |             target: 'into', | ||||||
|             isProtected: extraOptions.isProtected !== undefined ? extraOptions.isProtected : false, |             isProtected: extraOptions.isProtected !== undefined ? extraOptions.isProtected : false, | ||||||
|             type: extraOptions.type, |             type: extraOptions.type, | ||||||
| @ -50,7 +44,7 @@ function ScriptContext(noteId, dataKey) { | |||||||
|             note.mime = "text/html"; |             note.mime = "text/html"; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         const noteId = (await notes.createNewNote(parentNoteId, note)).noteId; |         const noteId = (await notes.createNewNote(parentNoteId, note, this.dataKey)).noteId; | ||||||
| 
 | 
 | ||||||
|         if (extraOptions.attributes) { |         if (extraOptions.attributes) { | ||||||
|             for (const attrName in extraOptions.attributes) { |             for (const attrName in extraOptions.attributes) { | ||||||
| @ -61,21 +55,7 @@ function ScriptContext(noteId, dataKey) { | |||||||
|         return noteId; |         return noteId; | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     this.updateNote = async function (note) { |     this.updateEntity = this.repository.updateEntity; | ||||||
|         if (note.isJson()) { |  | ||||||
|             note.content = serializePayload(note.jsonContent); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         delete note.jsonContent; |  | ||||||
| 
 |  | ||||||
|         if (note.isProtected) { |  | ||||||
|             protected_session.encryptNote(this.dataKey, note); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         await sql.replace("notes", note); |  | ||||||
| 
 |  | ||||||
|         await sync_table.addNoteSync(note.noteId); |  | ||||||
|     }; |  | ||||||
| 
 | 
 | ||||||
|     this.log = function(message) { |     this.log = function(message) { | ||||||
|         log.info(`Script ${this.scriptNoteId}: ${message}`); |         log.info(`Script ${this.scriptNoteId}: ${message}`); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 azivner
						azivner