Merge branch 'sqlite3' of https://codefirst.iut.uca.fr/git/sandkasten/labyrinth into sqlite3
continuous-integration/drone/pr Build is failing Details
continuous-integration/drone/push Build is failing Details

pull/2/head
Hugo PRADIER 1 year ago
commit 31d3b6403a

@ -1,5 +1,5 @@
import sqlite3 from "sqlite3";
import fs from "fs";
import sqlite3 from "sqlite3";
const dbDirectory = "./src/db";
const dbFilePath = `${dbDirectory}/database.db`;

@ -1,5 +1,8 @@
export const IMAGES = {
moshell: 'ghcr.io/moshell-lang/moshell:master',
export const RUNNERS = ['bash', 'moshell', 'bun', 'typescript'] as const;
const ALLOWED_LANGUAGES = new Set<string>(RUNNERS);
const aliases: Record<string, typeof RUNNERS[number]> = {
'JavaScript': 'bun',
'TypeScript': 'typescript',
};
/**
@ -20,3 +23,11 @@ export function allocateBuffer(jobId: string, code: string, image: string): Buff
buffer.write(code, cur);
return buffer;
}
export function getRunner(language: string): typeof RUNNERS[number] | null {
language = aliases[language] || language;
if (ALLOWED_LANGUAGES.has(language)) {
return language as typeof RUNNERS[number];
}
return null;
}

@ -22,42 +22,6 @@ await fastify.register(cors, {
origin: process.env.ALLOW_ORIGIN || "*",
});
/* Code runner in a container */
/* POST /run : Run code in a container */
fastify.post(
"/run",
{
schema: {
body: Type.Object({
code: Type.String(),
language: Type.String(),
}),
},
},
(req, reply) => {
const { code, language } = req.body;
const jobId = generateId();
const buffer = allocateBuffer(jobId, code, IMAGES.moshell);
reply.raw.writeHead(200, {
"Content-Type": "text/event-stream",
Connection: "keep-alive",
"Cache-Control": "no-cache",
"Access-Control-Allow-Origin": process.env.ALLOW_ORIGIN || "*",
});
reply.raw.on("close", () => {
delete clients[jobId];
});
sender.send(buffer).then(() => {
reply.raw.write("event: connected\n");
reply.raw.write(`data: ${jobId}\n`);
reply.raw.write("id: 0\n\n");
});
clients[jobId] = reply;
}
);
/* Database */
/* Création du répertoire de la base de données s'il n'existe pas */

Loading…
Cancel
Save