mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 11:39:01 +01:00 
			
		
		
		
	import error handling
This commit is contained in:
		
							parent
							
								
									e4c78f3887
								
							
						
					
					
						commit
						a097cefba7
					
				| @ -63,6 +63,12 @@ function importIntoNote(importNoteId) { | ||||
| } | ||||
| 
 | ||||
| messagingService.subscribeToMessages(async message => { | ||||
|     if (message.type === 'import-error') { | ||||
|         infoService.showError(message.message); | ||||
|         $dialog.modal('hide'); | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     if (!message.importId || message.importId !== importId) { | ||||
|         // incoming messages must correspond to this import instance
 | ||||
|         return; | ||||
|  | ||||
| @ -9,6 +9,7 @@ const messagingService = require('../../services/messaging'); | ||||
| const cls = require('../../services/cls'); | ||||
| const path = require('path'); | ||||
| const noteCacheService = require('../../services/note_cache'); | ||||
| const log = require('../../services/log'); | ||||
| 
 | ||||
| class ImportContext { | ||||
|     constructor(importId) { | ||||
| @ -40,6 +41,14 @@ class ImportContext { | ||||
|             noteId: noteId | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     // must remaing static
 | ||||
|     async reportError(message) { | ||||
|         await messagingService.sendMessageToAllClients({ | ||||
|             type: 'import-error', | ||||
|             message: message | ||||
|         }); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| async function importToBranch(req) { | ||||
| @ -66,24 +75,29 @@ async function importToBranch(req) { | ||||
| 
 | ||||
|     const importContext = new ImportContext(importId); | ||||
| 
 | ||||
|     try { | ||||
|         if (extension === '.tar') { | ||||
|             note = await tarImportService.importTar(importContext, file.buffer, parentNote); | ||||
|     } | ||||
|     else if (extension === '.opml') { | ||||
|         } else if (extension === '.opml') { | ||||
|             note = await opmlImportService.importOpml(importContext, file.buffer, parentNote); | ||||
|     } | ||||
|     else if (extension === '.md') { | ||||
|         } else if (extension === '.md') { | ||||
|             note = await singleImportService.importMarkdown(importContext, file, parentNote); | ||||
|     } | ||||
|     else if (extension === '.html' || extension === '.htm') { | ||||
|         } else if (extension === '.html' || extension === '.htm') { | ||||
|             note = await singleImportService.importHtml(importContext, file, parentNote); | ||||
|     } | ||||
|     else if (extension === '.enex') { | ||||
|         } else if (extension === '.enex') { | ||||
|             note = await enexImportService.importEnex(importContext, file, parentNote); | ||||
|     } | ||||
|     else { | ||||
|         } else { | ||||
|             return [400, `Unrecognized extension ${extension}, must be .tar or .opml`]; | ||||
|         } | ||||
|     } | ||||
|     catch (e) { | ||||
|         const message = "Import failed with following error: '" + e.message + "'. More details might be in the logs."; | ||||
|         importContext.reportError(message); | ||||
| 
 | ||||
|         log.error(message + e.stack); | ||||
| 
 | ||||
|         return [500, message]; | ||||
|     } | ||||
| 
 | ||||
|     // import has deactivated note events so note cache is not updated
 | ||||
|     // instead we force it to reload (can be async)
 | ||||
|  | ||||
| @ -24,7 +24,7 @@ let lastSentCountTs = Date.now(); | ||||
|  */ | ||||
| async function importTar(importContext, fileBuffer, importRootNote) { | ||||
|     importNoteCount = 0; | ||||
| 
 | ||||
|     throw new Error("Hello"); | ||||
|     // maps from original noteId (in tar file) to newly generated noteId
 | ||||
|     const noteIdMap = {}; | ||||
|     const attributes = []; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam