mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 21:11:30 +08:00 
			
		
		
		
	custom handler refactoring
This commit is contained in:
		
							parent
							
								
									b39f6ef7ad
								
							
						
					
					
						commit
						840a0b5f64
					
				| @ -12,18 +12,27 @@ function register(router) { | |||||||
| 
 | 
 | ||||||
|         for (const attr of attrs) { |         for (const attr of attrs) { | ||||||
|             const regex = new RegExp(attr.value); |             const regex = new RegExp(attr.value); | ||||||
|  |             let match; | ||||||
| 
 | 
 | ||||||
|             try { |             try { | ||||||
|                 const m = path.match(regex); |                 match = path.match(regex); | ||||||
|  |             } | ||||||
|  |             catch (e) { | ||||||
|  |                 log.error(`Testing path for label ${attr.attributeId}, regex=${attr.value} failed with error ` + e.stack); | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             if (!match) { | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
|                 if (m) { |  | ||||||
|             if (attr.name === 'customRequestHandler') { |             if (attr.name === 'customRequestHandler') { | ||||||
|                 const note = await attr.getNote(); |                 const note = await attr.getNote(); | ||||||
| 
 | 
 | ||||||
|                 log.info(`Handling custom request "${path}" with note ${note.noteId}`); |                 log.info(`Handling custom request "${path}" with note ${note.noteId}`); | ||||||
| 
 | 
 | ||||||
|                 await scriptService.executeNote(note, { |                 await scriptService.executeNote(note, { | ||||||
|                             pathParams: m.slice(1), |                     pathParams: match.slice(1), | ||||||
|                     req, |                     req, | ||||||
|                     res |                     res | ||||||
|                 }); |                 }); | ||||||
| @ -31,13 +40,11 @@ function register(router) { | |||||||
|             else if (attr.name === 'customResourceProvider') { |             else if (attr.name === 'customResourceProvider') { | ||||||
|                 await fileUploadService.downloadNoteFile(attr.noteId, res); |                 await fileUploadService.downloadNoteFile(attr.noteId, res); | ||||||
|             } |             } | ||||||
|  |             else { | ||||||
|  |                 throw new Error("Unrecognized attribute name " + attr.name); | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
|                     return; |             return; // only first handler is executed
 | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             catch (e) { |  | ||||||
|                 log.error(`Testing path for label ${attr.attributeId}, regex=${attr.value} failed with error ` + e.stack); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         const message = `No handler matched for custom ${path} request.`; |         const message = `No handler matched for custom ${path} request.`; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam