q-koa 7.7.2

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.
Files changed (116) hide show
  1. package/core/app.js +1813 -0
  2. package/core/config.js +124 -0
  3. package/core/file/plugins/administrator/config.js +17 -0
  4. package/core/file/plugins/administrator/controller.js +264 -0
  5. package/core/file/plugins/administrator/model.js +53 -0
  6. package/core/file/plugins/administrator/validate.js +41 -0
  7. package/core/file/plugins/alipay/controller.js +68 -0
  8. package/core/file/plugins/alipay/validate.js +9 -0
  9. package/core/file/plugins/cache/service.js +16 -0
  10. package/core/file/plugins/cloudfunction/config.js +4 -0
  11. package/core/file/plugins/cloudfunction/model.js +15 -0
  12. package/core/file/plugins/common/controller.js +398 -0
  13. package/core/file/plugins/common/validate.js +47 -0
  14. package/core/file/plugins/douyin/config.js +3 -0
  15. package/core/file/plugins/douyin/controller.js +521 -0
  16. package/core/file/plugins/douyin/validate.js +40 -0
  17. package/core/file/plugins/douyin_user/config.js +15 -0
  18. package/core/file/plugins/douyin_user/model.js +72 -0
  19. package/core/file/plugins/good_sku/controller.js +80 -0
  20. package/core/file/plugins/h5_user/config.js +19 -0
  21. package/core/file/plugins/h5_user/model.js +71 -0
  22. package/core/file/plugins/lang/config.js +4 -0
  23. package/core/file/plugins/lang/model.js +15 -0
  24. package/core/file/plugins/language/config.js +5 -0
  25. package/core/file/plugins/language/model.js +54 -0
  26. package/core/file/plugins/log/config.js +25 -0
  27. package/core/file/plugins/log/controller.js +31 -0
  28. package/core/file/plugins/log/model.js +51 -0
  29. package/core/file/plugins/model/config.js +12 -0
  30. package/core/file/plugins/model/controller.js +69 -0
  31. package/core/file/plugins/model/model.js +169 -0
  32. package/core/file/plugins/model/service.js +218 -0
  33. package/core/file/plugins/model/validate.js +42 -0
  34. package/core/file/plugins/model_attributes/config.js +12 -0
  35. package/core/file/plugins/model_attributes/model.js +114 -0
  36. package/core/file/plugins/mp_user/config.js +19 -0
  37. package/core/file/plugins/mp_user/model.js +59 -0
  38. package/core/file/plugins/permission/config.js +15 -0
  39. package/core/file/plugins/permission/model.js +91 -0
  40. package/core/file/plugins/role/config.js +27 -0
  41. package/core/file/plugins/role/controller.js +26 -0
  42. package/core/file/plugins/role/model.js +58 -0
  43. package/core/file/plugins/role_permission/config.js +12 -0
  44. package/core/file/plugins/role_permission/controller.js +27 -0
  45. package/core/file/plugins/role_permission/model.js +24 -0
  46. package/core/file/plugins/routes/config.js +17 -0
  47. package/core/file/plugins/routes/controller.js +153 -0
  48. package/core/file/plugins/routes/model.js +70 -0
  49. package/core/file/plugins/routes/service.js +22 -0
  50. package/core/file/plugins/setting/afterExecute.js +14 -0
  51. package/core/file/plugins/setting/config.js +14 -0
  52. package/core/file/plugins/setting/controller.js +50 -0
  53. package/core/file/plugins/setting/model.js +118 -0
  54. package/core/file/plugins/setting/validate.js +42 -0
  55. package/core/file/plugins/system/controller.js +501 -0
  56. package/core/file/plugins/system/service.js +148 -0
  57. package/core/file/plugins/system/validate.js +40 -0
  58. package/core/file/plugins/todolist/config.js +31 -0
  59. package/core/file/plugins/todolist/model.js +69 -0
  60. package/core/file/plugins/toutiao/controller.js +201 -0
  61. package/core/file/plugins/toutiao_user/config.js +15 -0
  62. package/core/file/plugins/toutiao_user/model.js +66 -0
  63. package/core/file/plugins/user/afterExecute.js +38 -0
  64. package/core/file/plugins/user/config.js +9 -0
  65. package/core/file/plugins/user/controller.js +329 -0
  66. package/core/file/plugins/user/model.js +96 -0
  67. package/core/file/plugins/user/test.js +71 -0
  68. package/core/file/plugins/user/validate.js +44 -0
  69. package/core/file/plugins/video/config.js +3 -0
  70. package/core/file/plugins/video/controller.js +15 -0
  71. package/core/file/plugins/video/validate.js +12 -0
  72. package/core/file/plugins/weixin/config.js +3 -0
  73. package/core/file/plugins/weixin/controller.js +994 -0
  74. package/core/file/plugins/weixin/service.js +105 -0
  75. package/core/file/plugins/weixin/validate.js +111 -0
  76. package/core/file/services/aliSms.js +45 -0
  77. package/core/file/services/alipay.js +123 -0
  78. package/core/file/services/amap.js +95 -0
  79. package/core/file/services/card.js +24 -0
  80. package/core/file/services/config.js +38 -0
  81. package/core/file/services/douyin.js +151 -0
  82. package/core/file/services/email.js +45 -0
  83. package/core/file/services/express.js +37 -0
  84. package/core/file/services/geo.js +71 -0
  85. package/core/file/services/qqVideo.js +64 -0
  86. package/core/file/services/toutiao.js +102 -0
  87. package/core/file/services/weixin.js +79 -0
  88. package/core/file/services/weixinArticle.js +53 -0
  89. package/core/file/services/weixinCrypt.js +34 -0
  90. package/core/file/services/weixinMP.js +435 -0
  91. package/core/file/services/weixinPay.js +35 -0
  92. package/core/file/services/xml.js +33 -0
  93. package/core/file/task/shop/index.js +589 -0
  94. package/core/file/task/shop/static/562e45760a44632de6fa7219bab78cce.png +0 -0
  95. package/core/file/task/shop/static/d7aeaeb6bfd68f71a00a83c0f5548363.png +0 -0
  96. package/core/file/utils/index.js +61 -0
  97. package/core/middlewares.js +120 -0
  98. package/core/restc/.npminstall.done +1 -0
  99. package/core/restc/LICENSE +21 -0
  100. package/core/restc/README.md +48 -0
  101. package/core/restc/faas/index.html +1112 -0
  102. package/core/restc/faas/index.txt +31 -0
  103. package/core/restc/faas/install_production.sh +6 -0
  104. package/core/restc/index.d.ts +7 -0
  105. package/core/restc/index.js +9 -0
  106. package/core/restc/lib/express.js +7 -0
  107. package/core/restc/lib/hapi.js +17 -0
  108. package/core/restc/lib/hapiLegacy.js +15 -0
  109. package/core/restc/lib/index.js +46 -0
  110. package/core/restc/lib/koa.js +9 -0
  111. package/core/restc/lib/koa2.js +9 -0
  112. package/core/restc/lib/utils/gateway.js +51 -0
  113. package/core/restc/package.json +41 -0
  114. package/core/validator.js +15 -0
  115. package/index.js +1 -0
  116. package/package.json +65 -0
@@ -0,0 +1,120 @@
1
+ const bodyParser = require('koa-bodyparser')
2
+ const compress = require('koa-compress')
3
+ const respond = require('koa-respond')
4
+ const koaBody = require('koa-body')
5
+ const xmlParser = require('koa-xml-body')
6
+ const websocket = require('koa-easy-ws')
7
+ const ratelimit = require('koa-ratelimit')
8
+ const { userAgent } = require('koa-useragent')
9
+ const staticFiles = require('koa-static')
10
+ const stringify = require('fast-json-stringify')
11
+ const path = require('path')
12
+
13
+ const rootDirectory = process.cwd()
14
+
15
+ exports.miAgent = () => userAgent
16
+
17
+ exports.miErrors = () => async (ctx, next) => {
18
+ const { url } = ctx
19
+ const appName = url.split('/')[1]
20
+ const app = ctx.app[appName]
21
+ try {
22
+ return await next()
23
+ } catch (e) {
24
+ // app.event.emit('message', {
25
+ // type: 'error',
26
+ // payload: {
27
+ // message: e.message,
28
+ // },
29
+ // });
30
+ const errorData = {
31
+ url: ctx.request.href,
32
+ body: ctx.request.body,
33
+ message: e.message,
34
+ content: e.stack,
35
+ header: ctx.request.header,
36
+ }
37
+ if (app && app.model && app.model.log) {
38
+ app.model.log.upsert(errorData)
39
+ }
40
+
41
+ return ctx.ERROR(e.message || '发生错误了')
42
+ }
43
+ }
44
+
45
+ exports.miStatic = (config) =>
46
+ staticFiles(path.resolve(__dirname, `${rootDirectory}/${config.dir}`))
47
+
48
+ exports.miSend = () => {
49
+ function render(json) {
50
+ this.set('Content-Type', 'application/json')
51
+ this.body = stringify(json)
52
+ }
53
+ return async (ctx, next) => {
54
+ ctx.send = render.bind(ctx)
55
+ await next()
56
+ }
57
+ }
58
+
59
+ exports.miResponse = (methods) =>
60
+ respond({
61
+ // @ts-ignore
62
+ methods,
63
+ })
64
+
65
+ exports.miCors = (arr = [], ip = '192.168.0.1') => async (ctx, next) => {
66
+ ctx.set('Access-Control-Allow-Origin', `${ctx.header.origin || '*'}`)
67
+ ctx.set('Access-Control-Allow-Credentials', true)
68
+ // ctx.set('Access-Control-Allow-Headers', '*');
69
+ ctx.set(
70
+ 'Access-Control-Allow-Headers',
71
+ ` Origin, X-Requested-With, Content-Type, client-type, Accept, ${arr
72
+ .map((item) => `${item}-token`)
73
+ .join(', ')}`
74
+ )
75
+ ctx.set('server-ip', ip)
76
+ ctx.set('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS')
77
+ if (ctx.method === 'OPTIONS') {
78
+ ctx.body = 200
79
+ } else {
80
+ await next()
81
+ }
82
+ }
83
+
84
+ exports.miXmlBody = (config) =>
85
+ xmlParser({
86
+ limit: 1024,
87
+ encoding: 'utf8', // lib will detect it from `content-type`
88
+ xmlOptions: {
89
+ explicitArray: false,
90
+ },
91
+ key: 'xmlBody', // lib will check ctx.request.xmlBody & set parsed data to it.
92
+ onerror: (err) => {
93
+ throw new Error(err.message)
94
+ },
95
+ ...config,
96
+ })
97
+
98
+ exports.miBody = (config) =>
99
+ koaBody({
100
+ multipart: true,
101
+ formLimit: '20mb',
102
+ jsonLimit: '20mb',
103
+ textLimit: '20mb',
104
+ formidable: {
105
+ maxFieldsSize: 20 * 1024 * 1024,
106
+ },
107
+ ...config,
108
+ })
109
+
110
+ exports.miCompress = (config) => compress(config)
111
+
112
+ exports.miBodyParser = (config) => bodyParser(config)
113
+
114
+ exports.miWebsocket = (config) => websocket(config)
115
+
116
+ exports.miLimit = (config) => ratelimit(config)
117
+ // exports.miProxy = () => proxy('/classroom', {
118
+ // target: 'https://ugcbsy.qq.com',
119
+ // changeOrigin: true,
120
+ // });
@@ -0,0 +1 @@
1
+ Sun Sep 29 2019 10:41:01 GMT+0800 (GMT+08:00)
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 ElemeFE
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,48 @@
1
+ <p align="center">
2
+ <img src="/docs/images/logo.svg" alt="restc" width="150" height="150">
3
+ </p>
4
+
5
+ <p align="center">
6
+ <img src="https://img.shields.io/circleci/project/github/ElemeFE/restc.svg" alt="CircleCI (all branches)">
7
+ </p>
8
+
9
+ <p align="center">
10
+ <a href="https://elemefe.github.io/restc/intro/">中文文档</a>
11
+ </p>
12
+
13
+ ## Introduction
14
+
15
+ restc is an HTTP server middleware, aiming to enhance debugging experience on RESTful APIs.
16
+
17
+ It can be easily integrated with popular HTTP frameworks. You will see:
18
+
19
+ - formatted JSON responses in the browser
20
+ - a debug panel with which you can send GET, POST, PUT, PATCH and DELETE requests directly in the browser
21
+
22
+ You can even share a request by sharing its URL directly to others and everything will be automatically filled in the panel.
23
+
24
+ ## Getting Started
25
+
26
+ npm install --save restc
27
+
28
+ Use the middleware
29
+
30
+ ```js
31
+ const restc = require('restc');
32
+ // for express
33
+ app.use(restc.express());
34
+ // for koa
35
+ app.use(restc.koa());
36
+ // ...and koa2
37
+ app.use(restc.koa2());
38
+ // for hapi
39
+ server.register(restc.hapi)
40
+ // for hapi of legacy version
41
+ server.register([{
42
+ register: restc.hapiLegacy
43
+ }], (err) => {
44
+ if (err) {
45
+ throw err
46
+ }
47
+ })
48
+ ```