2017-11-05 11:46:50 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const express = require('express');
|
|
|
|
const router = express.Router();
|
|
|
|
const sql = require('../../services/sql');
|
|
|
|
const auth = require('../../services/auth');
|
|
|
|
const utils = require('../../services/utils');
|
2017-11-17 10:50:00 +08:00
|
|
|
const sync_table = require('../../services/sync_table');
|
2017-11-19 06:05:50 +08:00
|
|
|
const options = require('../../services/options');
|
2017-11-05 11:46:50 +08:00
|
|
|
|
|
|
|
router.get('', auth.checkApiAuth, async (req, res, next) => {
|
|
|
|
res.send(await getRecentNotes());
|
|
|
|
});
|
|
|
|
|
2017-12-03 23:06:53 +08:00
|
|
|
router.put('/:noteTreeId/:notePath', auth.checkApiAuth, async (req, res, next) => {
|
|
|
|
const noteTreeId = req.params.noteTreeId;
|
2017-11-20 01:06:48 +08:00
|
|
|
const notePath = req.params.notePath;
|
2017-11-19 06:05:50 +08:00
|
|
|
|
2017-11-29 06:24:08 +08:00
|
|
|
await sql.doInTransaction(async () => {
|
|
|
|
await sql.replace('recent_notes', {
|
2017-12-03 23:06:53 +08:00
|
|
|
note_tree_id: noteTreeId,
|
2017-11-24 13:09:53 +08:00
|
|
|
note_path: notePath,
|
2017-12-11 01:56:59 +08:00
|
|
|
date_accessed: utils.nowDate(),
|
2017-11-24 13:09:53 +08:00
|
|
|
is_deleted: 0
|
|
|
|
});
|
2017-11-05 11:46:50 +08:00
|
|
|
|
2017-12-03 23:06:53 +08:00
|
|
|
await sync_table.addRecentNoteSync(noteTreeId);
|
2017-11-19 06:05:50 +08:00
|
|
|
|
2017-12-07 12:15:53 +08:00
|
|
|
await options.setOption('start_note_path', notePath);
|
2017-11-24 13:09:53 +08:00
|
|
|
});
|
2017-11-05 12:16:02 +08:00
|
|
|
|
2017-11-05 11:46:50 +08:00
|
|
|
res.send(await getRecentNotes());
|
|
|
|
});
|
|
|
|
|
|
|
|
async function getRecentNotes() {
|
2017-11-05 12:16:02 +08:00
|
|
|
return await sql.getResults("SELECT * FROM recent_notes WHERE is_deleted = 0 ORDER BY date_accessed DESC");
|
2017-11-05 11:46:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = router;
|