mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-11 18:24:43 +02:00
Fix sync issue, and added support for memory file api
This commit is contained in:
parent
4178d1f1de
commit
1e45668c19
@ -128,29 +128,6 @@ function importEnex(parentFolderId, filePath, importOptions = null) {
|
||||
if (!('onProgress' in importOptions)) importOptions.onProgress = function(state) {};
|
||||
if (!('onError' in importOptions)) importOptions.onError = function(error) {};
|
||||
|
||||
// Some notes were created with the exact same timestamp, for example when they were
|
||||
// batch imported. In order to make fuzzy matching easier, this function ensures
|
||||
// that each timestamp is unique.
|
||||
let existingTimestamps = [];
|
||||
function uniqueCreatedTimestamp(timestamp) {
|
||||
return timestamp;
|
||||
|
||||
if (existingTimestamps.indexOf(timestamp) < 0) {
|
||||
existingTimestamps.push(timestamp);
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
for (let i = 1; i <= 999; i++) {
|
||||
let t = timestamp + i;
|
||||
if (existingTimestamps.indexOf(t) < 0) {
|
||||
existingTimestamps.push(t);
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
let progressState = {
|
||||
loaded: 0,
|
||||
@ -207,6 +184,11 @@ function importEnex(parentFolderId, filePath, importOptions = null) {
|
||||
note.parent_id = parentFolderId;
|
||||
note.body = body;
|
||||
|
||||
// Notes in enex files always have a created timestamp but not always an
|
||||
// updated timestamp (it the note has never been modified). For sync
|
||||
// we require an updated_time property, so set it to create_time in that case
|
||||
if (!note.updated_time) note.updated_time = note.created_time;
|
||||
|
||||
return saveNoteToStorage(note, importOptions.fuzzyMatching);
|
||||
}).then((result) => {
|
||||
if (result.noteUpdated) {
|
||||
@ -250,7 +232,7 @@ function importEnex(parentFolderId, filePath, importOptions = null) {
|
||||
if (n == 'title') {
|
||||
note.title = text;
|
||||
} else if (n == 'created') {
|
||||
note.created_time = uniqueCreatedTimestamp(dateToTimestamp(text));
|
||||
note.created_time = dateToTimestamp(text);
|
||||
} else if (n == 'updated') {
|
||||
note.updated_time = dateToTimestamp(text);
|
||||
} else if (n == 'tag') {
|
||||
|
@ -5,6 +5,7 @@ require('babel-plugin-transform-runtime');
|
||||
|
||||
import { FileApi } from 'lib/file-api.js';
|
||||
import { FileApiDriverOneDrive } from 'lib/file-api-driver-onedrive.js';
|
||||
import { FileApiDriverMemory } from 'lib/file-api-driver-memory.js';
|
||||
import { Database } from 'lib/database.js';
|
||||
import { DatabaseDriverNode } from 'lib/database-driver-node.js';
|
||||
import { BaseModel } from 'lib/base-model.js';
|
||||
@ -311,7 +312,8 @@ commands.push({
|
||||
usage: 'sync',
|
||||
description: 'Synchronizes with remote storage.',
|
||||
action: function(args, end) {
|
||||
synchronizer('onedrive').then((s) => {
|
||||
//synchronizer('onedrive').then((s) => {
|
||||
synchronizer('memory').then((s) => {
|
||||
return s.start();
|
||||
}).catch((error) => {
|
||||
logger.error(error);
|
||||
@ -442,6 +444,10 @@ async function synchronizer(remoteBackend) {
|
||||
logger.info('App dir: ' + appDir);
|
||||
fileApi = new FileApi(appDir, driver);
|
||||
fileApi.setLogger(logger);
|
||||
} else if (remoteBackend == 'memory') {
|
||||
let driver = new FileApiDriverMemory();
|
||||
fileApi = new FileApi('joplin', driver);
|
||||
fileApi.setLogger(logger);
|
||||
} else {
|
||||
throw new Error('Unknown backend: ' + remoteBackend);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user