1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-10-31 00:07:48 +02:00
Laurent Cozic
2021-09-04 15:07:38 +01:00
parent 973121addd
commit 736bbbd8ed
5 changed files with 54 additions and 22 deletions

View File

@@ -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);

View File

@@ -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,
});
}