UNPKG

donobu

Version:

Create browser automations with an LLM agent and replay them as Playwright scripts.

86 lines 3.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FlowsFilesApi = void 0; const FlowNotFoundException_1 = require("../exceptions/FlowNotFoundException"); const Logger_1 = require("../utils/Logger"); class FlowsFilesApi { constructor(flowsPersistenceFactory) { this.flowsPersistenceFactory = flowsPersistenceFactory; } async getFlowImage(req, res) { const flowId = req.params.flowId; const imageId = req.params.imageId; for (const flowsPersistence of await this.flowsPersistenceFactory.createPersistenceLayers()) { try { const image = await flowsPersistence.getPngScreenShot(flowId, imageId); if (!image) { continue; } res.contentType('image/png'); res.send(image); return; } catch (error) { if (error instanceof FlowNotFoundException_1.FlowNotFoundException) { continue; } Logger_1.appLogger.error('Error getting flow image:', error); throw error; } } res.sendStatus(404); } async getFlowVideo(req, res) { const flowId = req.params.flowId; const rangeHeader = req.header('Range'); for (const flowsPersistence of await this.flowsPersistenceFactory.createPersistenceLayers()) { try { let startOffset = 0; let length; if (rangeHeader) { const ranges = rangeHeader.split('=')[1].split('-'); const start = parseInt(ranges[0], 10); const end = ranges.length > 1 && ranges[1] ? parseInt(ranges[1], 10) : Number.MAX_SAFE_INTEGER; if (end < start) { res.sendStatus(416); // Requested Range Not Satisfiable return; } length = end === Number.MAX_SAFE_INTEGER ? Number.MAX_SAFE_INTEGER : Math.min(end - start + 1, Number.MAX_SAFE_INTEGER); startOffset = start; } else { length = Number.MAX_SAFE_INTEGER; // Request the whole video } const videoSegment = await flowsPersistence.getVideoSegment(flowId, startOffset, length); if (!videoSegment) { continue; } res.header('Content-Type', 'video/webm'); res.header('Accept-Ranges', 'bytes'); res.header('Content-Length', videoSegment.bytes.length.toString()); if (rangeHeader) { const endOffset = startOffset + videoSegment.bytes.length - 1; res.status(206); // Partial Content res.header('Content-Range', `bytes ${startOffset}-${endOffset}/${videoSegment.totalLength}`); } res.send(videoSegment.bytes); return; } catch (error) { if (error instanceof FlowNotFoundException_1.FlowNotFoundException) { continue; } Logger_1.appLogger.error('Error getting flow video:', error); throw error; } } res.sendStatus(404); } } exports.FlowsFilesApi = FlowsFilesApi; //# sourceMappingURL=FlowsFilesApi.js.map