diff --git a/ElectronClient/app/InteropServiceHelper.js b/ElectronClient/app/InteropServiceHelper.js index 341a19c16..de2f367c4 100644 --- a/ElectronClient/app/InteropServiceHelper.js +++ b/ElectronClient/app/InteropServiceHelper.js @@ -11,7 +11,7 @@ class InteropServiceHelper { if (module.target === 'file') { path = bridge().showSaveDialog({ - filters: [{ name: module.description, extensions: [module.fileExtension]}] + filters: [{ name: module.description, extensions: module.fileExtension}] }); } else { path = bridge().showOpenDialog({ diff --git a/ElectronClient/app/app.js b/ElectronClient/app/app.js index 239571d5d..46264d96a 100644 --- a/ElectronClient/app/app.js +++ b/ElectronClient/app/app.js @@ -285,7 +285,7 @@ class Application extends BaseApplication { if (moduleSource === 'file') { path = bridge().showOpenDialog({ - filters: [{ name: module.description, extensions: [module.fileExtension]}] + filters: [{ name: module.description, extensions: module.fileExtensions}] }); } else { path = bridge().showOpenDialog({ diff --git a/ReactNativeClient/lib/services/InteropService.js b/ReactNativeClient/lib/services/InteropService.js index 28802fcfb..7e47a05ca 100644 --- a/ReactNativeClient/lib/services/InteropService.js +++ b/ReactNativeClient/lib/services/InteropService.js @@ -27,12 +27,12 @@ class InteropService { let importModules = [ { format: 'jex', - fileExtension: 'jex', + fileExtensions: ['jex'], sources: ['file'], description: _('Joplin Export File'), }, { format: 'md', - fileExtension: 'md', + fileExtensions: ['md', 'markdown'], sources: ['file', 'directory'], isNoteArchive: false, // Tells whether the file can contain multiple notes (eg. Enex or Jex format) description: _('Markdown'), @@ -42,7 +42,7 @@ class InteropService { description: _('Joplin Export Directory'), }, { format: 'enex', - fileExtension: 'enex', + fileExtensions: ['enex'], sources: ['file'], description: _('Evernote Export File'), }, @@ -51,7 +51,7 @@ class InteropService { let exportModules = [ { format: 'jex', - fileExtension: 'jex', + fileExtensions: ['jex'], target: 'file', description: _('Joplin Export File'), }, { @@ -108,7 +108,9 @@ class InteropService { const module = this.moduleByFormat_(type, format); if (!module) throw new Error(_('Cannot load "%s" module for format "%s"', type, format)); const ModuleClass = require(module.path); - return new ModuleClass(); + const output = new ModuleClass(); + output.setMetadata(module); + return output; } moduleByFileExtension_(type, ext) { @@ -119,7 +121,7 @@ class InteropService { for (let i = 0; i < modules.length; i++) { const m = modules[i]; if (type !== m.type) continue; - if (m.fileExtension === ext) return m; + if (m.fileExtensions.indexOf(ext) >= 0) return m; } return null; diff --git a/ReactNativeClient/lib/services/InteropService_Exporter_Base.js b/ReactNativeClient/lib/services/InteropService_Exporter_Base.js index 6d0ba2bb0..14b1e147b 100644 --- a/ReactNativeClient/lib/services/InteropService_Exporter_Base.js +++ b/ReactNativeClient/lib/services/InteropService_Exporter_Base.js @@ -5,6 +5,14 @@ class InteropService_Exporter_Base { async processResource(resource, filePath) {} async close() {} + setMetadata(md) { + this.metadata_ = md; + } + + metadata() { + return this.metadata_; + } + async temporaryDirectory_(createIt) { const md5 = require('md5'); const tempDir = require('os').tmpdir() + '/' + md5(Math.random() + Date.now()); diff --git a/ReactNativeClient/lib/services/InteropService_Importer_Base.js b/ReactNativeClient/lib/services/InteropService_Importer_Base.js index 6076cd6be..12c603d01 100644 --- a/ReactNativeClient/lib/services/InteropService_Importer_Base.js +++ b/ReactNativeClient/lib/services/InteropService_Importer_Base.js @@ -1,5 +1,13 @@ class InteropService_Importer_Base { + setMetadata(md) { + this.metadata_ = md; + } + + metadata() { + return this.metadata_; + } + async init(sourcePath, options) { this.sourcePath_ = sourcePath; this.options_ = options; diff --git a/ReactNativeClient/lib/services/InteropService_Importer_Md.js b/ReactNativeClient/lib/services/InteropService_Importer_Md.js index 86764b049..49ab0a342 100644 --- a/ReactNativeClient/lib/services/InteropService_Importer_Md.js +++ b/ReactNativeClient/lib/services/InteropService_Importer_Md.js @@ -21,12 +21,14 @@ class InteropService_Importer_Md extends InteropService_Importer_Base { async exec(result) { let parentFolderId = null; + const supportedFileExtension = this.metadata().fileExtensions; + const filePaths = []; if (await shim.fsDriver().isDirectory(this.sourcePath_)) { const stats = await shim.fsDriver().readDirStats(this.sourcePath_); for (let i = 0; i < stats.length; i++) { const stat = stats[i]; - if (fileExtension(stat.path).toLowerCase() === 'md') { + if (supportedFileExtension.indexOf(fileExtension(stat.path).toLowerCase()) >= 0) { filePaths.push(this.sourcePath_ + '/' + stat.path); } }