q-koa 13.8.55 → 13.8.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core/app.js
CHANGED
|
@@ -8,7 +8,6 @@ const Sequelize = require('sequelize')
|
|
|
8
8
|
const redis = require('redis')
|
|
9
9
|
const moment = require('moment')
|
|
10
10
|
const { EventEmitter } = require('events')
|
|
11
|
-
const nodeVm = require('vm')
|
|
12
11
|
const { LRUCache } = require('lru-cache')
|
|
13
12
|
const axios = require('axios')
|
|
14
13
|
|
|
@@ -67,7 +66,7 @@ const starter = new EventEmitter()
|
|
|
67
66
|
const formatPostFunction = (str) => `eval(${str})`
|
|
68
67
|
|
|
69
68
|
const runVm = (_str) => {
|
|
70
|
-
return
|
|
69
|
+
return new Function(`return ${_str}`)()
|
|
71
70
|
}
|
|
72
71
|
|
|
73
72
|
const getLiteral = (str) => {
|
|
@@ -550,106 +550,6 @@ exports.initDataWithCache = exports.initData = async (ctx) => {
|
|
|
550
550
|
return ctx.SUCCESS(result)
|
|
551
551
|
}
|
|
552
552
|
|
|
553
|
-
exports.recentlyError = async (ctx) => {
|
|
554
|
-
// const {
|
|
555
|
-
// app,
|
|
556
|
-
// appName,
|
|
557
|
-
// } = getAppByCtx(ctx);
|
|
558
|
-
|
|
559
|
-
if (ctx.ws) {
|
|
560
|
-
const ws = await ctx.ws()
|
|
561
|
-
const send = (data) => ws.send(JSON.stringify(data))
|
|
562
|
-
ctx.app.on('error', async (err) => {
|
|
563
|
-
console.log(err)
|
|
564
|
-
try {
|
|
565
|
-
send({
|
|
566
|
-
type: 'error',
|
|
567
|
-
payload: err ? err.errorData : {},
|
|
568
|
-
})
|
|
569
|
-
} catch (e) {
|
|
570
|
-
console.log(e)
|
|
571
|
-
}
|
|
572
|
-
})
|
|
573
|
-
} else {
|
|
574
|
-
throw new Error('这是一个websocket url')
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
exports.sandbox = async (ctx) => {
|
|
579
|
-
const code = `
|
|
580
|
-
module.exports = async (callback)=>{
|
|
581
|
-
callback({
|
|
582
|
-
name:1
|
|
583
|
-
})
|
|
584
|
-
}
|
|
585
|
-
`
|
|
586
|
-
// const { code } = ctx.request.body;
|
|
587
|
-
const vm = new VM({
|
|
588
|
-
sandbox: {
|
|
589
|
-
axios,
|
|
590
|
-
module,
|
|
591
|
-
setTimeout,
|
|
592
|
-
sleep: (time) =>
|
|
593
|
-
new Promise((resolve) => setTimeout(resolve, time * 1000)),
|
|
594
|
-
},
|
|
595
|
-
})
|
|
596
|
-
vm.run(code)(ctx.SUCCESS)
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
exports.onlineChat = async (ctx) => {
|
|
600
|
-
if (ctx.ws) {
|
|
601
|
-
const ws = await ctx.ws()
|
|
602
|
-
const send = (data) => ws.send(JSON.stringify(data))
|
|
603
|
-
ws.on('message', async (code) => {
|
|
604
|
-
const vm = new VM({
|
|
605
|
-
sandbox: {
|
|
606
|
-
send: (data) => ws.send(JSON.stringify(data)),
|
|
607
|
-
axios,
|
|
608
|
-
},
|
|
609
|
-
})
|
|
610
|
-
vm.run(code)
|
|
611
|
-
const unhandledRejections = {}
|
|
612
|
-
|
|
613
|
-
process.on('unhandledRejection', (reason) => {
|
|
614
|
-
if (unhandledRejections[reason]) {
|
|
615
|
-
console.log('====?', reason)
|
|
616
|
-
} else {
|
|
617
|
-
send({
|
|
618
|
-
type: 'error',
|
|
619
|
-
payload: `${reason}`,
|
|
620
|
-
})
|
|
621
|
-
unhandledRejections[reason] = true
|
|
622
|
-
}
|
|
623
|
-
})
|
|
624
|
-
})
|
|
625
|
-
} else {
|
|
626
|
-
throw new Error('这是一个websocket url')
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
exports.chat = async (ctx) => {
|
|
631
|
-
const { app } = getAppByCtx(ctx)
|
|
632
|
-
if (ctx.ws) {
|
|
633
|
-
const ws = await ctx.ws()
|
|
634
|
-
const send = (data) => ws.send(JSON.stringify(data))
|
|
635
|
-
ws.on('message', async (payload) => {
|
|
636
|
-
const message = JSON.parse(payload)
|
|
637
|
-
const result = await app.model.ask.create({
|
|
638
|
-
user_id: message.payload.user_id,
|
|
639
|
-
content: message.payload.content,
|
|
640
|
-
is_ask: Boolean(message.payload.user_id),
|
|
641
|
-
})
|
|
642
|
-
|
|
643
|
-
send({
|
|
644
|
-
type: 'message',
|
|
645
|
-
payload: result,
|
|
646
|
-
})
|
|
647
|
-
})
|
|
648
|
-
} else {
|
|
649
|
-
throw new Error('这是一个websocket url')
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
|
|
653
553
|
exports.showModelCount = async (ctx) => {
|
|
654
554
|
const { app, appName } = getAppByCtx(ctx)
|
|
655
555
|
const { is_count = false } = ctx.request.body
|
|
@@ -2,10 +2,9 @@ const lodash = require('lodash')
|
|
|
2
2
|
const { Sequelize } = require('q-koa')
|
|
3
3
|
const { formatLiteralObj, filterFunction } = require('../../utils')
|
|
4
4
|
const formatPostFunction = (str) => `eval(${str})`
|
|
5
|
-
const nodeVm = require('vm')
|
|
6
5
|
const axios = require('axios')
|
|
7
6
|
const runVm = (_str) => {
|
|
8
|
-
return
|
|
7
|
+
return new Function(`return ${_str}`)()
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
const memRunVm = lodash.memoize(runVm)
|