trilium/src/routes/api/note_revisions.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-10-22 09:10:33 +08:00
"use strict";
const repository = require('../../services/repository');
2019-09-07 16:11:59 +08:00
const noteCacheService = require('../../services/note_cache');
async function getNoteRevisions(req) {
2019-11-02 02:21:48 +08:00
const {noteId} = req.params;
return await repository.getEntities(`
SELECT note_revisions.*
FROM note_revisions
WHERE noteId = ?
2019-11-02 02:21:48 +08:00
ORDER BY utcDateCreated DESC`, [noteId]);
}
2019-11-02 02:21:48 +08:00
async function getNoteRevision(req) {
2019-11-02 03:00:56 +08:00
const noteRevision = await repository.getNoteRevision(req.params.noteRevisionId);
2019-11-02 03:00:56 +08:00
await noteRevision.getContent();
return noteRevision;
}
2019-09-07 16:11:59 +08:00
async function getEditedNotesOnDate(req) {
const date = req.params.date;
const notes = await repository.getEntities(`
select distinct notes.*
from notes
left join note_revisions using (noteId)
where substr(notes.dateCreated, 0, 11) = ?
or substr(notes.dateModified, 0, 11) = ?
2019-11-02 02:21:48 +08:00
or substr(note_revisions.dateLastEdited, 0, 11) = ?`, [date, date, date]);
2019-09-07 16:11:59 +08:00
for (const note of notes) {
const notePath = noteCacheService.getNotePath(note.noteId);
note.notePath = notePath ? notePath.notePath : null;
}
return notes;
}
module.exports = {
2019-09-07 16:11:59 +08:00
getNoteRevisions,
2019-11-02 02:21:48 +08:00
getNoteRevision,
2019-09-07 16:11:59 +08:00
getEditedNotesOnDate
};