mirror of
https://github.com/laurent22/joplin.git
synced 2025-04-04 21:35:03 +02:00
Merge branch 'master' of github.com:laurent22/joplin
This commit is contained in:
commit
899219abd2
@ -18,9 +18,11 @@ If you want to add a new feature, consider asking about it before implementing i
|
||||
|
||||
Building the apps is relatively easy - please [see the build instructions](https://github.com/laurent22/joplin/blob/master/BUILD.md) for more details.
|
||||
|
||||
Pull requests that automatically change many files tend to be rejected (for example changes that automatically update the code styling, or to add new lines to many files, or to automatically convert images to a different format) so if you have such a pull request in mind, please discuss it first in the forum.
|
||||
|
||||
# Coding style
|
||||
|
||||
There are only two rules, but not following them means the pull request will not be accepted (it can be accepted once the issues are fixed):
|
||||
|
||||
- **Please use tabs, NOT spaces.**
|
||||
- **Please do not add or remove optional characters, such as spaces or colons.** Please setup your editor so that it only changes what you are working on and is not making automated changes elsewhere. The reason for this is that small white space changes make diff hard to read and can cause needless conflicts.
|
||||
- **Please do not add or remove optional characters, such as spaces or colons.** Please setup your editor so that it only changes what you are working on and is not making automated changes elsewhere. The reason for this is that small white space changes make diff hard to read and can cause needless conflicts.
|
||||
|
@ -310,4 +310,25 @@ describe('services_InteropService', function() {
|
||||
expect(note2_2.body.indexOf(note1_2.id) >= 0).toBe(true);
|
||||
}));
|
||||
|
||||
it('should export into json format', asyncTest(async () => {
|
||||
const service = new InteropService();
|
||||
let folder1 = await Folder.save({ title: 'folder1' });
|
||||
let note1 = await Note.save({ title: 'ma note', parent_id: folder1.id });
|
||||
note1 = await Note.load(note1.id);
|
||||
const filePath = exportDir();
|
||||
|
||||
await service.export({ path: filePath, format: 'json' });
|
||||
|
||||
// verify that the json files exist and can be parsed
|
||||
const items = [folder1, note1];
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const jsonFile = filePath + '/' + items[i].id + '.json';
|
||||
let json = await fs.readFile(jsonFile, 'utf-8');
|
||||
let obj = JSON.parse(json);
|
||||
expect(obj.id).toBe(items[i].id);
|
||||
expect(obj.type_).toBe(items[i].type_);
|
||||
expect(obj.title).toBe(items[i].title);
|
||||
expect(obj.body).toBe(items[i].body);
|
||||
}
|
||||
}));
|
||||
});
|
@ -75,9 +75,14 @@ class BaseItem extends BaseModel {
|
||||
return r.total;
|
||||
}
|
||||
|
||||
static systemPath(itemOrId) {
|
||||
if (typeof itemOrId === 'string') return itemOrId + '.md';
|
||||
return itemOrId.id + '.md';
|
||||
static systemPath(itemOrId, extension = null) {
|
||||
if (extension === null)
|
||||
extension = 'md';
|
||||
|
||||
if (typeof itemOrId === 'string')
|
||||
return itemOrId + '.' + extension;
|
||||
else
|
||||
return itemOrId.id + '.' + extension;
|
||||
}
|
||||
|
||||
static isSystemPath(path) {
|
||||
|
@ -58,6 +58,10 @@ class InteropService {
|
||||
format: 'raw',
|
||||
target: 'directory',
|
||||
description: _('Joplin Export Directory'),
|
||||
}, {
|
||||
format: 'json',
|
||||
target: 'directory',
|
||||
description: _('Json Export Directory'),
|
||||
}, {
|
||||
format: 'md',
|
||||
target: 'directory',
|
||||
|
@ -0,0 +1,30 @@
|
||||
const InteropService_Exporter_Base = require('lib/services/InteropService_Exporter_Base');
|
||||
const { basename, filename } = require('lib/path-utils.js');
|
||||
const { shim } = require('lib/shim');
|
||||
|
||||
class InteropService_Exporter_Json extends InteropService_Exporter_Base {
|
||||
|
||||
async init(destDir) {
|
||||
this.destDir_ = destDir;
|
||||
this.resourceDir_ = destDir ? destDir + '/resources' : null;
|
||||
|
||||
await shim.fsDriver().mkdir(this.destDir_);
|
||||
await shim.fsDriver().mkdir(this.resourceDir_);
|
||||
}
|
||||
|
||||
async processItem(ItemClass, item) {
|
||||
const fileName = ItemClass.systemPath(item, "json");
|
||||
const filePath = this.destDir_ + '/' + fileName;
|
||||
const serialized = JSON.stringify(item);
|
||||
await shim.fsDriver().writeFile(filePath, serialized, 'utf-8');
|
||||
}
|
||||
|
||||
async processResource(resource, filePath) {
|
||||
const destResourcePath = this.resourceDir_ + '/' + basename(filePath);
|
||||
await shim.fsDriver().copy(filePath, destResourcePath);
|
||||
}
|
||||
|
||||
async close() {}
|
||||
}
|
||||
|
||||
module.exports = InteropService_Exporter_Json;
|
@ -238,7 +238,7 @@ function shimInit() {
|
||||
host: url.hostname,
|
||||
port: url.port,
|
||||
method: method,
|
||||
path: url.path + (url.query ? '?' + url.query : ''),
|
||||
path: url.pathname + (url.query ? '?' + url.query : ''),
|
||||
headers: headers,
|
||||
};
|
||||
|
||||
@ -316,4 +316,4 @@ function shimInit() {
|
||||
|
||||
}
|
||||
|
||||
module.exports = { shimInit };
|
||||
module.exports = { shimInit };
|
||||
|
Loading…
x
Reference in New Issue
Block a user