|
|
|
@ -1,8 +1,12 @@
|
|
|
|
|
export const RUNNERS = ['bash', 'moshell', 'bun', 'typescript'] as const;
|
|
|
|
|
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',
|
|
|
|
|
const aliases: Record<string, (typeof RUNNERS)[number]> = {
|
|
|
|
|
JavaScript: "bun",
|
|
|
|
|
TypeScript: "typescript",
|
|
|
|
|
};
|
|
|
|
|
export const IMAGES = {
|
|
|
|
|
logo: "logo.png",
|
|
|
|
|
background: "background.png",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -12,9 +16,15 @@ const aliases: Record<string, typeof RUNNERS[number]> = {
|
|
|
|
|
* @param code The code to be executed.
|
|
|
|
|
* @param image The image to be used.
|
|
|
|
|
*/
|
|
|
|
|
export function allocateBuffer(jobId: string, code: string, image: string): Buffer {
|
|
|
|
|
export function allocateBuffer(
|
|
|
|
|
jobId: string,
|
|
|
|
|
code: string,
|
|
|
|
|
image: string
|
|
|
|
|
): Buffer {
|
|
|
|
|
let cur = 0;
|
|
|
|
|
const buffer = Buffer.allocUnsafe(jobId.length + image.length + code.length + 9);
|
|
|
|
|
const buffer = Buffer.allocUnsafe(
|
|
|
|
|
jobId.length + image.length + code.length + 9
|
|
|
|
|
);
|
|
|
|
|
cur = buffer.writeUInt8(0, cur);
|
|
|
|
|
cur += buffer.write(jobId, cur);
|
|
|
|
|
cur = buffer.writeUInt32BE(image.length, cur);
|
|
|
|
@ -24,10 +34,10 @@ export function allocateBuffer(jobId: string, code: string, image: string): Buff
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getRunner(language: string): typeof RUNNERS[number] | null {
|
|
|
|
|
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 language as (typeof RUNNERS)[number];
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|