mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
judge: add env setting
This commit is contained in:
1 parent
4052fa691e
commit
2232cf9ff5
5 files changed
+16
-9
No files matched your search
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@hydrooj/hydrojudge",
|
||||
"bin": "bin/hydrojudge.js",
|
||||
"version": "2.6.4",
|
||||
"version": "2.6.5",
|
||||
"main": "package.json",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||
|
||||
@@ -51,4 +51,11 @@ disable:
|
||||
type: boolean
|
||||
name: disable
|
||||
desc: Disable builtin judge
|
||||
default: false
|
||||
default: false
|
||||
env:
|
||||
type: text
|
||||
name: env
|
||||
desc: Sandbox Env
|
||||
default: |
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
HOME=/w
|
||||
@@ -22,6 +22,9 @@ let config = {
|
||||
parallelism: 2,
|
||||
config: null,
|
||||
langs: null,
|
||||
env: `\
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
HOME=/w`,
|
||||
};
|
||||
|
||||
export function getConfig(key: string) {
|
||||
|
||||
@@ -8,8 +8,6 @@ import { getConfig } from './config';
|
||||
import { Logger } from './log';
|
||||
|
||||
const logger = new Logger('sandbox');
|
||||
const env = ['PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'HOME=/w'];
|
||||
const axios = Axios.create({ baseURL: getConfig('sandbox_host') });
|
||||
let callId = 0;
|
||||
|
||||
const statusMap = {
|
||||
@@ -33,7 +31,7 @@ function proc({
|
||||
const size = parseMemoryMB(getConfig('stdio_size'));
|
||||
return {
|
||||
args: cmd(execute.replace(/\$\{dir\}/g, '/w')),
|
||||
env,
|
||||
env: getConfig('env').split('\n'),
|
||||
files: [
|
||||
stdin ? { src: stdin } : { content: '' },
|
||||
{ name: 'stdout', max: 1024 * 1024 * size },
|
||||
@@ -93,7 +91,7 @@ export async function runMultiple(execute) {
|
||||
body.cmd[1].files[1] = null;
|
||||
const id = callId++;
|
||||
if (argv['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(body));
|
||||
res = await axios.post('/run', body);
|
||||
res = await Axios.create({ baseURL: getConfig('sandbox_host') }).post('/run', body);
|
||||
if (argv['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(res.data));
|
||||
} catch (e) {
|
||||
if (e instanceof FormatError) throw e;
|
||||
@@ -103,7 +101,7 @@ export async function runMultiple(execute) {
|
||||
}
|
||||
|
||||
export async function del(fileId) {
|
||||
const res = await axios.delete(`/file/${fileId}`);
|
||||
const res = await Axios.create({ baseURL: getConfig('sandbox_host') }).delete(`/file/${fileId}`);
|
||||
return res.data;
|
||||
}
|
||||
|
||||
@@ -116,7 +114,7 @@ export async function run(execute, params?) {
|
||||
const body = { cmd: [proc({ execute, ...params })] };
|
||||
const id = callId++;
|
||||
if (argv['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(body));
|
||||
const res = await axios.post('/run', body);
|
||||
const res = await Axios.create({ baseURL: getConfig('sandbox_host') }).post('/run', body);
|
||||
if (argv['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(res.data));
|
||||
[result] = res.data;
|
||||
} catch (e) {
|
||||
|
||||
@@ -18,7 +18,6 @@ import { getConfig } from './config';
|
||||
|
||||
declare module 'hydrooj/dist/interface' {
|
||||
interface SystemKeys {
|
||||
'hydrojudge.langs': string,
|
||||
'hydrojudge.cache_dir': string,
|
||||
'hydrojudge.tmp_dir': string,
|
||||
'hydrojudge.tmpfs_size': string,
|
||||
|
||||
Reference in new issue
Block a user