new mechanism to wait for sync after interaction with backend in Script API using api.waitForMaxKnownSyncId()

This commit is contained in:
zadam
2019-12-09 23:07:45 +01:00
parent 1e123f2390
commit 6f32d6fabe
7 changed files with 89 additions and 31 deletions

View File

@@ -44,6 +44,7 @@ const auth = require('../services/auth');
const cls = require('../services/cls');
const sql = require('../services/sql');
const protectedSessionService = require('../services/protected_session');
const syncTableService = require('../services/sync_table');
const csurf = require('csurf');
const csrfMiddleware = csurf({
@@ -52,6 +53,8 @@ const csrfMiddleware = csurf({
});
function apiResultHandler(req, res, result) {
res.setHeader('trilium-max-sync-id', syncTableService.getMaxSyncId());
// if it's an array and first element is integer then we consider this to be [statusCode, response] format
if (Array.isArray(result) && result.length > 0 && Number.isInteger(result[0])) {
const [statusCode, response] = result;