trilium/src/routes/api/recent_notes.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-11-05 11:46:50 +08:00
"use strict";
const sql = require('../../services/sql');
const utils = require('../../services/utils');
const sync_table = require('../../services/sync_table');
const options = require('../../services/options');
2017-11-05 11:46:50 +08:00
async function getRecentNotes() {
return await sql.getRows(`
SELECT
recent_notes.*
FROM
recent_notes
2018-03-25 09:39:15 +08:00
JOIN branches USING(branchId)
WHERE
2018-01-29 08:30:14 +08:00
recent_notes.isDeleted = 0
2018-03-25 09:39:15 +08:00
AND branches.isDeleted = 0
ORDER BY
dateAccessed DESC
LIMIT 200`);
2017-11-05 11:46:50 +08:00
}
2018-03-31 03:34:07 +08:00
async function addRecentNote(req) {
const branchId = req.params.branchId;
const notePath = req.params.notePath;
const sourceId = req.headers.source_id;
await sql.replace('recent_notes', {
branchId: branchId,
notePath: notePath,
dateAccessed: utils.nowDate(),
isDeleted: 0
});
await sync_table.addRecentNoteSync(branchId, sourceId);
await options.setOption('start_note_path', notePath, sourceId);
return await getRecentNotes();
}
module.exports = {
getRecentNotes,
addRecentNote
};