UNPKG

@fontoxml/fontoxml-development-tools

Version:

Development tools for Fonto.

57 lines (49 loc) 1.58 kB
/** @typedef {import('../../src/getAppConfig.js').DevCmsConfig} DevCmsConfig */ /** * @param {DevCmsConfig} _config */ export default function configureDocumentHistoryGetPostRouteHandler(_config) { return (req, res) => { const documentIds = req.body.documentIds; const correlationIdRepository = req.repositories.correlationId; // Because these requests do not originate from the editor, but from another 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); const promises = documentIds.map((documentId) => { return new Promise((resolve, _) => { req.cms.loadHistory( documentId, editSessionToken, (error, revisions) => { const historyResponse = { documentId }; if (error) { historyResponse.status = 404; } else { historyResponse.status = 200; const newestRevision = revisions[0]; const newestRevisionIsWorkingCopy = !!newestRevision && newestRevision._editSessionToken === editSessionToken; historyResponse.history = { newestRevisionIsWorkingCopy, revisions, }; } resolve(historyResponse); } ); }); }); Promise.all(promises).then((results) => { const response = { results, }; res.status(200) .set('content-type', 'application/json; charset=utf-8') .json(response); }); }; }