trilium/routes/api/sync.js

42 lines
1 KiB
JavaScript
Raw Normal View History

2017-10-25 10:58:59 +08:00
"use strict";
const express = require('express');
const router = express.Router();
const auth = require('../../services/auth');
2017-10-27 09:16:21 +08:00
const sync = require('../../services/sync');
2017-10-25 10:58:59 +08:00
2017-10-29 23:22:41 +08:00
router.post('/now', auth.checkApiAuth, async (req, res, next) => {
const log = await sync.sync();
res.send({
success: true,
log: log
});
});
2017-10-25 11:14:26 +08:00
router.get('/changed/:since', auth.checkApiAuth, async (req, res, next) => {
const since = parseInt(req.params.since);
2017-10-25 10:58:59 +08:00
2017-10-27 09:16:21 +08:00
res.send(await sync.getChangedSince(since));
});
router.put('/changed', auth.checkApiAuth, async (req, res, next) => {
await sync.putChanged(req.body);
res.send({});
2017-10-26 10:39:21 +08:00
});
router.get('/note/:noteId/:since', auth.checkApiAuth, async (req, res, next) => {
const noteId = req.params.noteId;
const since = parseInt(req.params.since);
2017-10-27 09:16:21 +08:00
res.send(await sync.getNoteSince(noteId, since));
});
router.put('/note', auth.checkApiAuth, async (req, res, next) => {
await sync.putNote(req.body);
2017-10-26 10:39:21 +08:00
2017-10-27 09:16:21 +08:00
res.send({});
2017-10-25 10:58:59 +08:00
});
module.exports = router;