UNPKG

@fontoxml/fontoxml-development-tools

Version:

Development tools for Fonto.

41 lines (35 loc) 1.4 kB
import asyncRouteWithLockCleanupHandler from '../asyncRouteWithLockCleanupHandler.js'; import correlationIdRepository from './correlationIdRepository.js'; /** @typedef {import('../../src/getAppConfig.js').DevCmsConfig} DevCmsConfig */ /** * @param {DevCmsConfig} _config */ export default function configureDocumentRevisionGetRouteHandler(_config) { return asyncRouteWithLockCleanupHandler(async (acquireLock, req, res) => { const { documentId, revisionId, context } = req.query; // 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. // For review this endpoint might also be called from the editor, in which case the // editSessionToken is provided as a query parameter. const editSessionToken = context ? JSON.parse(context).editSessionToken : correlationIdRepository.getEditSessionTokenForRequest(req); const fileLock = await acquireLock(documentId); const content = await req.cms.getFileByRevisionId( documentId, revisionId, editSessionToken, fileLock, ); fileLock.release(); if (content === null) { res.status(404).end(); return; } res .status(200) .set('content-type', 'application/json; charset=utf-8') .json({ content }); }); }