UNPKG

@fontoxml/fontoxml-development-tools

Version:

Development tools for Fonto.

46 lines (40 loc) 1.29 kB
import correlationIdRepository from './correlationIdRepository.js'; /** @typedef {import('../../src/getAppConfig.js').DevCmsConfig} DevCmsConfig */ /** * @param {DevCmsConfig} _config */ function configureDocumentHistoryGetRouteHandler(_config) { return (req, res) => { const documentId = req.query.documentId; // Because these requests do not originate from the editor, but from an other server, we // have no edit session token. We do, however, have an correlationId which we may resolve // to the editSessionToken used by the corresponding call to the proxy const editSessionToken = correlationIdRepository.getEditSessionTokenForRequest(req); req.cms.loadHistory( documentId, editSessionToken, (error, revisions) => { if (error) { if (error.status === 404) { res.status(404).end(); } else { res.status(500).end(); } return; } const newestRevision = revisions[0]; const newestRevisionIsWorkingCopy = !!newestRevision && newestRevision._editSessionToken === editSessionToken; res.status(200) .set('content-type', 'application/json; charset=utf-8') .json({ newestRevisionIsWorkingCopy, revisions, }); } ); }; } export default configureDocumentHistoryGetRouteHandler;