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 => { | messagingService.subscribeToMessages(async message => { | ||||||
|  |     if (message.type === 'import-error') { | ||||||
|  |         infoService.showError(message.message); | ||||||
|  |         $dialog.modal('hide'); | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     if (!message.importId || message.importId !== importId) { |     if (!message.importId || message.importId !== importId) { | ||||||
|         // incoming messages must correspond to this import instance
 |         // incoming messages must correspond to this import instance
 | ||||||
|         return; |         return; | ||||||
|  | |||||||
| @ -9,6 +9,7 @@ const messagingService = require('../../services/messaging'); | |||||||
| const cls = require('../../services/cls'); | const cls = require('../../services/cls'); | ||||||
| const path = require('path'); | const path = require('path'); | ||||||
| const noteCacheService = require('../../services/note_cache'); | const noteCacheService = require('../../services/note_cache'); | ||||||
|  | const log = require('../../services/log'); | ||||||
| 
 | 
 | ||||||
| class ImportContext { | class ImportContext { | ||||||
|     constructor(importId) { |     constructor(importId) { | ||||||
| @ -40,6 +41,14 @@ class ImportContext { | |||||||
|             noteId: noteId |             noteId: noteId | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     // must remaing static
 | ||||||
|  |     async reportError(message) { | ||||||
|  |         await messagingService.sendMessageToAllClients({ | ||||||
|  |             type: 'import-error', | ||||||
|  |             message: message | ||||||
|  |         }); | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async function importToBranch(req) { | async function importToBranch(req) { | ||||||
| @ -66,23 +75,28 @@ async function importToBranch(req) { | |||||||
| 
 | 
 | ||||||
|     const importContext = new ImportContext(importId); |     const importContext = new ImportContext(importId); | ||||||
| 
 | 
 | ||||||
|     if (extension === '.tar') { |     try { | ||||||
|         note = await tarImportService.importTar(importContext, file.buffer, parentNote); |         if (extension === '.tar') { | ||||||
|  |             note = await tarImportService.importTar(importContext, file.buffer, parentNote); | ||||||
|  |         } else if (extension === '.opml') { | ||||||
|  |             note = await opmlImportService.importOpml(importContext, file.buffer, parentNote); | ||||||
|  |         } else if (extension === '.md') { | ||||||
|  |             note = await singleImportService.importMarkdown(importContext, file, parentNote); | ||||||
|  |         } else if (extension === '.html' || extension === '.htm') { | ||||||
|  |             note = await singleImportService.importHtml(importContext, file, parentNote); | ||||||
|  |         } else if (extension === '.enex') { | ||||||
|  |             note = await enexImportService.importEnex(importContext, file, parentNote); | ||||||
|  |         } else { | ||||||
|  |             return [400, `Unrecognized extension ${extension}, must be .tar or .opml`]; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|     else if (extension === '.opml') { |     catch (e) { | ||||||
|         note = await opmlImportService.importOpml(importContext, file.buffer, parentNote); |         const message = "Import failed with following error: '" + e.message + "'. More details might be in the logs."; | ||||||
|     } |         importContext.reportError(message); | ||||||
|     else if (extension === '.md') { | 
 | ||||||
|         note = await singleImportService.importMarkdown(importContext, file, parentNote); |         log.error(message + e.stack); | ||||||
|     } | 
 | ||||||
|     else if (extension === '.html' || extension === '.htm') { |         return [500, message]; | ||||||
|         note = await singleImportService.importHtml(importContext, file, parentNote); |  | ||||||
|     } |  | ||||||
|     else if (extension === '.enex') { |  | ||||||
|         note = await enexImportService.importEnex(importContext, file, parentNote); |  | ||||||
|     } |  | ||||||
|     else { |  | ||||||
|         return [400, `Unrecognized extension ${extension}, must be .tar or .opml`]; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // import has deactivated note events so note cache is not updated
 |     // import has deactivated note events so note cache is not updated
 | ||||||
|  | |||||||
| @ -24,7 +24,7 @@ let lastSentCountTs = Date.now(); | |||||||
|  */ |  */ | ||||||
| async function importTar(importContext, fileBuffer, importRootNote) { | async function importTar(importContext, fileBuffer, importRootNote) { | ||||||
|     importNoteCount = 0; |     importNoteCount = 0; | ||||||
| 
 |     throw new Error("Hello"); | ||||||
|     // maps from original noteId (in tar file) to newly generated noteId
 |     // maps from original noteId (in tar file) to newly generated noteId
 | ||||||
|     const noteIdMap = {}; |     const noteIdMap = {}; | ||||||
|     const attributes = []; |     const attributes = []; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam