trilium/routes/api/sync.js
2017-10-29 11:22:41 -04:00

42 lines
No EOL
1 KiB
JavaScript

"use strict";
const express = require('express');
const router = express.Router();
const auth = require('../../services/auth');
const sync = require('../../services/sync');
router.post('/now', auth.checkApiAuth, async (req, res, next) => {
const log = await sync.sync();
res.send({
success: true,
log: log
});
});
router.get('/changed/:since', auth.checkApiAuth, async (req, res, next) => {
const since = parseInt(req.params.since);
res.send(await sync.getChangedSince(since));
});
router.put('/changed', auth.checkApiAuth, async (req, res, next) => {
await sync.putChanged(req.body);
res.send({});
});
router.get('/note/:noteId/:since', auth.checkApiAuth, async (req, res, next) => {
const noteId = req.params.noteId;
const since = parseInt(req.params.since);
res.send(await sync.getNoteSince(noteId, since));
});
router.put('/note', auth.checkApiAuth, async (req, res, next) => {
await sync.putNote(req.body);
res.send({});
});
module.exports = router;