@fontoxml/fontoxml-development-tools
Version:
Development tools for Fonto.
68 lines (58 loc) • 1.96 kB
JavaScript
import asyncRouteWithLockCleanupHandler from '../asyncRouteWithLockCleanupHandler.js';
import correlationIdRepository from './correlationIdRepository.js';
import mapAnnotationResult from './review-annotations/mapAnnotationResult.js';
/**
* This endpoint is a copy of configureReviewAnnotationGetPostRouteHandler.js.
*
* Please keep both endpoints in sync.
*
* But note the differences:
* - For Output there is never a editSessionToken in the request body or query parameters.
* - Output can receive an optional Fonto-Correlation-Id.
*/
/** @typedef {import('../../src/getAppConfig.js').DevCmsConfig} DevCmsConfig */
/**
* @param {DevCmsConfig} config
*/
export default function configureOutputReviewAnnotationGetPostRouteHandler(
config,
) {
return asyncRouteWithLockCleanupHandler(async (_acquireLock, req, res) => {
const { annotationIds } = req.body;
const editSessionToken = correlationIdRepository.getEditSessionTokenForRequest(req);
if (!annotationIds || !annotationIds.length) {
res
.status(400)
.send('Missing at least one item in "annotationIds" in the request.');
return;
}
const timeoutSet = await config.debugConfiguration.getTimeoutConfigForRoute(
req.cms,
editSessionToken,
'/output/review/annotation/get',
'POST',
);
if (timeoutSet) {
// Do not handle the request, but let it time out.
return new Promise(() => {});
}
const debugStatusGetCode =
await config.debugConfiguration.getDebugConfigurationForAnnotationGet(
req.cms,
editSessionToken,
);
if (debugStatusGetCode) {
res.status(debugStatusGetCode).end();
return;
}
const currentSession = req.getFontoSession(editSessionToken);
const annotations = await req.repositories.annotation.getAnnotations(
req.cms,
currentSession,
annotationIds,
);
res.set('content-type', 'application/json; charset=utf-8').json({
annotations: annotations.map(mapAnnotationResult),
});
});
}