diff --git a/CliClient/app/main.js b/CliClient/app/main.js index 5cb874857..587a7164e 100644 --- a/CliClient/app/main.js +++ b/CliClient/app/main.js @@ -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) => { diff --git a/lib/file-api-driver-local.js b/lib/file-api-driver-local.js index de50b2a6a..4c6c035ea 100644 --- a/lib/file-api-driver-local.js +++ b/lib/file-api-driver-local.js @@ -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() { diff --git a/lib/file-api-driver-memory.js b/lib/file-api-driver-memory.js index 44af1cc1e..6c167b410 100644 --- a/lib/file-api-driver-memory.js +++ b/lib/file-api-driver-memory.js @@ -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(); } diff --git a/lib/file-api.js b/lib/file-api.js index f540c1db8..b62446b8a 100644 --- a/lib/file-api.js +++ b/lib/file-api.js @@ -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) { diff --git a/lib/models/folder.js b/lib/models/folder.js index 46e23dde3..b49a5697d 100644 --- a/lib/models/folder.js +++ b/lib/models/folder.js @@ -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 = {}; diff --git a/lib/models/note.js b/lib/models/note.js index 124a792f3..b7844cdb1 100644 --- a/lib/models/note.js +++ b/lib/models/note.js @@ -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';