mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-17 23:12:23 +00:00
feat(judge): add stdin support with test cases and default timeLimit
This commit is contained in:
parent
7f3ac2e0ec
commit
aa9d6d5586
@ -64,7 +64,7 @@ function createTarStream(file: string, value: string) {
|
|||||||
|
|
||||||
export async function judge(
|
export async function judge(
|
||||||
language: EditorLanguage,
|
language: EditorLanguage,
|
||||||
value: string
|
value: string,
|
||||||
): Promise<JudgeResult> {
|
): Promise<JudgeResult> {
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
if (!session) redirect("/sign-in");
|
if (!session) redirect("/sign-in");
|
||||||
@ -230,13 +230,14 @@ async function compile(
|
|||||||
async function run(
|
async function run(
|
||||||
container: Docker.Container,
|
container: Docker.Container,
|
||||||
fileName: string,
|
fileName: string,
|
||||||
timeLimit?: number,
|
timeLimit: number = 1000,
|
||||||
maxOutput: number = 1 * 1024 * 1024
|
maxOutput: number = 1 * 1024 * 1024,
|
||||||
): Promise<JudgeResult> {
|
): Promise<JudgeResult> {
|
||||||
const runExec = await container.exec({
|
const runExec = await container.exec({
|
||||||
Cmd: [`./${fileName}`],
|
Cmd: [`./${fileName}`],
|
||||||
AttachStdout: true,
|
AttachStdout: true,
|
||||||
AttachStderr: true,
|
AttachStderr: true,
|
||||||
|
AttachStdin: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Promise<JudgeResult>((resolve, reject) => {
|
return new Promise<JudgeResult>((resolve, reject) => {
|
||||||
@ -277,11 +278,14 @@ async function run(
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Start the exec stream
|
// Start the exec stream
|
||||||
runExec.start({}, (error, stream) => {
|
runExec.start({ hijack: true }, (error, stream) => {
|
||||||
if (error || !stream) {
|
if (error || !stream) {
|
||||||
return reject({ output: "System Error", exitCode: ExitCode.SE });
|
return reject({ output: "System Error", exitCode: ExitCode.SE });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stream.write("[2,7,11,15]\n9\n[3,2,4]\n6\n[3,3]\n6");
|
||||||
|
stream.end();
|
||||||
|
|
||||||
docker.modem.demuxStream(stream, stdoutStream, stderrStream);
|
docker.modem.demuxStream(stream, stdoutStream, stderrStream);
|
||||||
|
|
||||||
// Timeout mechanism
|
// Timeout mechanism
|
||||||
|
Loading…
Reference in New Issue
Block a user