You've already forked joplin
							
							
				mirror of
				https://github.com/laurent22/joplin.git
				synced 2025-10-31 00:07:48 +02:00 
			
		
		
		
	Plugins: Fixed import API
Ref: https://discourse.joplinapp.org/t/prompt-when-the-plugin-is-running-typeerror-this-module-oninit-is-not-a-function/20009/14
This commit is contained in:
		| @@ -5,27 +5,28 @@ import { ImportExportResult } from './types'; | ||||
| import Setting from '../../models/Setting'; | ||||
|  | ||||
| export default class InteropService_Importer_Base { | ||||
|  | ||||
| 	private metadata_: any = null; | ||||
| 	protected sourcePath_: string = ''; | ||||
| 	protected options_: any = {}; | ||||
|  | ||||
| 	setMetadata(md: any) { | ||||
| 	public setMetadata(md: any) { | ||||
| 		this.metadata_ = md; | ||||
| 	} | ||||
|  | ||||
| 	metadata() { | ||||
| 	public metadata() { | ||||
| 		return this.metadata_; | ||||
| 	} | ||||
|  | ||||
| 	async init(sourcePath: string, options: any) { | ||||
| 	public async init(sourcePath: string, options: any) { | ||||
| 		this.sourcePath_ = sourcePath; | ||||
| 		this.options_ = options; | ||||
| 	} | ||||
|  | ||||
| 	// @ts-ignore | ||||
| 	async exec(result: ImportExportResult): Promise<ImportExportResult> {} | ||||
| 	public async exec(result: ImportExportResult): Promise<ImportExportResult> {} | ||||
|  | ||||
| 	async temporaryDirectory_(createIt: boolean) { | ||||
| 	protected async temporaryDirectory_(createIt: boolean) { | ||||
| 		const md5 = require('md5'); | ||||
| 		const tempDir = `${Setting.value('tempDir')}/${md5(Math.random() + Date.now())}`; | ||||
| 		if (createIt) await require('fs-extra').mkdirp(tempDir); | ||||
|   | ||||
| @@ -5,15 +5,27 @@ export default class InteropService_Importer_Custom extends InteropService_Impor | ||||
|  | ||||
| 	private module_: Module = null; | ||||
|  | ||||
| 	constructor(handler: Module) { | ||||
| 	public constructor(handler: Module) { | ||||
| 		super(); | ||||
| 		this.module_ = handler; | ||||
| 	} | ||||
|  | ||||
| 	async exec(result: ImportExportResult): Promise<ImportExportResult> { | ||||
| 	public async exec(result: ImportExportResult): Promise<ImportExportResult> { | ||||
| 		// When passing the options to the plugin, we strip off any function | ||||
| 		// because they won't serialized over ipc. | ||||
|  | ||||
| 		const processedOptions: any = {}; | ||||
|  | ||||
| 		if (this.options_) { | ||||
| 			for (const [k, v] of Object.entries(this.options_)) { | ||||
| 				if (typeof v === 'function') continue; | ||||
| 				processedOptions[k] = v; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		return this.module_.onExec({ | ||||
| 			sourcePath: this.sourcePath_, | ||||
| 			options: this.options_, | ||||
| 			options: processedOptions, | ||||
| 			warnings: result.warnings, | ||||
| 		}); | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user