UNPKG

@fontoxml/fontoxml-development-tools

Version:

Development tools for Fonto.

54 lines (46 loc) 1.7 kB
import asyncRouteWithLockCleanupHandler from '../asyncRouteWithLockCleanupHandler.js'; import correlationIdRepository from './correlationIdRepository.js'; /** @typedef {import('../../src/getAppConfig.js').DevCmsConfig} DevCmsConfig */ /** * @param {DevCmsConfig} _config */ function configureDocumentHistoryGetRouteHandler(_config) { return asyncRouteWithLockCleanupHandler(async (acquireLock, 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); const fileLock = await acquireLock(documentId); const revisionsAndLatestContent = await req.cms.getRevisionsAndLatestContent( documentId, editSessionToken, fileLock, ); fileLock.release(); if (!revisionsAndLatestContent) { res.status(404).end(); return; } const revisions = revisionsAndLatestContent.revisions; const newestRevision = revisions[0]; const newestRevisionIsWorkingCopy = !!newestRevision && newestRevision._editSessionToken === editSessionToken; res .status(200) .set('content-type', 'application/json; charset=utf-8') .json({ newestRevisionIsWorkingCopy, revisions: revisions.map((revision) => { return { id: revision.id, author: revision.author, lastModifiedTimestamp: revision.lastModifiedTimestamp, }; }), }); }); } export default configureDocumentHistoryGetRouteHandler;