mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 11:26:15 +01:00
added sync for recent notes
This commit is contained in:
@@ -13,14 +13,19 @@ router.get('', auth.checkApiAuth, async (req, res, next) => {
|
||||
router.put('/:noteId', auth.checkApiAuth, async (req, res, next) => {
|
||||
await sql.replace('recent_notes', {
|
||||
note_id: req.params.noteId,
|
||||
date_accessed: utils.nowTimestamp()
|
||||
date_accessed: utils.nowTimestamp(),
|
||||
is_deleted: 0
|
||||
});
|
||||
|
||||
await sql.addRecentNoteSync(req.params.noteId);
|
||||
|
||||
res.send(await getRecentNotes());
|
||||
});
|
||||
|
||||
router.delete('/:noteId', auth.checkApiAuth, async (req, res, next) => {
|
||||
await sql.remove('recent_notes', req.params.noteId);
|
||||
await sql.execute('UPDATE recent_notes SET is_deleted = 1 WHERE note_id = ?', [req.params.noteId]);
|
||||
|
||||
await sql.addRecentNoteSync(req.params.noteId);
|
||||
|
||||
res.send(await getRecentNotes());
|
||||
});
|
||||
@@ -28,11 +33,11 @@ router.delete('/:noteId', auth.checkApiAuth, async (req, res, next) => {
|
||||
async function getRecentNotes() {
|
||||
await deleteOld();
|
||||
|
||||
return await sql.getResults("SELECT * FROM recent_notes ORDER BY date_accessed DESC");
|
||||
return await sql.getResults("SELECT * FROM recent_notes WHERE is_deleted = 0 ORDER BY date_accessed DESC");
|
||||
}
|
||||
|
||||
async function deleteOld() {
|
||||
const cutoffDateAccessed = await sql.getSingleValue("SELECT date_accessed FROM recent_notes ORDER BY date_accessed DESC LIMIT 100, 1");
|
||||
const cutoffDateAccessed = await sql.getSingleValue("SELECT date_accessed FROM recent_notes WHERE is_deleted = 0 ORDER BY date_accessed DESC LIMIT 100, 1");
|
||||
|
||||
if (cutoffDateAccessed) {
|
||||
await sql.execute("DELETE FROM recent_notes WHERE date_accessed < ?", [cutoffDateAccessed]);
|
||||
|
||||
@@ -59,6 +59,12 @@ router.get('/notes_reordering/:noteParentId', auth.checkApiAuth, async (req, res
|
||||
});
|
||||
});
|
||||
|
||||
router.get('/recent_notes/:noteId', auth.checkApiAuth, async (req, res, next) => {
|
||||
const noteId = req.params.noteId;
|
||||
|
||||
res.send(await sql.getSingleResult("SELECT * FROM recent_notes WHERE note_id = ?", [noteId]));
|
||||
});
|
||||
|
||||
router.put('/notes', auth.checkApiAuth, async (req, res, next) => {
|
||||
await sync.updateNote(req.body.entity, req.body.links, req.body.sourceId);
|
||||
|
||||
@@ -89,4 +95,10 @@ router.put('/options', auth.checkApiAuth, async (req, res, next) => {
|
||||
res.send({});
|
||||
});
|
||||
|
||||
router.put('/recent_notes', auth.checkApiAuth, async (req, res, next) => {
|
||||
await sync.updateRecentNotes(req.body.entity, req.body.sourceId);
|
||||
|
||||
res.send({});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user