q-koa 12.9.4 → 12.9.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
@@ -22,7 +22,7 @@ const jwt = require('jsonwebtoken')
22
22
  const verify = util.promisify(jwt.verify)
23
23
  const fsExtra = require('fs-extra')
24
24
  const { getObject, getAppConfig } = require('./file/utils')
25
-
25
+ const { push } = require('./file/plugins/log/service')
26
26
  const restc = require('./restc')
27
27
  const APP_DIR = 'app'
28
28
  const PLUGINS_DIR = 'plugins'
@@ -472,6 +472,10 @@ class APP {
472
472
  await this.initModel(appName)
473
473
  // const models = Object.keys(this.app[appName].model).join(' / ')
474
474
  } catch (e) {
475
+ push({
476
+ appName,
477
+ message: `${appName}数据库连接失败`,
478
+ })
475
479
  console.log(`${appName}数据库连接失败`)
476
480
  console.log(e)
477
481
  throw new Error(e.message)
@@ -1,4 +1,5 @@
1
- const { lodash, getConfig } = require('q-koa')
1
+ const { getConfig } = require('q-koa')
2
+ const lodash = require('lodash')
2
3
  const axios = require('axios')
3
4
 
4
5
  const is_dev = process.env.NODE_ENV !== 'production'
@@ -38,10 +39,17 @@ exports.push = async ({ app, appName = '通知', url, message }) => {
38
39
  return
39
40
  }
40
41
  if (log_push_url) {
41
- const appConfig = getConfig(app)
42
- const { site_name, logo_image, logo_img } = await appConfig.getObject(
43
- 'base'
44
- )
42
+ let site_name = appName
43
+ let logo_image = ''
44
+ let logo_img = ''
45
+ if (app) {
46
+ const appConfig = getConfig(app)
47
+ const res = await appConfig.getObject('base')
48
+
49
+ site_name = res.site_name
50
+ logo_image = res.logo_image
51
+ logo_img = res.logo_img
52
+ }
45
53
 
46
54
  const queryObject = {
47
55
  ...(is_dev ? {} : { url: encodeURIComponent(url) }),
@@ -1963,3 +1963,89 @@ exports.getCommentInfo = async (ctx, _data) => {
1963
1963
  ctx.SUCCESS(result)
1964
1964
  return result
1965
1965
  }
1966
+
1967
+ exports.createActivity = async (ctx, _data) => {
1968
+ const { app, appName } = getAppByCtx(ctx)
1969
+ const { config = 'weixin_mp' } = _data || ctx.request.body
1970
+ const appConfig = getConfig(app)
1971
+ const {
1972
+ app_id,
1973
+ app_secrect,
1974
+ template_type = 'start',
1975
+ limit_number = 5,
1976
+ room_limit = 100,
1977
+ activityId = '',
1978
+ } = await appConfig.getObject(config)
1979
+
1980
+ const weixinMp = new WeixinMp({
1981
+ appid: app_id,
1982
+ secrect: app_secrect,
1983
+ })
1984
+ weixinMp.init()
1985
+
1986
+ const template = {
1987
+ start: '21B034D08C5615B9889CE362BB957B1EE69A584B',
1988
+ present: '666F374D69D16C932E45D7E7D9F10CEF6177F5F5',
1989
+ }
1990
+
1991
+ if (!activityId) {
1992
+ const { activity_id: activityId } = await weixinMp.createActivity()
1993
+ }
1994
+
1995
+ const payLoad = {
1996
+ withShareTicket: true,
1997
+ isUpdatableMessage: true,
1998
+ activityId,
1999
+ templateInfo: {
2000
+ parameterList: [
2001
+ {
2002
+ name: 'member_count',
2003
+ value: limit_number + '',
2004
+ },
2005
+ {
2006
+ name: 'room_limit',
2007
+ value: room_limit + '',
2008
+ },
2009
+ ],
2010
+ templateld: template[template_type],
2011
+ },
2012
+ }
2013
+ ctx.SUCCESS(payLoad)
2014
+ return payLoad
2015
+ }
2016
+
2017
+ exports.setUpdatableMsg = async (ctx, _data) => {
2018
+ const { app, appName } = getAppByCtx(ctx)
2019
+
2020
+ const {
2021
+ config = 'weixin_mp',
2022
+ activity_id,
2023
+ target_state = 0,
2024
+ room_limit,
2025
+ member_count,
2026
+ path,
2027
+ version_type,
2028
+ } = _data || ctx.request.body
2029
+
2030
+ if (!activity_id) throw new ServiceError('?activity_id')
2031
+
2032
+ const appConfig = getConfig(app)
2033
+ const { app_id, app_secrect } = await appConfig.getObject(config)
2034
+ const weixinMp = new WeixinMp({
2035
+ appid: app_id,
2036
+ secrect: app_secrect,
2037
+ })
2038
+ weixinMp.init()
2039
+
2040
+ const result = await weixinMp.setUpdatableMsg({
2041
+ activity_id,
2042
+ target_state,
2043
+ room_limit,
2044
+ member_count,
2045
+ path,
2046
+ version_type,
2047
+ })
2048
+
2049
+ ctx.SUCCESS(result)
2050
+ return result
2051
+ }
@@ -373,14 +373,8 @@ exports.qr_code = async ({
373
373
 
374
374
  return qr_image
375
375
  } else {
376
- const {
377
- accessKeyId,
378
- accessKeySecret,
379
- bucket,
380
- region,
381
- cdn_host,
382
- oss_host,
383
- } = await appConfig.getObject('oss')
376
+ const { accessKeyId, accessKeySecret, bucket, region, cdn_host, oss_host } =
377
+ await appConfig.getObject('oss')
384
378
  if (!(accessKeyId && accessKeySecret && bucket && region)) {
385
379
  throw new Error('没有配置oss设置')
386
380
  }
@@ -1,7 +1,7 @@
1
1
  const util = require('util')
2
2
  const axios = require('axios')
3
3
 
4
- const { lodash } = require('q-koa')
4
+ const { lodash, ServiceError } = require('q-koa')
5
5
  const getAccessTokenUrl =
6
6
  'https://api.weixin.qq.com/cgi-bin/token?grant_type=%s&appid=%s&secret=%s'
7
7
  const getPhoneNumberUrl =
@@ -885,7 +885,7 @@ module.exports = class Singleton {
885
885
  }
886
886
 
887
887
  async setUpdatableMsg(target) {
888
- const {
888
+ let {
889
889
  activity_id,
890
890
  target_state,
891
891
  member_count,
@@ -893,6 +893,16 @@ module.exports = class Singleton {
893
893
  version_type,
894
894
  path,
895
895
  } = target
896
+
897
+ if (target_state === 1) {
898
+ version_type = version_type || 'release'
899
+ path = path || 'pages/index/index'
900
+ room_limit = null
901
+ member_count = null
902
+ } else {
903
+ version_type = ''
904
+ path = ''
905
+ }
896
906
  const access_token = await this.getAccessToken()
897
907
  const url = util.format(setUpdatableMsgUrl, access_token)
898
908
  const postData = {
@@ -927,6 +937,9 @@ module.exports = class Singleton {
927
937
  ].filter(Boolean),
928
938
  },
929
939
  }
940
+ if (!postData.template_info.parameter_list.length) {
941
+ throw new ServiceError('?parameter_list length 0')
942
+ }
930
943
  const result = await axios.post(url, postData).then((res) => res.data)
931
944
  if (result.errcode) {
932
945
  if (result.errcode === 40001) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "12.9.4",
3
+ "version": "12.9.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {