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) {
|
||||
promise = Folder.loadByField('title', title);
|
||||
} else {
|
||||
promise = Folder.loadNoteByField(currentFolder.id, 'title', title);
|
||||
promise = Note.loadFolderNoteByField(currentFolder.id, 'title', title);
|
||||
}
|
||||
|
||||
promise.then((item) => {
|
||||
@ -152,7 +152,7 @@ commands.push({
|
||||
type_: item.type_,
|
||||
};
|
||||
newItem[propName] = propValue;
|
||||
let ItemClass = BaseItem.itemClass();
|
||||
let ItemClass = BaseItem.itemClass(newItem);
|
||||
return ItemClass.save(newItem);
|
||||
}).catch((error) => {
|
||||
this.log(error);
|
||||
@ -173,7 +173,7 @@ commands.push({
|
||||
if (!currentFolder) {
|
||||
promise = Folder.loadByField('title', title);
|
||||
} else {
|
||||
promise = Folder.loadNoteByField(currentFolder.id, 'title', title);
|
||||
promise = Note.loadFolderNoteByField(currentFolder.id, 'title', title);
|
||||
}
|
||||
|
||||
promise.then((item) => {
|
||||
|
@ -21,28 +21,29 @@ class FileApiDriverLocal {
|
||||
});
|
||||
}
|
||||
|
||||
statTimeToUnixTimestamp_(time) {
|
||||
statTimeToTimestampMs_(time) {
|
||||
let m = moment(time, 'YYYY-MM-DDTHH:mm:ss.SSSZ');
|
||||
if (!m.isValid()) {
|
||||
throw new Error('Invalid date: ' + time);
|
||||
}
|
||||
return Math.round(m.toDate().getTime() / 1000);
|
||||
return m.toDate().getTime();
|
||||
}
|
||||
|
||||
metadataFromStats_(path, stats) {
|
||||
return {
|
||||
path: path,
|
||||
created_time: this.statTimeToUnixTimestamp_(stats.birthtime),
|
||||
updated_time: this.statTimeToUnixTimestamp_(stats.mtime),
|
||||
created_time: this.statTimeToTimestampMs_(stats.birthtime),
|
||||
updated_time: this.statTimeToTimestampMs_(stats.mtime),
|
||||
created_time_orig: stats.birthtime,
|
||||
updated_time_orig: stats.mtime,
|
||||
isDir: stats.isDirectory(),
|
||||
};
|
||||
}
|
||||
|
||||
setTimestamp(path, timestamp) {
|
||||
setTimestamp(path, timestampMs) {
|
||||
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) {
|
||||
reject(error);
|
||||
return;
|
||||
@ -151,15 +152,7 @@ class FileApiDriverLocal {
|
||||
}
|
||||
|
||||
move(oldPath, newPath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fse.move(oldPath, newPath, function(error) {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
return fse.move(oldPath, newPath, { overwrite: true });
|
||||
}
|
||||
|
||||
format() {
|
||||
|
@ -34,10 +34,10 @@ class FileApiDriverMemory {
|
||||
return Promise.resolve(item ? Object.assign({}, item) : null);
|
||||
}
|
||||
|
||||
setTimestamp(path, timestamp) {
|
||||
setTimestamp(path, timestampMs) {
|
||||
let item = this.itemByPath(path);
|
||||
if (!item) return Promise.reject(new Error('File not found: ' + path));
|
||||
item.updated_time = timestamp;
|
||||
item.updated_time = timestampMs;
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
|
@ -41,9 +41,9 @@ class FileApi {
|
||||
});
|
||||
}
|
||||
|
||||
setTimestamp(path, timestamp) {
|
||||
setTimestamp(path, timestampMs) {
|
||||
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) {
|
||||
|
@ -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) {
|
||||
if (!options) options = {};
|
||||
|
||||
|
@ -47,6 +47,10 @@ class Note extends BaseItem {
|
||||
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) {
|
||||
if (!options) options = {};
|
||||
if (!options.orderBy) options.orderBy = 'updated_time';
|
||||
|
Loading…
x
Reference in New Issue
Block a user