perf: improver code editor request return type and test modal style
This commit is contained in:
parent
b751222b39
commit
4f35463f89
@ -44,5 +44,11 @@ interface AxiosConfig {
|
||||
} | false;
|
||||
}
|
||||
|
||||
const request = async (config: AxiosConfig) => {}
|
||||
interface RequestReturn {
|
||||
headers: Record<string, string>;
|
||||
data: any;
|
||||
status: number;
|
||||
}
|
||||
|
||||
const request = async (config: AxiosConfig): Promise<RequestReturn> => {}
|
||||
`;
|
||||
|
@ -26,6 +26,9 @@ export const CodeEditor: React.FC<CodeEditorProps> = React.memo((props) => {
|
||||
theme={theme}
|
||||
defaultLanguage="javascript"
|
||||
value={props.value}
|
||||
options={{
|
||||
tabSize: 2,
|
||||
}}
|
||||
onChange={(val) => props.onChange?.(val ?? '')}
|
||||
beforeMount={handleEditorWillMount}
|
||||
/>
|
||||
|
@ -27,6 +27,7 @@ export const MonitorCustom: React.FC = React.memo(() => {
|
||||
centered: true,
|
||||
maskClosable: true,
|
||||
title: 'Run Completed',
|
||||
width: 'clamp(320px, 60vw, 860px)',
|
||||
content: (
|
||||
<div>
|
||||
{logger.map(([type, time, ...args]) => (
|
||||
@ -43,7 +44,7 @@ export const MonitorCustom: React.FC = React.memo(() => {
|
||||
{dayjs(time).format('HH:mm:ss')}
|
||||
</span>
|
||||
|
||||
{args.join(' ')}
|
||||
<span className="break-all">{args.join(' ')}</span>
|
||||
</div>
|
||||
))}
|
||||
|
||||
|
@ -27,7 +27,12 @@ export async function runCodeInVM(_code: string) {
|
||||
const start = Date.now();
|
||||
const isolate = new ivm.Isolate({ memoryLimit: env.sandboxMemoryLimit });
|
||||
|
||||
const code = `${environmentScript}\n\n;(async () => {${_code}})()`;
|
||||
// avoid end comment with line break
|
||||
const code = `${environmentScript}
|
||||
|
||||
;(async () => {
|
||||
${_code}
|
||||
})()`;
|
||||
|
||||
const [context, script] = await Promise.all([
|
||||
isolate.createContext(),
|
||||
|
@ -187,7 +187,13 @@ export const monitorRouter = router({
|
||||
})
|
||||
)
|
||||
.mutation(async ({ input }) => {
|
||||
return runCodeInVM(input.code);
|
||||
const res = await runCodeInVM(input.code);
|
||||
|
||||
return {
|
||||
logger: res.logger,
|
||||
result: res.result ?? -1,
|
||||
usage: res.usage,
|
||||
};
|
||||
}),
|
||||
data: workspaceProcedure
|
||||
.meta(
|
||||
|
@ -155,6 +155,7 @@ export function buildSandbox(context: Context, globals: SandboxGlobals = {}) {
|
||||
const result = await axios.request(config);
|
||||
|
||||
return makeTransferable({
|
||||
headers: { ...result.headers },
|
||||
data: result.data,
|
||||
status: result.status,
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user