1 Star 0 Fork 0

inveta/peer-stream

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
.js 1.82 KB
一键复制 编辑 原始数据 按行查看 历史
Jean 提交于 2023-12-01 13:55 . 1
module.exports = async function (request, response, server) {
switch (request.url) {
case "/signal": {
return Signal(request, response, server);
break;
}
case "/eval": {
return eval(decodeURIComponent(request.headers['eval']))
break;
}
case "/exec": {
return new Promise((res, rej) => {
require('child_process').exec(
decodeURIComponent(request.headers['exec']),
(error, stdout, stderr) => {
if (error) {
rej(stderr)
} else {
res(stdout)
}
});
})
break;
}
case "/write": {
return Write(request, response, server);
break;
}
}
};
// 修改整体配置
async function Signal(request, response, server) {
let newSignal = JSON.parse(decodeURIComponent(request.headers['signal']))
//修改了端口,执行下列方法使其生效
if (newSignal.PORT) {
await global.serve(newSignal.PORT);
}
let signal = require('./signal.json');
Object.assign(signal, newSignal);
Object.assign(global, newSignal);
if (newSignal.UE5) {
global.InitUe5Pool();
}
await require('fs').promises.writeFile(__dirname + '/signal.json', JSON.stringify(signal, null, '\t'));
await new Promise(res => {
response.end(JSON.stringify(newSignal), res);
})
if (newSignal.PORT) {
server.closeAllConnections()
server.close(() => { });
}
}
async function Write(req, res, server) {
const chunks = [];
// Receive chunks of data
req.on('data', chunk => {
chunks.push(chunk);
});
const body = await new Promise(res => {
req.on('end', () => {
res(Buffer.concat(chunks));
})
})
await require('fs').promises.writeFile(__dirname + decodeURIComponent(req.headers['write']), body)
return ('updated');
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/inveta/peer-stream.git
git@gitee.com:inveta/peer-stream.git
inveta
peer-stream
peer-stream
main

搜索帮助