You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-15 23:00:36 +02:00
Applied prettier to code base
This commit is contained in:
@ -1,22 +1,21 @@
|
||||
const BaseItem = require('lib/models/BaseItem.js');
|
||||
const BaseModel = require('lib/BaseModel.js');
|
||||
const Resource = require('lib/models/Resource.js');
|
||||
const Folder = require('lib/models/Folder.js');
|
||||
const NoteTag = require('lib/models/NoteTag.js');
|
||||
const Note = require('lib/models/Note.js');
|
||||
const Tag = require('lib/models/Tag.js');
|
||||
const { basename, filename } = require('lib/path-utils.js');
|
||||
const fs = require('fs-extra');
|
||||
const ArrayUtils = require('lib/ArrayUtils');
|
||||
const { sprintf } = require('sprintf-js');
|
||||
const { shim } = require('lib/shim');
|
||||
const { _ } = require('lib/locale');
|
||||
const { fileExtension } = require('lib/path-utils');
|
||||
const { uuid } = require('lib/uuid.js');
|
||||
const { toTitleCase } = require('lib/string-utils');
|
||||
const BaseItem = require("lib/models/BaseItem.js");
|
||||
const BaseModel = require("lib/BaseModel.js");
|
||||
const Resource = require("lib/models/Resource.js");
|
||||
const Folder = require("lib/models/Folder.js");
|
||||
const NoteTag = require("lib/models/NoteTag.js");
|
||||
const Note = require("lib/models/Note.js");
|
||||
const Tag = require("lib/models/Tag.js");
|
||||
const { basename, filename } = require("lib/path-utils.js");
|
||||
const fs = require("fs-extra");
|
||||
const ArrayUtils = require("lib/ArrayUtils");
|
||||
const { sprintf } = require("sprintf-js");
|
||||
const { shim } = require("lib/shim");
|
||||
const { _ } = require("lib/locale");
|
||||
const { fileExtension } = require("lib/path-utils");
|
||||
const { uuid } = require("lib/uuid.js");
|
||||
const { toTitleCase } = require("lib/string-utils");
|
||||
|
||||
class InteropService {
|
||||
|
||||
constructor() {
|
||||
this.modules_ = null;
|
||||
}
|
||||
@ -26,57 +25,69 @@ class InteropService {
|
||||
|
||||
let importModules = [
|
||||
{
|
||||
format: 'jex',
|
||||
fileExtension: 'jex',
|
||||
sources: ['file'],
|
||||
description: _('Joplin Export File'),
|
||||
}, {
|
||||
format: 'md',
|
||||
fileExtension: 'md',
|
||||
sources: ['file', 'directory'],
|
||||
format: "jex",
|
||||
fileExtension: "jex",
|
||||
sources: ["file"],
|
||||
description: _("Joplin Export File"),
|
||||
},
|
||||
{
|
||||
format: "md",
|
||||
fileExtension: "md",
|
||||
sources: ["file", "directory"],
|
||||
isNoteArchive: false, // Tells whether the file can contain multiple notes (eg. Enex or Jex format)
|
||||
description: _('Markdown'),
|
||||
}, {
|
||||
format: 'raw',
|
||||
sources: ['directory'],
|
||||
description: _('Joplin Export Directory'),
|
||||
}, {
|
||||
format: 'enex',
|
||||
fileExtension: 'enex',
|
||||
sources: ['file'],
|
||||
description: _('Evernote Export File'),
|
||||
description: _("Markdown"),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
sources: ["directory"],
|
||||
description: _("Joplin Export Directory"),
|
||||
},
|
||||
{
|
||||
format: "enex",
|
||||
fileExtension: "enex",
|
||||
sources: ["file"],
|
||||
description: _("Evernote Export File"),
|
||||
},
|
||||
];
|
||||
|
||||
let exportModules = [
|
||||
{
|
||||
format: 'jex',
|
||||
fileExtension: 'jex',
|
||||
target: 'file',
|
||||
description: _('Joplin Export File'),
|
||||
}, {
|
||||
format: 'raw',
|
||||
target: 'directory',
|
||||
description: _('Joplin Export Directory'),
|
||||
format: "jex",
|
||||
fileExtension: "jex",
|
||||
target: "file",
|
||||
description: _("Joplin Export File"),
|
||||
},
|
||||
{
|
||||
format: "raw",
|
||||
target: "directory",
|
||||
description: _("Joplin Export Directory"),
|
||||
},
|
||||
];
|
||||
|
||||
importModules = importModules.map((a) => {
|
||||
const className = 'InteropService_Importer_' + toTitleCase(a.format);
|
||||
const output = Object.assign({}, {
|
||||
type: 'importer',
|
||||
path: 'lib/services/' + className,
|
||||
}, a);
|
||||
if (!('isNoteArchive' in output)) output.isNoteArchive = true;
|
||||
importModules = importModules.map(a => {
|
||||
const className = "InteropService_Importer_" + toTitleCase(a.format);
|
||||
const output = Object.assign(
|
||||
{},
|
||||
{
|
||||
type: "importer",
|
||||
path: "lib/services/" + className,
|
||||
},
|
||||
a
|
||||
);
|
||||
if (!("isNoteArchive" in output)) output.isNoteArchive = true;
|
||||
return output;
|
||||
});
|
||||
|
||||
exportModules = exportModules.map((a) => {
|
||||
const className = 'InteropService_Exporter_' + toTitleCase(a.format);
|
||||
return Object.assign({}, {
|
||||
type: 'exporter',
|
||||
path: 'lib/services/' + className,
|
||||
}, a);
|
||||
exportModules = exportModules.map(a => {
|
||||
const className = "InteropService_Exporter_" + toTitleCase(a.format);
|
||||
return Object.assign(
|
||||
{},
|
||||
{
|
||||
type: "exporter",
|
||||
path: "lib/services/" + className,
|
||||
},
|
||||
a
|
||||
);
|
||||
});
|
||||
|
||||
this.modules_ = importModules.concat(exportModules);
|
||||
@ -117,15 +128,19 @@ class InteropService {
|
||||
async import(options) {
|
||||
if (!await shim.fsDriver().exists(options.path)) throw new Error(_('Cannot find "%s".', options.path));
|
||||
|
||||
options = Object.assign({}, {
|
||||
format: 'auto',
|
||||
destinationFolderId: null,
|
||||
destinationFolder: null,
|
||||
}, options);
|
||||
options = Object.assign(
|
||||
{},
|
||||
{
|
||||
format: "auto",
|
||||
destinationFolderId: null,
|
||||
destinationFolder: null,
|
||||
},
|
||||
options
|
||||
);
|
||||
|
||||
if (options.format === 'auto') {
|
||||
const module = this.moduleByFileExtension_('importer', fileExtension(options.path));
|
||||
if (!module) throw new Error(_('Please specify import format for %s', options.path));
|
||||
if (options.format === "auto") {
|
||||
const module = this.moduleByFileExtension_("importer", fileExtension(options.path));
|
||||
if (!module) throw new Error(_("Please specify import format for %s", options.path));
|
||||
options.format = module.format;
|
||||
}
|
||||
|
||||
@ -135,9 +150,9 @@ class InteropService {
|
||||
options.destinationFolder = folder;
|
||||
}
|
||||
|
||||
let result = { warnings: [] }
|
||||
let result = { warnings: [] };
|
||||
|
||||
const importer = this.newModule_('importer', options.format);
|
||||
const importer = this.newModule_("importer", options.format);
|
||||
await importer.init(options.path, options);
|
||||
result = await importer.exec(result);
|
||||
|
||||
@ -148,16 +163,16 @@ class InteropService {
|
||||
const exportPath = options.path ? options.path : null;
|
||||
const sourceFolderIds = options.sourceFolderIds ? options.sourceFolderIds : [];
|
||||
const sourceNoteIds = options.sourceNoteIds ? options.sourceNoteIds : [];
|
||||
const exportFormat = options.format ? options.format : 'jex';
|
||||
const result = { warnings: [] }
|
||||
const exportFormat = options.format ? options.format : "jex";
|
||||
const result = { warnings: [] };
|
||||
const itemsToExport = [];
|
||||
|
||||
const queueExportItem = (itemType, itemOrId) => {
|
||||
itemsToExport.push({
|
||||
type: itemType,
|
||||
itemOrId: itemOrId
|
||||
itemOrId: itemOrId,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
let exportedNoteIds = [];
|
||||
let resourceIds = [];
|
||||
@ -204,25 +219,28 @@ class InteropService {
|
||||
await queueExportItem(BaseModel.TYPE_TAG, exportedTagIds[i]);
|
||||
}
|
||||
|
||||
const exporter = this.newModule_('exporter', exportFormat);
|
||||
const exporter = this.newModule_("exporter", exportFormat);
|
||||
await exporter.init(exportPath);
|
||||
|
||||
for (let i = 0; i < itemsToExport.length; i++) {
|
||||
const itemType = itemsToExport[i].type;
|
||||
const ItemClass = BaseItem.getClassByItemType(itemType);
|
||||
const itemOrId = itemsToExport[i].itemOrId;
|
||||
const item = typeof itemOrId === 'object' ? itemOrId : await ItemClass.load(itemOrId);
|
||||
const item = typeof itemOrId === "object" ? itemOrId : await ItemClass.load(itemOrId);
|
||||
|
||||
if (!item) {
|
||||
if (itemType === BaseModel.TYPE_RESOURCE) {
|
||||
result.warnings.push(sprintf('A resource that does not exist is referenced in a note. The resource was skipped. Resource ID: %s', itemOrId));
|
||||
result.warnings.push(sprintf("A resource that does not exist is referenced in a note. The resource was skipped. Resource ID: %s", itemOrId));
|
||||
} else {
|
||||
result.warnings.push(sprintf('Cannot find item with type "%s" and ID %s. Item was skipped.', ItemClass.tableName(), JSON.stringify(itemOrId)));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.encryption_applied || item.encryption_blob_encrypted) throw new Error(_('This item is currently encrypted: %s "%s". Please wait for all items to be decrypted and try again.', BaseModel.modelTypeToName(itemType), item.title ? item.title : item.id));
|
||||
if (item.encryption_applied || item.encryption_blob_encrypted)
|
||||
throw new Error(
|
||||
_('This item is currently encrypted: %s "%s". Please wait for all items to be decrypted and try again.', BaseModel.modelTypeToName(itemType), item.title ? item.title : item.id)
|
||||
);
|
||||
|
||||
try {
|
||||
if (itemType == BaseModel.TYPE_RESOURCE) {
|
||||
@ -240,7 +258,6 @@ class InteropService {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = InteropService;
|
||||
module.exports = InteropService;
|
||||
|
Reference in New Issue
Block a user