UNPKG

@fontoxml/fontoxml-development-tools

Version:

Development tools for Fonto.

64 lines (56 loc) 1.89 kB
import asyncRouteWithLockCleanupHandler from '../asyncRouteWithLockCleanupHandler.js'; /** @typedef {import('../../src/getAppConfig.js').DevCmsConfig} DevCmsConfig */ /** * @param {DevCmsConfig} _config */ export default function configureDocumentHistoryGetPostRouteHandler(_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. 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 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, }); }); }