mirror of
https://github.com/laurent22/joplin.git
synced 2025-02-01 19:15:01 +02:00
Fixed local sync issue
This commit is contained in:
parent
9acf41567b
commit
c18e1ac417
@ -137,7 +137,7 @@ commands.push({
|
|||||||
if (!currentFolder) {
|
if (!currentFolder) {
|
||||||
promise = Folder.loadByField('title', title);
|
promise = Folder.loadByField('title', title);
|
||||||
} else {
|
} else {
|
||||||
promise = Folder.loadNoteByField(currentFolder.id, 'title', title);
|
promise = Note.loadFolderNoteByField(currentFolder.id, 'title', title);
|
||||||
}
|
}
|
||||||
|
|
||||||
promise.then((item) => {
|
promise.then((item) => {
|
||||||
@ -152,7 +152,7 @@ commands.push({
|
|||||||
type_: item.type_,
|
type_: item.type_,
|
||||||
};
|
};
|
||||||
newItem[propName] = propValue;
|
newItem[propName] = propValue;
|
||||||
let ItemClass = BaseItem.itemClass();
|
let ItemClass = BaseItem.itemClass(newItem);
|
||||||
return ItemClass.save(newItem);
|
return ItemClass.save(newItem);
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
this.log(error);
|
this.log(error);
|
||||||
@ -173,7 +173,7 @@ commands.push({
|
|||||||
if (!currentFolder) {
|
if (!currentFolder) {
|
||||||
promise = Folder.loadByField('title', title);
|
promise = Folder.loadByField('title', title);
|
||||||
} else {
|
} else {
|
||||||
promise = Folder.loadNoteByField(currentFolder.id, 'title', title);
|
promise = Note.loadFolderNoteByField(currentFolder.id, 'title', title);
|
||||||
}
|
}
|
||||||
|
|
||||||
promise.then((item) => {
|
promise.then((item) => {
|
||||||
|
@ -21,28 +21,29 @@ class FileApiDriverLocal {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
statTimeToUnixTimestamp_(time) {
|
statTimeToTimestampMs_(time) {
|
||||||
let m = moment(time, 'YYYY-MM-DDTHH:mm:ss.SSSZ');
|
let m = moment(time, 'YYYY-MM-DDTHH:mm:ss.SSSZ');
|
||||||
if (!m.isValid()) {
|
if (!m.isValid()) {
|
||||||
throw new Error('Invalid date: ' + time);
|
throw new Error('Invalid date: ' + time);
|
||||||
}
|
}
|
||||||
return Math.round(m.toDate().getTime() / 1000);
|
return m.toDate().getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
metadataFromStats_(path, stats) {
|
metadataFromStats_(path, stats) {
|
||||||
return {
|
return {
|
||||||
path: path,
|
path: path,
|
||||||
created_time: this.statTimeToUnixTimestamp_(stats.birthtime),
|
created_time: this.statTimeToTimestampMs_(stats.birthtime),
|
||||||
updated_time: this.statTimeToUnixTimestamp_(stats.mtime),
|
updated_time: this.statTimeToTimestampMs_(stats.mtime),
|
||||||
created_time_orig: stats.birthtime,
|
created_time_orig: stats.birthtime,
|
||||||
updated_time_orig: stats.mtime,
|
updated_time_orig: stats.mtime,
|
||||||
isDir: stats.isDirectory(),
|
isDir: stats.isDirectory(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimestamp(path, timestamp) {
|
setTimestamp(path, timestampMs) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fs.utimes(path, timestamp, timestamp, (error) => {
|
let t = Math.floor(timestampMs / 1000);
|
||||||
|
fs.utimes(path, t, t, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
return;
|
return;
|
||||||
@ -151,15 +152,7 @@ class FileApiDriverLocal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
move(oldPath, newPath) {
|
move(oldPath, newPath) {
|
||||||
return new Promise((resolve, reject) => {
|
return fse.move(oldPath, newPath, { overwrite: true });
|
||||||
fse.move(oldPath, newPath, function(error) {
|
|
||||||
if (error) {
|
|
||||||
reject(error);
|
|
||||||
} else {
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
format() {
|
format() {
|
||||||
|
@ -34,10 +34,10 @@ class FileApiDriverMemory {
|
|||||||
return Promise.resolve(item ? Object.assign({}, item) : null);
|
return Promise.resolve(item ? Object.assign({}, item) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimestamp(path, timestamp) {
|
setTimestamp(path, timestampMs) {
|
||||||
let item = this.itemByPath(path);
|
let item = this.itemByPath(path);
|
||||||
if (!item) return Promise.reject(new Error('File not found: ' + path));
|
if (!item) return Promise.reject(new Error('File not found: ' + path));
|
||||||
item.updated_time = timestamp;
|
item.updated_time = timestampMs;
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,9 +41,9 @@ class FileApi {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimestamp(path, timestamp) {
|
setTimestamp(path, timestampMs) {
|
||||||
this.logger().debug('setTimestamp ' + this.fullPath_(path));
|
this.logger().debug('setTimestamp ' + this.fullPath_(path));
|
||||||
return this.driver_.setTimestamp(this.fullPath_(path), timestamp);
|
return this.driver_.setTimestamp(this.fullPath_(path), timestampMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
mkdir(path) {
|
mkdir(path) {
|
||||||
|
@ -77,10 +77,6 @@ class Folder extends BaseItem {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static loadNoteByField(folderId, field, value) {
|
|
||||||
return this.modelSelectOne('SELECT * FROM notes WHERE is_conflict = 0 AND `parent_id` = ? AND `' + field + '` = ?', [folderId, value]);
|
|
||||||
}
|
|
||||||
|
|
||||||
static async all(options = null) {
|
static async all(options = null) {
|
||||||
if (!options) options = {};
|
if (!options) options = {};
|
||||||
|
|
||||||
|
@ -47,6 +47,10 @@ class Note extends BaseItem {
|
|||||||
return this.db().escapeFields(this.previewFields()).join(',');
|
return this.db().escapeFields(this.previewFields()).join(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static loadFolderNoteByField(folderId, field, value) {
|
||||||
|
return this.modelSelectOne('SELECT * FROM notes WHERE is_conflict = 0 AND `parent_id` = ? AND `' + field + '` = ?', [folderId, value]);
|
||||||
|
}
|
||||||
|
|
||||||
static previews(parentId, options = null) {
|
static previews(parentId, options = null) {
|
||||||
if (!options) options = {};
|
if (!options) options = {};
|
||||||
if (!options.orderBy) options.orderBy = 'updated_time';
|
if (!options.orderBy) options.orderBy = 'updated_time';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user