"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.journeyScreenshotHandler = void 0; var _get_journey_screenshot = require("../legacy_uptime/lib/requests/get_journey_screenshot"); var _runtime_types = require("../../common/runtime_types"); /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ function getSharedHeaders(stepName, totalSteps) { return { 'cache-control': 'max-age=600', 'caption-name': stepName, 'max-steps': String(totalSteps) }; } const journeyScreenshotHandler = async ({ response, request, uptimeEsClient }) => { var _result$synthetics; const { checkGroup, stepIndex } = request.params; const result = await (0, _get_journey_screenshot.getJourneyScreenshot)({ uptimeEsClient, checkGroup, stepIndex }); if ((0, _runtime_types.isFullScreenshot)(result) && typeof ((_result$synthetics = result.synthetics) === null || _result$synthetics === void 0 ? void 0 : _result$synthetics.blob) !== 'undefined') { return response.ok({ body: Buffer.from(result.synthetics.blob, 'base64'), headers: { 'content-type': result.synthetics.blob_mime || 'image/png', // falls back to 'image/png' for earlier versions of synthetics ...getSharedHeaders(result.synthetics.step.name, result.totalSteps) } }); } else if ((0, _runtime_types.isRefResult)(result)) { return response.ok({ body: { screenshotRef: result }, headers: getSharedHeaders(result.synthetics.step.name, result.totalSteps) }); } return response.notFound(); }; exports.journeyScreenshotHandler = journeyScreenshotHandler;