| 1376 | } |
| 1377 | |
| 1378 | void RenderingController::HandleGET_screenshot(const httplib::Request& req, httplib::Response& res) const |
| 1379 | { |
| 1380 | if (m_RenderWindowBridge == nullptr || !m_RenderWindowBridge->HasScreenshotProvider()) |
| 1381 | { |
| 1382 | const auto error = ErrorResponse::RenderWindowNotAvailable(req.path); |
| 1383 | this->SendErrorResponse(res, 503, error); |
| 1384 | return; |
| 1385 | } |
| 1386 | |
| 1387 | ScreenshotQueryParams params; |
| 1388 | try |
| 1389 | { |
| 1390 | params = ParseScreenshotQueryParams(req); |
| 1391 | } |
| 1392 | catch (const InvalidScreenshotRequest& e) |
| 1393 | { |
| 1394 | this->SendErrorResponse(res, 400, ErrorResponse::InvalidRequest(e.detail, req.path)); |
| 1395 | return; |
| 1396 | } |
| 1397 | |
| 1398 | try |
| 1399 | { |
| 1400 | const auto imageData = m_RenderWindowBridge->TakeScreenshot(params.size, params.format); |
| 1401 | res.status = 200; |
| 1402 | res.set_content( |
| 1403 | reinterpret_cast<const char*>(imageData.data()), |
| 1404 | imageData.size(), |
| 1405 | ContentTypeFor(params.format)); |
| 1406 | } |
| 1407 | catch (const std::exception& e) |
| 1408 | { |
| 1409 | const auto [status, payload] = MapBridgeException(e, req.path); |
| 1410 | this->SendErrorResponse(res, status, payload); |
| 1411 | } |
| 1412 | } |
| 1413 | |
| 1414 | void RenderingController::HandleGET_stdmultiScreenshot(const httplib::Request& req, httplib::Response& res) const |
| 1415 | { |