You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-16 00:14:34 +02:00
Api: Allow preserving timestamps when updating a note
This commit is contained in:
@ -432,6 +432,8 @@ export default class Api {
|
||||
const timestamp = Date.now();
|
||||
note.updated_time = timestamp;
|
||||
note.created_time = timestamp;
|
||||
if (!('user_updated_time' in note)) note.user_updated_time = timestamp;
|
||||
if (!('user_created_time' in note)) note.user_created_time = timestamp;
|
||||
|
||||
note = await Note.save(note, saveOptions);
|
||||
|
||||
@ -454,7 +456,24 @@ export default class Api {
|
||||
|
||||
if (!note) throw new ErrorNotFound();
|
||||
|
||||
const updatedNote = await this.defaultAction_(BaseModel.TYPE_NOTE, request, id, link);
|
||||
const saveOptions = {
|
||||
...this.defaultSaveOptions_(note, 'PUT'),
|
||||
autoTimestamp: false, // No auto-timestamp because user may have provided them
|
||||
userSideValidation: true,
|
||||
};
|
||||
|
||||
const timestamp = Date.now();
|
||||
|
||||
const newProps = request.bodyJson(this.readonlyProperties('PUT'));
|
||||
if (!('user_updated_time' in newProps)) newProps.user_updated_time = timestamp;
|
||||
|
||||
let newNote = {
|
||||
...note,
|
||||
...newProps,
|
||||
updated_time: timestamp,
|
||||
};
|
||||
|
||||
newNote = await Note.save(newNote, saveOptions);
|
||||
|
||||
const requestNote = JSON.parse(request.body);
|
||||
if (requestNote.tags || requestNote.tags === '') {
|
||||
@ -462,7 +481,7 @@ export default class Api {
|
||||
await Tag.setNoteTagsByTitles(id, tagTitles);
|
||||
}
|
||||
|
||||
return updatedNote;
|
||||
return newNote;
|
||||
}
|
||||
|
||||
return this.defaultAction_(BaseModel.TYPE_NOTE, request, id, link);
|
||||
|
Reference in New Issue
Block a user