UNPKG

@fontoxml/fontoxml-development-tools

Version:

Development tools for Fonto.

72 lines (63 loc) 2.03 kB
import asyncRouteWithLockCleanupHandler from '../asyncRouteWithLockCleanupHandler.js'; /** * This endpoint is a copy of configureDocumentHistoryGetPostRouteHandler.js. * * Please keep them in sync. */ /** @typedef {import('../../src/getAppConfig.js').DevCmsConfig} DevCmsConfig */ /** * @param {DevCmsConfig} _config */ export default function configureOutputDocumentHistoryGetPostRouteHandler( _config, ) { return asyncRouteWithLockCleanupHandler(async (acquireLock, 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. In some cases, however, we have an correlationId which we // may resolve to the editSessionToken used by the corresponding call to the proxy. const editSessionToken = correlationIdRepository.getEditSessionTokenForRequest(req); const results = await Promise.all( documentIds.map(async (documentId) => { const fileLock = await acquireLock(documentId); const revisionsAndLatestContent = await req.cms.getRevisionsAndLatestContent( documentId, editSessionToken, fileLock, ); fileLock.release(); if (!revisionsAndLatestContent) { return { documentId, status: 404 }; } const revisions = revisionsAndLatestContent.revisions; const newestRevision = revisions[0]; const newestRevisionIsWorkingCopy = !!newestRevision && newestRevision._editSessionToken === editSessionToken; return { documentId, status: 200, history: { newestRevisionIsWorkingCopy, revisions: revisions.map((revision) => { return { id: revision.id, author: revision.author, lastModifiedTimestamp: revision.lastModifiedTimestamp, }; }), }, }; }), ); res .status(200) .set('content-type', 'application/json; charset=utf-8') .json({ results, }); }); }