mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 04:51:31 +08:00 
			
		
		
		
	added #runOnInstance and #runAtHour
This commit is contained in:
		
							parent
							
								
									052f584bf4
								
							
						
					
					
						commit
						9c679aef20
					
				
							
								
								
									
										14
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										14
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @ -65,7 +65,7 @@ | ||||
|       }, | ||||
|       "devDependencies": { | ||||
|         "cross-env": "7.0.3", | ||||
|         "electron": "13.0.0-beta.11", | ||||
|         "electron": "13.0.0-beta.12", | ||||
|         "electron-builder": "22.10.5", | ||||
|         "electron-packager": "15.2.0", | ||||
|         "electron-rebuild": "2.3.5", | ||||
| @ -3312,9 +3312,9 @@ | ||||
|       } | ||||
|     }, | ||||
|     "node_modules/electron": { | ||||
|       "version": "13.0.0-beta.11", | ||||
|       "resolved": "https://registry.npmjs.org/electron/-/electron-13.0.0-beta.11.tgz", | ||||
|       "integrity": "sha512-hSKu4n3BIznAgnmDmURFJ7Xe7BO5B2DKw8g+J8LLE/PLverIH1qBwVzHL/oWlMLxjPCCKd8WARNX7L8X/bOJHA==", | ||||
|       "version": "13.0.0-beta.12", | ||||
|       "resolved": "https://registry.npmjs.org/electron/-/electron-13.0.0-beta.12.tgz", | ||||
|       "integrity": "sha512-Ly+60Sgb5PITxRWA15XrW46GXSajOO8w+BHft07TZKKuicyGN+vqZAhR8HvvOtm9nGmVrrWsi430R9t4zQL8kw==", | ||||
|       "dev": true, | ||||
|       "hasInstallScript": true, | ||||
|       "dependencies": { | ||||
| @ -12984,9 +12984,9 @@ | ||||
|       } | ||||
|     }, | ||||
|     "electron": { | ||||
|       "version": "13.0.0-beta.11", | ||||
|       "resolved": "https://registry.npmjs.org/electron/-/electron-13.0.0-beta.11.tgz", | ||||
|       "integrity": "sha512-hSKu4n3BIznAgnmDmURFJ7Xe7BO5B2DKw8g+J8LLE/PLverIH1qBwVzHL/oWlMLxjPCCKd8WARNX7L8X/bOJHA==", | ||||
|       "version": "13.0.0-beta.12", | ||||
|       "resolved": "https://registry.npmjs.org/electron/-/electron-13.0.0-beta.12.tgz", | ||||
|       "integrity": "sha512-Ly+60Sgb5PITxRWA15XrW46GXSajOO8w+BHft07TZKKuicyGN+vqZAhR8HvvOtm9nGmVrrWsi430R9t4zQL8kw==", | ||||
|       "dev": true, | ||||
|       "requires": { | ||||
|         "@electron/get": "^1.0.1", | ||||
|  | ||||
| @ -78,7 +78,7 @@ | ||||
|   }, | ||||
|   "devDependencies": { | ||||
|     "cross-env": "7.0.3", | ||||
|     "electron": "13.0.0-beta.11", | ||||
|     "electron": "13.0.0-beta.12", | ||||
|     "electron-builder": "22.10.5", | ||||
|     "electron-packager": "15.2.0", | ||||
|     "electron-rebuild": "2.3.5", | ||||
|  | ||||
| @ -303,6 +303,14 @@ class Note extends Entity { | ||||
|         return this.getAttributes(LABEL, name); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @param {string} [name] - label name to filter | ||||
|      * @returns {string[]} all note's label values, including inherited ones | ||||
|      */ | ||||
|     getLabelValues(name) { | ||||
|         return this.getLabels(name).map(l => l.value); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @param {string} [name] - label name to filter | ||||
|      * @returns {Attribute[]} all note's labels (attributes with type label), excluding inherited ones | ||||
| @ -311,6 +319,14 @@ class Note extends Entity { | ||||
|         return this.getOwnedAttributes(LABEL, name); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @param {string} [name] - label name to filter | ||||
|      * @returns {string[]} all note's label values, excluding inherited ones | ||||
|      */ | ||||
|     getOwnedLabelValues(name) { | ||||
|         return this.getOwnedAttributes(LABEL, name).map(l => l.value); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @param {string} [name] - relation name to filter | ||||
|      * @returns {Attribute[]} all note's relations (attributes with type relation), including inherited ones | ||||
|  | ||||
| @ -182,9 +182,11 @@ const ATTR_HELP = { | ||||
|                 <ul> | ||||
|                     <li>frontendStartup - when Trilium frontend starts up (or is refreshed).</li> | ||||
|                     <li>backendStartup - when Trilium backend starts up</li> | ||||
|                     <li>hourly - run once an hour</li> | ||||
|                     <li>hourly - run once an hour. You can use additional label <code>runAtHours</code> to specify at which hour.</li> | ||||
|                     <li>daily - run once a day</li> | ||||
|                 </ul>`, | ||||
|         "runOnInstance": "Define which trilium instance should run this on. Default to all instances.", | ||||
|         "runAtHour": "On which hour should this run. Should be used together with <code>#run=hourly</code>", | ||||
|         "disableInclusion": "scripts with this label won't be included into parent script execution.", | ||||
|         "sorted": "keeps child notes sorted by title alphabetically", | ||||
|         "hidePromotedAttributes": "Hide promoted attributes on this note", | ||||
|  | ||||
| @ -25,6 +25,8 @@ const BUILTIN_ATTRIBUTES = [ | ||||
|     { type: 'label', name: 'iconClass' }, | ||||
|     { type: 'label', name: 'keyboardShortcut' }, | ||||
|     { type: 'label', name: 'run', isDangerous: true }, | ||||
|     { type: 'label', name: 'runOnInstance', isDangerous: false }, | ||||
|     { type: 'label', name: 'runAtHours', isDangerous: false }, | ||||
|     { type: 'label', name: 'customRequestHandler', isDangerous: true }, | ||||
|     { type: 'label', name: 'customResourceProvider', isDangerous: true }, | ||||
|     { type: 'label', name: 'widget', isDangerous: true }, | ||||
|  | ||||
| @ -2,6 +2,19 @@ const scriptService = require('./script'); | ||||
| const repository = require('./repository'); | ||||
| const cls = require('./cls'); | ||||
| const sqlInit = require('./sql_init'); | ||||
| const config = require('./config'); | ||||
| const log = require('./log'); | ||||
| 
 | ||||
| function getRunAtHours(note) { | ||||
|     try { | ||||
|         return note.getLabelValues('runAtHour').map(hour => parseInt(hour)); | ||||
|     } | ||||
|     catch (e) { | ||||
|         log.error(`Could not parse runAtHour for note ${note.noteId}: ${e.message}`); | ||||
| 
 | ||||
|         return []; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| function runNotesWithLabel(runAttrValue) { | ||||
|     const notes = repository.getEntities(` | ||||
| @ -16,10 +29,20 @@ function runNotesWithLabel(runAttrValue) { | ||||
|           notes.type = 'code' | ||||
|           AND notes.isDeleted = 0`, [runAttrValue]);
 | ||||
| 
 | ||||
|     const instanceName = config.General ? config.General.instanceName : null; | ||||
|     const currentHours = new Date().getHours(); | ||||
| 
 | ||||
|     for (const note of notes) { | ||||
|         const runOnInstances = note.getLabelValues('runOnInstance'); | ||||
|         const runAtHours = getRunAtHours(note); | ||||
| 
 | ||||
|         if ((runOnInstances.length === 0 || runOnInstances.includes(instanceName)) | ||||
|             && (runAtHours.length === 0 || runAtHours.includes(currentHours)) | ||||
|         ) { | ||||
|             scriptService.executeNoteNoException(note, {originEntity: note}); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| sqlInit.dbReady.then(() => { | ||||
|     if (!process.env.TRILIUM_SAFE_MODE) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam