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;
|
} | 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}
|
theme={theme}
|
||||||
defaultLanguage="javascript"
|
defaultLanguage="javascript"
|
||||||
value={props.value}
|
value={props.value}
|
||||||
|
options={{
|
||||||
|
tabSize: 2,
|
||||||
|
}}
|
||||||
onChange={(val) => props.onChange?.(val ?? '')}
|
onChange={(val) => props.onChange?.(val ?? '')}
|
||||||
beforeMount={handleEditorWillMount}
|
beforeMount={handleEditorWillMount}
|
||||||
/>
|
/>
|
||||||
|
@ -27,6 +27,7 @@ export const MonitorCustom: React.FC = React.memo(() => {
|
|||||||
centered: true,
|
centered: true,
|
||||||
maskClosable: true,
|
maskClosable: true,
|
||||||
title: 'Run Completed',
|
title: 'Run Completed',
|
||||||
|
width: 'clamp(320px, 60vw, 860px)',
|
||||||
content: (
|
content: (
|
||||||
<div>
|
<div>
|
||||||
{logger.map(([type, time, ...args]) => (
|
{logger.map(([type, time, ...args]) => (
|
||||||
@ -43,7 +44,7 @@ export const MonitorCustom: React.FC = React.memo(() => {
|
|||||||
{dayjs(time).format('HH:mm:ss')}
|
{dayjs(time).format('HH:mm:ss')}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
{args.join(' ')}
|
<span className="break-all">{args.join(' ')}</span>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
@ -27,7 +27,12 @@ export async function runCodeInVM(_code: string) {
|
|||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
const isolate = new ivm.Isolate({ memoryLimit: env.sandboxMemoryLimit });
|
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([
|
const [context, script] = await Promise.all([
|
||||||
isolate.createContext(),
|
isolate.createContext(),
|
||||||
|
@ -187,7 +187,13 @@ export const monitorRouter = router({
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
.mutation(async ({ input }) => {
|
.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
|
data: workspaceProcedure
|
||||||
.meta(
|
.meta(
|
||||||
|
@ -155,6 +155,7 @@ export function buildSandbox(context: Context, globals: SandboxGlobals = {}) {
|
|||||||
const result = await axios.request(config);
|
const result = await axios.request(config);
|
||||||
|
|
||||||
return makeTransferable({
|
return makeTransferable({
|
||||||
|
headers: { ...result.headers },
|
||||||
data: result.data,
|
data: result.data,
|
||||||
status: result.status,
|
status: result.status,
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user