mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Desktop: Fixes #1676: Preserve user timestamps when adding note via API
This commit is contained in:
parent
0ecf2d6d9a
commit
6ee2595dce
@ -156,6 +156,25 @@ describe('services_rest_Api', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
it('should preserve user timestamps when creating notes', async (done) => {
|
||||
let response = null;
|
||||
const f = await Folder.save({ title: "mon carnet" });
|
||||
|
||||
const updatedTime = Date.now() - 1000;
|
||||
const createdTime = Date.now() - 10000;
|
||||
|
||||
response = await api.route('POST', 'notes', null, JSON.stringify({
|
||||
parent_id: f.id,
|
||||
user_updated_time: updatedTime,
|
||||
user_created_time: createdTime,
|
||||
}));
|
||||
|
||||
expect(response.user_updated_time).toBe(updatedTime);
|
||||
expect(response.user_created_time).toBe(createdTime);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('should create notes with supplied ID', async (done) => {
|
||||
let response = null;
|
||||
const f = await Folder.save({ title: "mon carnet" });
|
||||
|
@ -1,4 +1,5 @@
|
||||
const { ltrimSlashes } = require('lib/path-utils.js');
|
||||
const { Database } = require('lib/database.js');
|
||||
const Folder = require('lib/models/Folder');
|
||||
const Note = require('lib/models/Note');
|
||||
const Tag = require('lib/models/Tag');
|
||||
@ -383,6 +384,11 @@ class Api {
|
||||
this.logger().info('Request (' + requestId + '): Saving note...');
|
||||
|
||||
const saveOptions = this.defaultSaveOptions_(note, 'POST');
|
||||
saveOptions.autoTimestamp = false; // No auto-timestamp because user may have provided them
|
||||
const timestamp = Date.now();
|
||||
note.updated_time = timestamp;
|
||||
note.created_time = timestamp;
|
||||
|
||||
note = await Note.save(note, saveOptions);
|
||||
|
||||
if (requestNote.tags) {
|
||||
@ -442,8 +448,10 @@ class Api {
|
||||
output.parent_id = folder.id;
|
||||
}
|
||||
|
||||
if (requestNote.source_url) output.source_url = requestNote.source_url;
|
||||
if (requestNote.author) output.author = requestNote.author;
|
||||
if ('source_url' in requestNote) output.source_url = requestNote.source_url;
|
||||
if ('author' in requestNote) output.author = requestNote.author;
|
||||
if ('user_updated_time' in requestNote) output.user_updated_time = Database.formatValue(Database.TYPE_INT, requestNote.user_updated_time);
|
||||
if ('user_created_time' in requestNote) output.user_created_time = Database.formatValue(Database.TYPE_INT, requestNote.user_created_time);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user