Files
Dorod-Sky/skyvern-frontend/server.js
2024-04-01 21:34:52 +03:00

29 lines
731 B
JavaScript

import express from "express";
import fs from "fs";
const app = express();
app.get("/artifact", (req, res) => {
const range = req.headers.range;
const path = req.query.path;
const videoSize = fs.statSync(path).size;
const chunkSize = 1 * 1e6;
const start = Number(range.replace(/\D/g, ""));
const end = Math.min(start + chunkSize, videoSize - 1);
const contentLength = end - start + 1;
const headers = {
"Content-Range": `bytes ${start}-${end}/${videoSize}`,
"Accept-Ranges": "bytes",
"Content-Length": contentLength,
"Content-Type": "video/mp4",
};
res.writeHead(206, headers);
const stream = fs.createReadStream(path, {
start,
end,
});
stream.pipe(res);
});
app.listen(9090);