* Milvus (#1644)

* feat: support regx

* 4.8.3 test and fix (#1648)

* perf: version tip

* feat: sandbox support log

* fix: debug component render

* fix: share page header

* fix: input guide auth

* fix: iso viewport

* remove file

* fix: route url

* feat: add debug timout

* perf: reference select support trigger

* perf: session code

* perf: theme

* perf: load milvus
This commit is contained in:
Archer
2024-06-01 09:26:11 +08:00
committed by GitHub
parent 9fc6a8c74a
commit a259d034b8
81 changed files with 1775 additions and 594 deletions

View File

@@ -12,7 +12,7 @@ export class HttpExceptionFilter implements ExceptionFilter {
response.status(500).send({
success: false,
time: new Date(),
msg: getErrText(error)
message: getErrText(error)
});
}
}

View File

@@ -2,3 +2,8 @@ export class RunCodeDto {
code: string;
variables: object;
}
export class RunCodeResponse {
codeReturn: Record<string, any>;
log: string;
}

View File

@@ -1,6 +1,6 @@
import { Controller, Post, Body, HttpCode } from '@nestjs/common';
import { SandboxService } from './sandbox.service';
import { RunCodeDto } from './dto/create-sandbox.dto';
import { RunCodeDto, RunCodeResponse } from './dto/create-sandbox.dto';
import { WorkerNameEnum, runWorker } from 'src/worker/utils';
@Controller('sandbox')
@@ -10,6 +10,6 @@ export class SandboxController {
@Post('/js')
@HttpCode(200)
runJs(@Body() codeProps: RunCodeDto) {
return runWorker(WorkerNameEnum.runJs, codeProps);
return runWorker<RunCodeResponse>(WorkerNameEnum.runJs, codeProps);
}
}

View File

@@ -1,4 +1,4 @@
import { RunCodeDto } from 'src/sandbox/dto/create-sandbox.dto';
import { RunCodeDto, RunCodeResponse } from 'src/sandbox/dto/create-sandbox.dto';
import { parentPort } from 'worker_threads';
import { workerResponse } from './utils';
@@ -6,19 +6,33 @@ import { workerResponse } from './utils';
const ivm = require('isolated-vm');
parentPort?.on('message', ({ code, variables = {} }: RunCodeDto) => {
const resolve = (data: any) => workerResponse({ parentPort, type: 'success', data });
const resolve = (data: RunCodeResponse) => workerResponse({ parentPort, type: 'success', data });
const reject = (error: any) => workerResponse({ parentPort, type: 'error', data: error });
const isolate = new ivm.Isolate({ memoryLimit: 32 });
const context = isolate.createContextSync();
const jail = context.global;
// custom log function
// custom function
const logData = [];
const CustomLogStr = 'CUSTOM_LOG';
code = code.replace(/console\.log/g, `${CustomLogStr}`);
jail.setSync(CustomLogStr, function (...args) {
logData.push(
args
.map((item) => (typeof item === 'object' ? JSON.stringify(item, null, 2) : item))
.join(', ')
);
});
jail.setSync('responseData', function (args: any): any {
if (typeof args === 'object') {
resolve(args);
resolve({
codeReturn: args,
log: logData.join('\n')
});
} else {
reject('Not an invalid response');
reject('Not an invalid response, must return an object');
}
});