|
|
|
@ -18,15 +18,20 @@ const server = http.createServer((req, res) => {
|
|
|
|
|
switch (req.url) {
|
|
|
|
|
case '/run':
|
|
|
|
|
const jobId = generateId();
|
|
|
|
|
const Code = "echo a";
|
|
|
|
|
const Image = "ghcr.io/moshell-lang/moshell:master";
|
|
|
|
|
const sizeStingIMage = Image.length;
|
|
|
|
|
const code = "echo a";
|
|
|
|
|
const image = "ghcr.io/moshell-lang/moshell:master";
|
|
|
|
|
const buffer = Buffer.allocUnsafe(jobId.length + image.length + code.length + 8);
|
|
|
|
|
buffer.write(jobId, 0);
|
|
|
|
|
buffer.writeUInt32BE(image.length, jobId.length);
|
|
|
|
|
buffer.writeUInt32BE(code.length, jobId.length + 4);
|
|
|
|
|
buffer.write(image, jobId.length + 8);
|
|
|
|
|
buffer.write(code, jobId.length + 8 + image.length);
|
|
|
|
|
res.writeHead(200, {
|
|
|
|
|
'Content-Type': 'text/event-stream',
|
|
|
|
|
Connection: 'keep-alive',
|
|
|
|
|
'Cache-Control': 'no-cache',
|
|
|
|
|
});
|
|
|
|
|
sender.send(`${jobId}${sizeStingIMage}${Image}${Code}`).then(() => {
|
|
|
|
|
sender.send(buffer).then(() => {
|
|
|
|
|
res.write('event: connected\n');
|
|
|
|
|
res.write(`data: ${jobId}\n`);
|
|
|
|
|
res.write('id: 0\n');
|
|
|
|
|