this is awful right now
This commit is contained in:
commit
353bd175b0
7 changed files with 991 additions and 0 deletions
64
index.js
Normal file
64
index.js
Normal file
|
@ -0,0 +1,64 @@
|
|||
import { spawn } from "node:child_process";
|
||||
import { mkdir } from 'node:fs/promises';
|
||||
import { createHash } from "node:crypto";
|
||||
import express from "express";
|
||||
|
||||
let sessions = {};
|
||||
let channels = {};
|
||||
|
||||
const app = express();
|
||||
app.use(express.json())
|
||||
app.set('trust proxy', true)
|
||||
|
||||
app.use(express.static('static'));
|
||||
|
||||
app.post('/', async function (req, res) {
|
||||
let id = 'web:' + createHash('sha256').update(req.ip).digest('base64');
|
||||
|
||||
if (!sessions[id]) {
|
||||
try {
|
||||
await mkdir(`./bin/${id}`);
|
||||
} catch (err) {
|
||||
|
||||
}
|
||||
sessions[id] = spawn('../elem', [id], {
|
||||
'cwd': `./bin/${id}`
|
||||
});
|
||||
|
||||
sessions[id].stdout.on('data', (chunk) => {
|
||||
if (chunk.toString().length > 1) {
|
||||
let str = chunk.toString();
|
||||
//str = str.replaceAll(/user:([0-9]+)/g, '<@$1>');
|
||||
|
||||
if (channels[id].headersSent) return;
|
||||
|
||||
try {
|
||||
channels[id].send(str).header('access-allow-control-origin','*')
|
||||
} catch (err) { }
|
||||
}
|
||||
});
|
||||
sessions[id].on('close', () => {
|
||||
delete sessions[id];
|
||||
})
|
||||
}
|
||||
|
||||
setTimeout(async function() {
|
||||
if (!sessions[id]) return;
|
||||
if (channels[id].headersSent) return;
|
||||
try {
|
||||
channels[id].send('Input is possibly malformed.').header('access-allow-control-origin','*')
|
||||
} catch (err) {
|
||||
|
||||
}
|
||||
},1000);
|
||||
|
||||
channels[id] = res;
|
||||
|
||||
let msgs = req.body.data.split('\n');
|
||||
|
||||
setTimeout(async function () {
|
||||
sessions[id].stdin.write(msgs[0] + '\n');
|
||||
}, 100);
|
||||
});
|
||||
|
||||
app.listen(process.env.port || 3007)
|
Loading…
Add table
Add a link
Reference in a new issue