mirror of
https://github.com/engineer-man/piston.git
synced 2025-06-07 18:56:26 +02:00
remove **everything** in preparations for v3
This commit is contained in:
parent
b9ef21cbea
commit
c5f3305c23
103 changed files with 1 additions and 3179 deletions
|
@ -1,79 +0,0 @@
|
|||
const express = require('express');
|
||||
const { execute } = require('../../lxc/execute.js');
|
||||
const { languages } = require('./languages');
|
||||
const { checkSchema, validationResult } = require('express-validator');
|
||||
|
||||
const PORT = 2000;
|
||||
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
|
||||
app.post(
|
||||
'/execute',
|
||||
checkSchema({
|
||||
language: {
|
||||
in: 'body',
|
||||
notEmpty: {
|
||||
errorMessage: 'No language supplied',
|
||||
},
|
||||
isString: {
|
||||
errorMessage: 'Supplied language is not a string',
|
||||
},
|
||||
custom: {
|
||||
options: value => value && languages.find(language => language.aliases.includes(value.toLowerCase())),
|
||||
errorMessage: 'Supplied language is not supported by Piston',
|
||||
},
|
||||
},
|
||||
source: {
|
||||
in: 'body',
|
||||
notEmpty: {
|
||||
errorMessage: 'No source supplied',
|
||||
},
|
||||
isString: {
|
||||
errorMessage: 'Supplied source is not a string',
|
||||
},
|
||||
},
|
||||
args: {
|
||||
in: 'body',
|
||||
optional: true,
|
||||
isArray: {
|
||||
errorMessage: 'Supplied args is not an array',
|
||||
},
|
||||
},
|
||||
stdin: {
|
||||
in: 'body',
|
||||
optional: true,
|
||||
isString: {
|
||||
errorMessage: 'Supplied stdin is not a string',
|
||||
},
|
||||
}
|
||||
}),
|
||||
async (req, res) => {
|
||||
const errors = validationResult(req).array();
|
||||
|
||||
if (errors.length === 0) {
|
||||
const language = languages.find(language =>
|
||||
language.aliases.includes(req.body.language.toLowerCase())
|
||||
);
|
||||
|
||||
const { stdout, stderr, output, ran } = await execute(language, req.body.source, req.body.stdin, req.body.args);
|
||||
|
||||
res.status(200).json({
|
||||
ran,
|
||||
language: language.name,
|
||||
version: language.version,
|
||||
stdout,
|
||||
stderr,
|
||||
output,
|
||||
});
|
||||
} else {
|
||||
res.status(400).json({
|
||||
message: errors[0].msg,
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
app.get('/versions', (_, res) => res.json(languages));
|
||||
|
||||
app.listen(PORT, () => console.log(`Listening on port ${PORT}`));
|
|
@ -1,39 +0,0 @@
|
|||
const { spawn } = require('child_process');
|
||||
const languages = require('../../config/languages.json');
|
||||
|
||||
{
|
||||
const process = spawn(__dirname + '/../../lxc/util/versions');
|
||||
|
||||
let output = '';
|
||||
process.stderr.on('data', chunk => output += chunk);
|
||||
process.stdout.on('data', chunk => output += chunk);
|
||||
|
||||
process.on('exit', () => {
|
||||
const sections = output.toLowerCase().split('---');
|
||||
const versions = {};
|
||||
|
||||
for (const section of sections) {
|
||||
const lines = section.trim().split('\n');
|
||||
|
||||
if (lines.length >= 2) {
|
||||
const language = lines[0];
|
||||
|
||||
if (language === 'java') {
|
||||
versions[language] = /\d+/.exec(lines[1])?.[0];
|
||||
} else if (language === 'emacs') {
|
||||
versions[language] = /\d+\.\d+/.exec(lines[1])?.[0];
|
||||
} else {
|
||||
versions[language] = /\d+\.\d+\.\d+/.exec(section)?.[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const language of languages) {
|
||||
language.version = versions[language.name];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
languages,
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue