update: 更新light-code部分的代码模块
This commit is contained in:
@@ -3,6 +3,7 @@ import { app, assistantConfig } from '../app.ts';
|
||||
import './config/index.ts';
|
||||
import './shop-install/index.ts';
|
||||
import './ai/index.ts';
|
||||
import './light-code/index.ts';
|
||||
|
||||
import os from 'node:os';
|
||||
|
||||
|
||||
30
assistant/src/routes/light-code/call.ts
Normal file
30
assistant/src/routes/light-code/call.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { app, assistantConfig } from '../../app.ts'
|
||||
import path from 'path'
|
||||
import { runCode } from '../../module/light-code/run.ts'
|
||||
|
||||
// http://localhost:4005/api/router?path=call
|
||||
app.route({
|
||||
path: 'call',
|
||||
// middleware: ['auth']
|
||||
}).define(async (ctx) => {
|
||||
const filename = ctx.query?.filename || 'root/light-code-demo/demo-router.ts'
|
||||
const data = ctx.query?.data || {}
|
||||
const appsConfigPath = assistantConfig.configPath?.appsDir || '';
|
||||
const testA = path.join(appsConfigPath, filename)
|
||||
try {
|
||||
const resulst = await runCode(testA, data);
|
||||
if (resulst.success) {
|
||||
const callResult = resulst.data;
|
||||
if (callResult.code === 200) ctx.body = callResult.data
|
||||
else {
|
||||
const callError = `调用程序错误: ${callResult.message}`
|
||||
ctx.throw(callResult.code, callError)
|
||||
}
|
||||
} else {
|
||||
ctx.body = `执行脚本错误: ${resulst.error}`
|
||||
}
|
||||
} catch (error) {
|
||||
ctx.body = `执行脚本异常: ${error?.message || error}`
|
||||
}
|
||||
|
||||
}).addTo(app)
|
||||
1
assistant/src/routes/light-code/index.ts
Normal file
1
assistant/src/routes/light-code/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
import './call.ts'
|
||||
Reference in New Issue
Block a user