trilium/routes/api/sync.js
2017-10-29 14:55:48 -04:00

44 lines
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);
const result = await sync.getChangedSince(since);
res.send(result);
});
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;