q-koa 12.4.2 → 12.4.5

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
@@ -50,6 +50,11 @@ const starter = new EventEmitter()
50
50
 
51
51
  const formatPostFunction = (str) => `eval(${str})`
52
52
 
53
+ const runVm = (_str) => {
54
+ return nodeVm.runInNewContext(_str)
55
+ }
56
+
57
+ const memRunVm = _.memoize(runVm)
53
58
  const connectDatabase = (database) => (config) => {
54
59
  if (!database) throw new Error('请配置数据库名称')
55
60
  if (!config.username) throw new Error('请配置数据库账号')
@@ -1001,11 +1006,11 @@ class APP {
1001
1006
  * 如果像user_distribute里有两个user,需要用这个来重新建立关系
1002
1007
  */
1003
1008
  const _str = formatPostFunction(relate)
1004
- nodeVm.runInNewContext(_str)(app[appName])
1009
+ memRunVm(_str)(app[appName])
1005
1010
  // relate.toFunction()(app[appName]);
1006
1011
  }
1007
1012
  const _str = formatPostFunction(include)
1008
- const postInclude = nodeVm.runInNewContext(_str)
1013
+ const postInclude = memRunVm(_str)
1009
1014
  const strInclude = postInclude(app[appName])
1010
1015
  // const postInclude = include.toFunction();
1011
1016
 
@@ -110,9 +110,9 @@ exports.oss_upload = async (ctx) => {
110
110
  let imageData
111
111
  if (ctx.request.files && ctx.request.files.file) {
112
112
  const { file } = ctx.request.files
113
- fileName = `${
114
- String(new Date().getTime()).split('').reverse().join('') + Math.random()
115
- }.${file.name.split('.')[file.name.split('.').length - 1]}`
113
+ fileName = `${String(
114
+ new Date().getYear() + new Date().getMonth() + Math.random()
115
+ )}.${file.name.split('.')[file.name.split('.').length - 1]}`
116
116
  imageData = file.path
117
117
  } else {
118
118
  const { url: imageUrl, filename: imageFileName } = ctx.request.body
@@ -1,4 +1,4 @@
1
- const { lodash } = require('q-koa')
1
+ const { lodash, getConfig } = require('q-koa')
2
2
  const axios = require('axios')
3
3
 
4
4
  const is_dev = process.env.NODE_ENV !== 'production'
@@ -10,9 +10,31 @@ exports.push = async ({ app, appName = '通知', url, message }) => {
10
10
  'https://api.day.app/ieaRfoE3LiPveGbY5qmUwk'
11
11
  )
12
12
  if (log_push_url) {
13
- const logUrl =
14
- `${log_push_url}/${appName}/${encodeURIComponent(message)}` +
15
- (is_dev ? '' : `?url=${encodeURIComponent(url)}`)
13
+ const appConfig = getConfig(app)
14
+ const { site_name, logo_image, logo_img } = await appConfig.getObject(
15
+ 'base'
16
+ )
17
+
18
+ const queryObject = {
19
+ ...(is_dev ? {} : { url: encodeURIComponent(url) }),
20
+ ...(logo_image || logo_img
21
+ ? {
22
+ icon: encodeURIComponent(
23
+ (logo_image || logo_img).replace('http', 'https')
24
+ ),
25
+ }
26
+ : {}),
27
+ }
28
+
29
+ const query = Object.keys(queryObject)
30
+ .map((key) => {
31
+ return `${key}=${queryObject[key]}`
32
+ })
33
+ .join('&')
34
+
35
+ const logUrl = `${log_push_url}/${encodeURIComponent(
36
+ site_name || appName
37
+ )}/${encodeURIComponent(message)}${query ? '?' + query : ''}`
16
38
 
17
39
  axios({
18
40
  url: logUrl,
@@ -2,6 +2,11 @@ const { getConfig, lodash, Sequelize } = require('q-koa')
2
2
  const formatPostFunction = (str) => `eval(${str})`
3
3
  const nodeVm = require('vm')
4
4
  const axios = require('axios')
5
+ const runVm = (_str) => {
6
+ return nodeVm.runInNewContext(_str)
7
+ }
8
+
9
+ const memRunVm = lodash.memoize(runVm)
5
10
 
6
11
  exports.initData = async ({ includes, excludes, app, ctx }) => {
7
12
  const appConfig = getConfig(app)
@@ -86,7 +91,7 @@ exports.initData = async ({ includes, excludes, app, ctx }) => {
86
91
 
87
92
  if (include) {
88
93
  const _str = formatPostFunction(include)
89
- const postInclude = nodeVm.runInNewContext(_str)
94
+ const postInclude = memRunVm(_str)
90
95
  // const postInclude = include.toFunction();
91
96
  if (!Array.isArray(postInclude(app))) {
92
97
  if (process.env.NODE_ENV !== 'production') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "12.4.2",
3
+ "version": "12.4.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {