mm_os 1.3.3 → 1.3.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/README.en.md +36 -0
- package/README.md +25 -166
- package/conf.json +3 -0
- package/core/base/index.js +29 -0
- package/core/base/mqtt/index.js +268 -0
- package/core/base/mqtt/lib.js +40 -0
- package/core/base/web/index.js +110 -0
- package/core/com/api/com.json +4 -0
- package/{bin → core}/com/api/config.tpl.json +9 -7
- package/{bin → core}/com/api/drive.js +239 -64
- package/{bin → core}/com/api/index.js +8 -9
- package/{bin → core}/com/api/oauth.js +23 -14
- package/core/com/api/script.js +32 -0
- package/core/com/db/com.json +4 -0
- package/{bin → core}/com/db/drive.js +99 -65
- package/{bin → core}/com/db/index.js +2 -2
- package/core/com/event/com.json +4 -0
- package/{bin → core}/com/event/config.tpl.json +2 -2
- package/core/com/event/drive.js +125 -0
- package/{bin → core}/com/event/index.js +5 -10
- package/core/com/event/script.js +26 -0
- package/core/com/eventer/com.js +450 -0
- package/core/com/eventer/com.json +4 -0
- package/core/com/middleware/com.js +128 -0
- package/core/com/middleware/com.json +4 -0
- package/core/com/middleware/config.tpl.json +8 -0
- package/core/com/middleware/script.js +9 -0
- package/core/com/mqtt/com.json +4 -0
- package/core/com/mqtt/config.tpl.json +12 -0
- package/core/com/mqtt/drive.js +139 -0
- package/core/com/mqtt/index.js +138 -0
- package/core/com/mqtt/script.js +33 -0
- package/core/com/msg/com.js +296 -0
- package/core/com/msg/com.json +4 -0
- package/{bin → core}/com/nav/drive.js +42 -17
- package/{bin → core}/com/nav/index.js +4 -4
- package/core/com/nav/tpl/admin_pc/page_channel.vue +299 -0
- package/core/com/nav/tpl/admin_pc/page_config.vue +279 -0
- package/core/com/nav/tpl/admin_pc/page_config_form.vue +194 -0
- package/core/com/nav/tpl/admin_pc/page_default.vue +287 -0
- package/core/com/nav/tpl/admin_pc/page_form.vue +180 -0
- package/core/com/nav/tpl/admin_pc/page_lang.vue +265 -0
- package/core/com/nav/tpl/admin_pc/page_nav.vue +313 -0
- package/core/com/nav/tpl/admin_pc/page_table.vue +285 -0
- package/core/com/nav/tpl/admin_pc/page_type.vue +313 -0
- package/core/com/nav/tpl/dev_pc/page_channel.vue +253 -0
- package/core/com/nav/tpl/dev_pc/page_config.vue +253 -0
- package/core/com/nav/tpl/dev_pc/page_default.vue +247 -0
- package/core/com/nav/tpl/dev_pc/page_form.vue +162 -0
- package/core/com/nav/tpl/dev_pc/page_nav.vue +253 -0
- package/core/com/nav/tpl/dev_pc/page_table.vue +247 -0
- package/core/com/nav/tpl/dev_pc/page_type.vue +253 -0
- package/{bin/com/nav/tpl/home_phone → core/com/nav/tpl/home_pc}/page_channel.vue +231 -231
- package/{bin/com/nav/tpl/home_phone → core/com/nav/tpl/home_pc}/page_default.vue +231 -231
- package/{bin → core}/com/nav/tpl/home_pc/page_form.vue +9 -9
- package/{bin → core}/com/nav/tpl/home_pc/page_list.vue +231 -231
- package/{bin → core}/com/nav/tpl/home_pc/page_nav.vue +221 -221
- package/{bin/com/nav/tpl/home_phone → core/com/nav/tpl/home_pc}/page_type.vue +231 -231
- package/{bin → core}/com/nav/tpl/home_pc/page_view.vue +8 -8
- package/{bin/com/nav/tpl/home_pc → core/com/nav/tpl/home_phone}/page_channel.vue +231 -231
- package/{bin/com/nav/tpl/home_pc → core/com/nav/tpl/home_phone}/page_default.vue +231 -231
- package/{bin → core}/com/nav/tpl/home_phone/page_form.vue +9 -9
- package/{bin → core}/com/nav/tpl/home_phone/page_list.vue +231 -231
- package/{bin/com/nav/tpl/admin_pc → core/com/nav/tpl/home_phone}/page_nav.vue +236 -220
- package/{bin/com/nav/tpl/home_pc → core/com/nav/tpl/home_phone}/page_type.vue +231 -231
- package/{bin → core}/com/nav/tpl/home_phone/page_view.vue +8 -8
- package/core/com/nav/viewmodel.js +296 -0
- package/{bin → core}/com/param/config.tpl.json +24 -0
- package/{bin → core}/com/param/drive.js +47 -15
- package/core/com/plugin/com.json +4 -0
- package/core/com/plugin/config.tpl.json +20 -0
- package/{bin → core}/com/plugin/drive.js +5 -8
- package/{bin → core}/com/plugin/index.js +11 -56
- package/core/com/socket/README.md +47 -0
- package/core/com/socket/com.json +4 -0
- package/core/com/socket/config.tpl.json +14 -0
- package/{bin → core}/com/socket/drive.js +74 -51
- package/{bin → core}/com/socket/index.js +4 -2
- package/{bin → core}/com/socket/script.js +8 -6
- package/core/com/sql/config.tpl.json +70 -0
- package/{bin → core}/com/sql/drive.js +281 -58
- package/core/com/static/com.json +4 -0
- package/core/com/static/config.tpl.json +20 -0
- package/{bin → core}/com/static/drive.js +6 -4
- package/{bin → core}/com/static/index.js +5 -1
- package/core/com/task/com.json +4 -0
- package/core/com/task/config.tpl.json +24 -0
- package/core/com/task/drive.js +374 -0
- package/{bin → core}/com/task/index.js +14 -20
- package/core/com/task/script.js +37 -0
- package/core/com/timer/com.js +217 -0
- package/core/com/timer/com.json +4 -0
- package/core/com/tpl/com.js +19 -0
- package/core/com/tpl/com.json +4 -0
- package/index.js +161 -740
- package/lib/actions.js +50 -0
- package/lib/app.js +73 -0
- package/lib/base.js +355 -0
- package/lib/com.js +31 -0
- package/lib/game.js +31 -0
- package/lib/ref.js +121 -0
- package/middleware/cors/index.js +57 -0
- package/middleware/cors/middleware.json +7 -0
- package/middleware/mqtt_base/index.js +10 -0
- package/middleware/mqtt_base/middleware.json +8 -0
- package/{waf.js → middleware/waf/index.js} +12 -2
- package/middleware/waf/middleware.json +9 -0
- package/middleware/web_base/index.js +67 -0
- package/middleware/web_base/middleware.json +9 -0
- package/middleware/web_event/index.js +411 -0
- package/middleware/web_event/middleware.json +10 -0
- package/middleware/web_proxy/index.js +24 -0
- package/middleware/web_proxy/middleware.json +9 -0
- package/middleware/web_router/index.js +33 -0
- package/middleware/web_router/middleware.json +10 -0
- package/middleware/web_socket/index.js +21 -0
- package/middleware/web_socket/middleware.json +9 -0
- package/middleware/web_static/index.js +26 -0
- package/middleware/web_static/middleware.json +9 -0
- package/nodemon.json +12 -2
- package/package.json +56 -66
- package/.gitattributes +0 -5
- package/bin/com/README.md +0 -2
- package/bin/com/api/script.js +0 -14
- package/bin/com/cmd/README.md +0 -3
- package/bin/com/cmd/config.tpl.json +0 -41
- package/bin/com/cmd/drive.js +0 -512
- package/bin/com/cmd/index.js +0 -213
- package/bin/com/cmd/old/5w2h.js +0 -54
- package/bin/com/cmd/old/drive.js +0 -423
- package/bin/com/cmd/script.js +0 -11
- package/bin/com/event/drive.js +0 -69
- package/bin/com/event/script.js +0 -12
- package/bin/com/nav/tpl/admin_pc/page_channel.vue +0 -234
- package/bin/com/nav/tpl/admin_pc/page_default.vue +0 -236
- package/bin/com/nav/tpl/admin_pc/page_form.vue +0 -152
- package/bin/com/nav/tpl/admin_pc/page_table.vue +0 -236
- package/bin/com/nav/tpl/admin_pc/page_type.vue +0 -234
- package/bin/com/nav/tpl/home_phone/page_nav.vue +0 -221
- package/bin/com/nav/viewmodel.js +0 -161
- package/bin/com/plugin/config.tpl.json +0 -11
- package/bin/com/socket/config.tpl.json +0 -8
- package/bin/com/sql/config.tpl.json +0 -34
- package/bin/com/static/config.tpl.json +0 -11
- package/bin/com/task/config.tpl.json +0 -13
- package/bin/com/task/drive.js +0 -288
- package/bin/com/task/script.js +0 -38
- package/bin/com.js +0 -74
- package/bin/mm.conf +0 -48
- package/bin/static/404.html +0 -52
- package/bin/static/README.md +0 -1
- package/bin/static/css/font-awesome.min.css +0 -7
- package/bin/static/css/mm_base.css +0 -220
- package/bin/static/css/mm_common.css +0 -518
- package/bin/static/css/mm_component.css +0 -307
- package/bin/static/css/mm_expand.css +0 -634
- package/bin/static/css/mm_theme.css +0 -291
- package/bin/static/css/new_file.css +0 -79
- package/bin/static/css/swiper.min.css +0 -12
- package/bin/static/favicon.ico +0 -0
- package/bin/static/font/FontAwesome.otf +0 -0
- package/bin/static/font/HelveticaNeue.eot +0 -0
- package/bin/static/font/HelveticaNeue.otf +0 -0
- package/bin/static/font/HelveticaNeue.svg +0 -1273
- package/bin/static/font/HelveticaNeue.woff +0 -0
- package/bin/static/font/HelveticaNeue.woff2 +0 -0
- package/bin/static/font/fontawesome-webfont.eot +0 -0
- package/bin/static/font/fontawesome-webfont.svg +0 -2671
- package/bin/static/font/fontawesome-webfont.ttf +0 -0
- package/bin/static/font/fontawesome-webfont.woff +0 -0
- package/bin/static/font/fontawesome-webfont.woff2 +0 -0
- package/bin/static/h5.html +0 -325
- package/bin/static/highlight/highlight.pack.js +0 -2
- package/bin/static/highlight/styles/a11y-dark.css +0 -99
- package/bin/static/highlight/styles/a11y-light.css +0 -99
- package/bin/static/highlight/styles/agate.css +0 -108
- package/bin/static/highlight/styles/an-old-hope.css +0 -89
- package/bin/static/highlight/styles/androidstudio.css +0 -66
- package/bin/static/highlight/styles/arduino-light.css +0 -88
- package/bin/static/highlight/styles/arta.css +0 -73
- package/bin/static/highlight/styles/ascetic.css +0 -45
- package/bin/static/highlight/styles/atelier-cave-dark.css +0 -83
- package/bin/static/highlight/styles/atelier-cave-light.css +0 -85
- package/bin/static/highlight/styles/atelier-dune-dark.css +0 -69
- package/bin/static/highlight/styles/atelier-dune-light.css +0 -69
- package/bin/static/highlight/styles/atelier-estuary-dark.css +0 -84
- package/bin/static/highlight/styles/atelier-estuary-light.css +0 -84
- package/bin/static/highlight/styles/atelier-forest-dark.css +0 -69
- package/bin/static/highlight/styles/atelier-forest-light.css +0 -69
- package/bin/static/highlight/styles/atelier-heath-dark.css +0 -69
- package/bin/static/highlight/styles/atelier-heath-light.css +0 -69
- package/bin/static/highlight/styles/atelier-lakeside-dark.css +0 -69
- package/bin/static/highlight/styles/atelier-lakeside-light.css +0 -69
- package/bin/static/highlight/styles/atelier-plateau-dark.css +0 -84
- package/bin/static/highlight/styles/atelier-plateau-light.css +0 -84
- package/bin/static/highlight/styles/atelier-savanna-dark.css +0 -84
- package/bin/static/highlight/styles/atelier-savanna-light.css +0 -84
- package/bin/static/highlight/styles/atelier-seaside-dark.css +0 -69
- package/bin/static/highlight/styles/atelier-seaside-light.css +0 -69
- package/bin/static/highlight/styles/atelier-sulphurpool-dark.css +0 -69
- package/bin/static/highlight/styles/atelier-sulphurpool-light.css +0 -69
- package/bin/static/highlight/styles/atom-one-dark-reasonable.css +0 -77
- package/bin/static/highlight/styles/atom-one-dark.css +0 -96
- package/bin/static/highlight/styles/atom-one-light.css +0 -96
- package/bin/static/highlight/styles/brown-paper.css +0 -64
- package/bin/static/highlight/styles/brown-papersq.png +0 -0
- package/bin/static/highlight/styles/codepen-embed.css +0 -60
- package/bin/static/highlight/styles/color-brewer.css +0 -71
- package/bin/static/highlight/styles/darcula.css +0 -77
- package/bin/static/highlight/styles/dark.css +0 -63
- package/bin/static/highlight/styles/darkula.css +0 -6
- package/bin/static/highlight/styles/default.css +0 -99
- package/bin/static/highlight/styles/docco.css +0 -97
- package/bin/static/highlight/styles/dracula.css +0 -76
- package/bin/static/highlight/styles/far.css +0 -71
- package/bin/static/highlight/styles/foundation.css +0 -88
- package/bin/static/highlight/styles/github-gist.css +0 -79
- package/bin/static/highlight/styles/github.css +0 -99
- package/bin/static/highlight/styles/gml.css +0 -78
- package/bin/static/highlight/styles/googlecode.css +0 -89
- package/bin/static/highlight/styles/grayscale.css +0 -101
- package/bin/static/highlight/styles/gruvbox-dark.css +0 -108
- package/bin/static/highlight/styles/gruvbox-light.css +0 -108
- package/bin/static/highlight/styles/hopscotch.css +0 -83
- package/bin/static/highlight/styles/hybrid.css +0 -102
- package/bin/static/highlight/styles/idea.css +0 -97
- package/bin/static/highlight/styles/ir-black.css +0 -73
- package/bin/static/highlight/styles/isbl-editor-dark.css +0 -112
- package/bin/static/highlight/styles/isbl-editor-light.css +0 -112
- package/bin/static/highlight/styles/kimbie.dark.css +0 -74
- package/bin/static/highlight/styles/kimbie.light.css +0 -74
- package/bin/static/highlight/styles/lightfair.css +0 -87
- package/bin/static/highlight/styles/magula.css +0 -70
- package/bin/static/highlight/styles/mono-blue.css +0 -59
- package/bin/static/highlight/styles/monokai-sublime.css +0 -83
- package/bin/static/highlight/styles/monokai.css +0 -70
- package/bin/static/highlight/styles/nord.css +0 -309
- package/bin/static/highlight/styles/obsidian.css +0 -88
- package/bin/static/highlight/styles/ocean.css +0 -74
- package/bin/static/highlight/styles/paraiso-dark.css +0 -72
- package/bin/static/highlight/styles/paraiso-light.css +0 -72
- package/bin/static/highlight/styles/pojoaque.css +0 -83
- package/bin/static/highlight/styles/pojoaque.jpg +0 -0
- package/bin/static/highlight/styles/purebasic.css +0 -96
- package/bin/static/highlight/styles/qtcreator_dark.css +0 -83
- package/bin/static/highlight/styles/qtcreator_light.css +0 -83
- package/bin/static/highlight/styles/railscasts.css +0 -106
- package/bin/static/highlight/styles/rainbow.css +0 -85
- package/bin/static/highlight/styles/routeros.css +0 -108
- package/bin/static/highlight/styles/school-book.css +0 -69
- package/bin/static/highlight/styles/school-book.png +0 -0
- package/bin/static/highlight/styles/shades-of-purple.css +0 -97
- package/bin/static/highlight/styles/solarized-dark.css +0 -84
- package/bin/static/highlight/styles/solarized-light.css +0 -84
- package/bin/static/highlight/styles/sunburst.css +0 -102
- package/bin/static/highlight/styles/tomorrow-night-blue.css +0 -75
- package/bin/static/highlight/styles/tomorrow-night-bright.css +0 -74
- package/bin/static/highlight/styles/tomorrow-night-eighties.css +0 -74
- package/bin/static/highlight/styles/tomorrow-night.css +0 -75
- package/bin/static/highlight/styles/tomorrow.css +0 -72
- package/bin/static/highlight/styles/vs.css +0 -68
- package/bin/static/highlight/styles/vs2015.css +0 -115
- package/bin/static/highlight/styles/xcode.css +0 -104
- package/bin/static/highlight/styles/xt256.css +0 -92
- package/bin/static/highlight/styles/zenburn.css +0 -80
- package/bin/static/highlight/vue-highlight.js +0 -29
- package/bin/static/ifame.html +0 -24
- package/bin/static/img/add.png +0 -0
- package/bin/static/img/avatar.png +0 -0
- package/bin/static/img/banner_2.png +0 -0
- package/bin/static/img/default.png +0 -0
- package/bin/static/img/loading.svg +0 -1
- package/bin/static/img/logo.png +0 -0
- package/bin/static/img/logo1.png +0 -0
- package/bin/static/img/logo_gray.png +0 -0
- package/bin/static/img/logo_round.png +0 -0
- package/bin/static/img/mm.ico +0 -0
- package/bin/static/img/mm.jpg +0 -0
- package/bin/static/img/select.png +0 -0
- package/bin/static/img/web.png +0 -0
- package/bin/static/index.html +0 -12
- package/bin/static/js/clipboard.min.js +0 -257
- package/bin/static/js/css.min.js +0 -1
- package/bin/static/js/echarts.js +0 -22
- package/bin/static/js/html5.min.js +0 -1
- package/bin/static/js/jquery.lazyload.min.js +0 -2
- package/bin/static/js/jquery.min.js +0 -4189
- package/bin/static/js/jquery.scrollstop.min.js +0 -2
- package/bin/static/js/mm-requirejs-vue.js +0 -283
- package/bin/static/js/mm_check.js +0 -490
- package/bin/static/js/mm_flexble.js +0 -112
- package/bin/static/js/mm_picker.js +0 -1417
- package/bin/static/js/mm_pinyinlite.js +0 -873
- package/bin/static/js/mm_sdk.js +0 -2841
- package/bin/static/js/mm_ui_expand.js +0 -468
- package/bin/static/js/mm_vue.js +0 -376
- package/bin/static/js/mm_vue_ui.js +0 -2375
- package/bin/static/js/mm_websocket.js +0 -145
- package/bin/static/js/require.js +0 -5
- package/bin/static/js/sortable.min.js +0 -3
- package/bin/static/js/swiper.min.js +0 -13
- package/bin/static/js/text.min.js +0 -1
- package/bin/static/js/vue-router.min.js +0 -6
- package/bin/static/js/vue.js +0 -12338
- package/bin/static/js/vuedraggable.min.js +0 -2
- package/bin/static/js/vuex.min.js +0 -6
- package/bin/static/src/components/bar/mm_action.vue +0 -19
- package/bin/static/src/components/bar/mm_buy.vue +0 -19
- package/bin/static/src/components/bar/mm_chat.vue +0 -18
- package/bin/static/src/components/bar/mm_count.vue +0 -18
- package/bin/static/src/components/bar/mm_filter.vue +0 -18
- package/bin/static/src/components/bar/mm_search.vue +0 -18
- package/bin/static/src/components/bar/mm_sort.vue +0 -18
- package/bin/static/src/components/bar/mm_tag.vue +0 -18
- package/bin/static/src/components/bar/mm_title.vue +0 -19
- package/bin/static/src/components/content/mm_pre.vue +0 -70
- package/bin/static/src/components/expand/mm_drag.vue +0 -39
- package/bin/static/src/components/item/mm_article.vue +0 -115
- package/bin/static/src/components/item/mm_base.vue +0 -26
- package/bin/static/src/components/item/mm_contact.vue +0 -25
- package/bin/static/src/components/item/mm_goods.vue +0 -23
- package/bin/static/src/components/item/mm_img.vue +0 -21
- package/bin/static/src/components/item/mm_media.vue +0 -18
- package/bin/static/src/components/item/mm_message.vue +0 -18
- package/bin/static/src/components/item/mm_music.vue +0 -95
- package/bin/static/src/components/item/mm_news.vue +0 -22
- package/bin/static/src/components/item/mm_number.vue +0 -26
- package/bin/static/src/components/item/mm_question.vue +0 -35
- package/bin/static/src/components/item/mm_user.vue +0 -22
- package/bin/static/src/components/item/mm_video.vue +0 -95
- package/bin/static/src/components/slide/mm_slide_card.vue +0 -64
- package/bin/static/src/components/slide/mm_slide_img.vue +0 -47
- package/bin/static/src/components/slide/mm_slide_page.vue +0 -8
- package/bin/static/src/components/slide/mm_slide_text.vue +0 -54
- package/bin/static/src/main.js +0 -84
- package/bin/static/src/mixins/form.js +0 -223
- package/bin/static/src/mixins/item.js +0 -242
- package/bin/static/src/mixins/list.js +0 -244
- package/bin/static/src/mixins/page.js +0 -1011
- package/bin/static/src/mm_component.js +0 -74
- package/bin/static/src/router.js +0 -72
- package/bin/static/src/store/user.js +0 -75
- package/bin/static/src/store/web.js +0 -50
- package/bin/static/user/1/number_info.xlsx +0 -0
- package/bin/static/w3c.html +0 -94
- package/init.js +0 -55
- package/update.md +0 -1
- /package/{bin → core}/com/api/README.md +0 -0
- /package/{bin → core}/com/api/rpc.js +0 -0
- /package/{bin → core}/com/db/README.md +0 -0
- /package/{bin → core}/com/event/README.md +0 -0
- /package/{bin/com/socket → core/com/mqtt}/README.md +0 -0
- /package/{bin → core}/com/nav/README.md +0 -0
- /package/{bin → core}/com/nav/config.tpl.json +0 -0
- /package/{bin → core}/com/param/README.md +0 -0
- /package/{bin → core}/com/param/index.js +0 -0
- /package/{bin → core}/com/param/script.js +0 -0
- /package/{bin → core}/com/param/test.js +0 -0
- /package/{bin → core}/com/plugin/README.md +0 -0
- /package/{bin → core}/com/plugin/script.js +0 -0
- /package/{bin → core}/com/sql/README.md +0 -0
- /package/{bin → core}/com/sql/index.js +0 -0
- /package/{bin → core}/com/sql/script.js +0 -0
- /package/{bin → core}/com/static/README.md +0 -0
- /package/{bin → core}/com/static/script.js +0 -0
- /package/{bin → core}/com/task/README.md +0 -0
- /package/{bin/rps.bat → rps.bat} +0 -0
- /package/{bin/tps.bat → tps.bat} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
// 路由路径
|
|
3
|
-
"path": "
|
|
3
|
+
"path": "{path}",
|
|
4
4
|
// 名称, 用于动态增删改API配置
|
|
5
|
-
"name": "
|
|
5
|
+
"name": "{name}",
|
|
6
6
|
// 标题, 用于开发文档显示
|
|
7
7
|
"title": "示例接口",
|
|
8
8
|
// 描述, 用于介绍该路由的作用
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
// 开放域, 如果域未开放, 则只有特定的协议头才能访问该API, 同时API文档不接见
|
|
15
15
|
"scope": true,
|
|
16
16
|
// 缓存时长, 单位: 分钟。使用缓存后, 二次访问API直接从缓存读取, 不重复执行业务脚本
|
|
17
|
-
"cache":
|
|
17
|
+
"cache": 0,
|
|
18
|
+
// 是否启用
|
|
19
|
+
"state": 1,
|
|
18
20
|
// 是否客户端缓存, 使用客户端则不再访问服务器, 直接从浏览器中拿; 使用服务端缓存则会访问服务器
|
|
19
21
|
"client_cache": false,
|
|
20
22
|
// SQL配置路径, 用于将请求参数拼接成SQL, 实现比较复杂的查询
|
|
@@ -31,9 +33,9 @@
|
|
|
31
33
|
"gm": 0,
|
|
32
34
|
// 商户/第三方权限级别, 如果小于该值, 则无法访问, 0为不限制
|
|
33
35
|
"mc": 0,
|
|
34
|
-
// 用户组,
|
|
35
|
-
"user_group": [
|
|
36
|
-
// 管理组,
|
|
37
|
-
"user_admin": [
|
|
36
|
+
// 用户组, 允许访问该接口的普通用户群体, 传ID数组,例如: [1,5]
|
|
37
|
+
"user_group": [],
|
|
38
|
+
// 管理组, 允许访问该接口的管理员群体, 传ID数组,例如: [1,5]
|
|
39
|
+
"user_admin": []
|
|
38
40
|
}
|
|
39
41
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
1
3
|
const Item = require('mm_machine').Item;
|
|
2
4
|
const Param = require('../param/drive.js'); // 是MM自带的参数机制,可以不使用
|
|
3
5
|
const Sql = require('../sql/drive.js'); // 是MM自带的参数机制,可以不使用
|
|
4
6
|
const Oauth = require('./oauth.js'); // 是MM自带的身份验证机制,基于Oauth2.0,可以不使用
|
|
5
7
|
const Ret = require('mm_ret').Ret;
|
|
6
|
-
const CacheBase = require('mm_cachebase');
|
|
7
8
|
|
|
8
9
|
if (!$.dict) {
|
|
9
10
|
if (!$.dict.session_id) {
|
|
@@ -11,9 +12,8 @@ if (!$.dict) {
|
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
15
|
+
var dir = '/app/sys/static/doc/';
|
|
16
|
+
var url_path = "/sys/doc/";
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Api接口驱动类
|
|
@@ -30,9 +30,6 @@ class Drive extends Item {
|
|
|
30
30
|
super(dir, __dirname);
|
|
31
31
|
this.default_file = "./api.json";
|
|
32
32
|
|
|
33
|
-
// 开关,开启可使用接口
|
|
34
|
-
this.onOff = true;
|
|
35
|
-
|
|
36
33
|
// oauth身份验证配置 + 函数
|
|
37
34
|
this.oauth;
|
|
38
35
|
// param参数配置 + 函数
|
|
@@ -42,8 +39,10 @@ class Drive extends Item {
|
|
|
42
39
|
/* 通用项 */
|
|
43
40
|
// 配置参数
|
|
44
41
|
this.config = {
|
|
45
|
-
// 名称, 由中英文和下“_”组成,
|
|
42
|
+
// 名称, 由中英文和下“_”组成, 用于修改或卸载 例如: demo
|
|
46
43
|
"name": "",
|
|
44
|
+
// 状态 0未启用,1启用
|
|
45
|
+
"state": 1,
|
|
47
46
|
// 标题, 介绍接口作用
|
|
48
47
|
"title": "示例接口",
|
|
49
48
|
// 描述, 用于描述该接口有什么用的
|
|
@@ -61,7 +60,7 @@ class Drive extends Item {
|
|
|
61
60
|
// Rpc接口文件路径
|
|
62
61
|
"rpc_file": "",
|
|
63
62
|
// 请求方式, POST或GET, 为空或ALL表示都可以
|
|
64
|
-
"method": "
|
|
63
|
+
"method": "ALL",
|
|
65
64
|
// 缓存时长 (单位:秒) 默认:60秒,建议600秒
|
|
66
65
|
"cache": 0,
|
|
67
66
|
// 是否用客户端缓存,即 http 304 状态
|
|
@@ -89,9 +88,8 @@ class Drive extends Item {
|
|
|
89
88
|
/**
|
|
90
89
|
* 定义rpc 方法
|
|
91
90
|
*/
|
|
92
|
-
this.methods = {
|
|
91
|
+
this.methods = {};
|
|
93
92
|
|
|
94
|
-
};
|
|
95
93
|
/**
|
|
96
94
|
* 定义当前RPC文件路径
|
|
97
95
|
*/
|
|
@@ -99,6 +97,46 @@ class Drive extends Item {
|
|
|
99
97
|
}
|
|
100
98
|
}
|
|
101
99
|
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 新建配置
|
|
103
|
+
* @param {String} 文件
|
|
104
|
+
*/
|
|
105
|
+
Drive.prototype.new_config = function(file) {
|
|
106
|
+
var fl = __dirname + "/config.tpl.json";
|
|
107
|
+
if (fl.hasFile()) {
|
|
108
|
+
var text = fl.loadText();
|
|
109
|
+
if (text) {
|
|
110
|
+
var l = $.slash;
|
|
111
|
+
var arr = file.split(l);
|
|
112
|
+
arr = arr.slice(arr.indexOf('app'));
|
|
113
|
+
var app_name = arr[1];
|
|
114
|
+
var name = arr[arr.length - 2];
|
|
115
|
+
var api_name = arr[arr.length - 3];
|
|
116
|
+
var scope = api_name.replace('_manage', '').replace('_client', '').replace('api_', '');
|
|
117
|
+
if (api_name === "api_client") {
|
|
118
|
+
text = text.replaceAll('{path}', `/api/${name}`);
|
|
119
|
+
text = text.replaceAll('{name}', `${scope}_${name}`);
|
|
120
|
+
} else if (api_name === "api_manage") {
|
|
121
|
+
text = text.replaceAll('{path}', `/apis/${name}`);
|
|
122
|
+
text = text.replaceAll('{name}', `${scope}_${name}_manage`);
|
|
123
|
+
} else if (api_name.indexOf('_manage') !== -1) {
|
|
124
|
+
text = text.replaceAll('{path}', `/apis/${scope}/${name}`);
|
|
125
|
+
text = text.replaceAll('{name}', `${scope}_${name}_manage`);
|
|
126
|
+
} else if (api_name.indexOf('_client') !== -1) {
|
|
127
|
+
text = text.replaceAll('{path}', `/api/${scope}/${name}`);
|
|
128
|
+
text = text.replaceAll('{name}', `${scope}_${name}`);
|
|
129
|
+
} else {
|
|
130
|
+
text = text.replaceAll('{path}', `/api/${scope}/${name}`);
|
|
131
|
+
text = text.replaceAll('{name}', `${scope}_${name}`);
|
|
132
|
+
}
|
|
133
|
+
text = text.replaceAll('{0}', name);
|
|
134
|
+
file.saveText(text);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
|
|
102
140
|
/**
|
|
103
141
|
* 加载完成后执行
|
|
104
142
|
*/
|
|
@@ -245,8 +283,7 @@ Drive.prototype.loadRPC = async function(file_path) {
|
|
|
245
283
|
await this.unloadRPC(this.rpc_file_now);
|
|
246
284
|
var f = require(p);
|
|
247
285
|
this.methods = f(this);
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
286
|
+
} else {
|
|
250
287
|
var fl = this.dir_base + "/rpc.js";
|
|
251
288
|
fl.copyFile(p);
|
|
252
289
|
var f = require(p);
|
|
@@ -281,7 +318,137 @@ Drive.prototype.loadOauth = function() {
|
|
|
281
318
|
}
|
|
282
319
|
};
|
|
283
320
|
|
|
321
|
+
/**
|
|
322
|
+
* 保存文件
|
|
323
|
+
* @param {Object} files 上传的文件
|
|
324
|
+
*/
|
|
325
|
+
Drive.prototype.save_file = function(files) {
|
|
326
|
+
var file;
|
|
327
|
+
var url;
|
|
328
|
+
if (files.file) {
|
|
329
|
+
var f = files.file;
|
|
330
|
+
// 创建可读流
|
|
331
|
+
const readStream = fs.createReadStream(f.path);
|
|
332
|
+
var stamp = Date.now();
|
|
333
|
+
var name = f.name;
|
|
334
|
+
file = path.join($.runPath, dir, name);
|
|
335
|
+
const fileDir = path.join($.runPath, dir);
|
|
336
|
+
if (!fs.existsSync(fileDir)) {
|
|
337
|
+
fs.mkdirSync(fileDir, err => {
|
|
338
|
+
$.log.error('创建失败', err);
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
// 创建写入流
|
|
342
|
+
try {
|
|
343
|
+
const writeStream = fs.createWriteStream(file);
|
|
344
|
+
readStream.pipe(writeStream);
|
|
345
|
+
// writeStream.close();
|
|
346
|
+
url = url_path + name;
|
|
347
|
+
} catch (err) {
|
|
348
|
+
$.log.error('保存文件失败', err);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return {
|
|
352
|
+
file,
|
|
353
|
+
url
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
|
|
284
357
|
/* 回调函数集 */
|
|
358
|
+
$.get_state = async function(db, token) {
|
|
359
|
+
var db1 = db.new("user_state", "user_id");
|
|
360
|
+
var state = await db1.getObj({
|
|
361
|
+
token
|
|
362
|
+
});
|
|
363
|
+
if (!state) {
|
|
364
|
+
return null
|
|
365
|
+
}
|
|
366
|
+
var now = new Date();
|
|
367
|
+
if (state.time_sign.interval(now, 'day') <= 30) {
|
|
368
|
+
db.table = "user_account";
|
|
369
|
+
var user = await db.getObj({
|
|
370
|
+
user_id: state.user_id
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
o = Object.assign({}, user);
|
|
374
|
+
o.password_pay = o.password_pay ? "******" : "";
|
|
375
|
+
o.password = o.password ? "******" : "";
|
|
376
|
+
delete o.salt;
|
|
377
|
+
delete o.time_create;
|
|
378
|
+
return { state, user: o };
|
|
379
|
+
} else {
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* 获取登录态
|
|
386
|
+
* @param {Object} ctx 请求上下文
|
|
387
|
+
* @param {Object} db 数据管理器
|
|
388
|
+
* @return {Object} 执行结果
|
|
389
|
+
*/
|
|
390
|
+
Drive.prototype.get_state = async function(ctx, db) {
|
|
391
|
+
var o;
|
|
392
|
+
// 获取请求参数
|
|
393
|
+
var u = ctx.session.user;
|
|
394
|
+
if (u) {
|
|
395
|
+
o = Object.assign({}, u);
|
|
396
|
+
o.token = ctx.session.uuid;
|
|
397
|
+
} else {
|
|
398
|
+
var token = ctx.headers[$.dict.token];
|
|
399
|
+
if (token) {
|
|
400
|
+
u = await $.cache.get($.dict.session_id + '_' + token);
|
|
401
|
+
if (u) {
|
|
402
|
+
var type = typeof(u);
|
|
403
|
+
if (type === "string") {
|
|
404
|
+
o = Object.assign({}, u.toJson());
|
|
405
|
+
} else {
|
|
406
|
+
if (Object.keys(u).length > 0) {
|
|
407
|
+
o = Object.assign({}, u);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
if (!o.user_id) {
|
|
411
|
+
var obj = await $.get_state(db, token);
|
|
412
|
+
if (obj) {
|
|
413
|
+
ctx.session.user = obj.user;
|
|
414
|
+
o.token = ctx.session.uuid;
|
|
415
|
+
obj.state.token = o.token;
|
|
416
|
+
}
|
|
417
|
+
} else {
|
|
418
|
+
o.token = token;
|
|
419
|
+
}
|
|
420
|
+
} else {
|
|
421
|
+
var obj = await $.get_state(db, token);
|
|
422
|
+
if (obj) {
|
|
423
|
+
o = Object.assign({}, obj.user);
|
|
424
|
+
ctx.session.user = obj.user;
|
|
425
|
+
o.token = ctx.session.uuid;
|
|
426
|
+
obj.state.token = o.token;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
if (o) {
|
|
432
|
+
o.password_pay = o.password_pay ? "******" : "";
|
|
433
|
+
o.password = o.password ? "******" : "";
|
|
434
|
+
delete o.salt;
|
|
435
|
+
delete o.time_create;
|
|
436
|
+
}
|
|
437
|
+
return o;
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* 获取登录态
|
|
442
|
+
* @param {Object} ctx 请求上下文
|
|
443
|
+
* @param {Object} db 数据管理器
|
|
444
|
+
* @return {Object} 执行结果
|
|
445
|
+
*/
|
|
446
|
+
Drive.prototype.before = async function(ctx, db) {
|
|
447
|
+
if (this.config.oauth && this.config.oauth.signIn) {
|
|
448
|
+
db.user = await this.get_state(ctx, db);
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
|
|
285
452
|
/**
|
|
286
453
|
* 主要函数
|
|
287
454
|
* @param {Object} ctx 请求上下文
|
|
@@ -291,9 +458,11 @@ Drive.prototype.loadOauth = function() {
|
|
|
291
458
|
Drive.prototype.main = async function(ctx, db) {
|
|
292
459
|
if (this.sql) {
|
|
293
460
|
var req = ctx.request;
|
|
294
|
-
|
|
295
|
-
if (
|
|
296
|
-
|
|
461
|
+
// 获取文件
|
|
462
|
+
if (req.files) {
|
|
463
|
+
var fobj = this.save_file(req.files);
|
|
464
|
+
req.body.file = fobj.file;
|
|
465
|
+
req.body.url = fobj.url;
|
|
297
466
|
}
|
|
298
467
|
var ret = await this.sql.run(req.query, req.body, db);
|
|
299
468
|
return ret;
|
|
@@ -317,12 +486,16 @@ Drive.prototype.run = async function(ctx, db) {
|
|
|
317
486
|
if (md !== req.method && md !== "ALL") {
|
|
318
487
|
return null;
|
|
319
488
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
489
|
+
|
|
490
|
+
await this.before(ctx, db);
|
|
491
|
+
var ret = await this.check(ctx, db);
|
|
492
|
+
if (!ret) {
|
|
493
|
+
try {
|
|
494
|
+
ret = await this.main(ctx, db);
|
|
495
|
+
} catch (err) {
|
|
496
|
+
$.log.error("脚本文件错误", req.path, err);
|
|
497
|
+
ret = $.ret.error(10000, "脚本文件错误:" + err.toString());
|
|
498
|
+
}
|
|
326
499
|
}
|
|
327
500
|
var res = ctx.response;
|
|
328
501
|
body = this.body(ret, res, req.type);
|
|
@@ -337,31 +510,29 @@ Drive.prototype.run = async function(ctx, db) {
|
|
|
337
510
|
* @return {String} 响应内容
|
|
338
511
|
*/
|
|
339
512
|
Drive.prototype.getCache = async function(ctx) {
|
|
340
|
-
var
|
|
341
|
-
if (
|
|
342
|
-
var
|
|
343
|
-
if (
|
|
344
|
-
var
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
513
|
+
var cg = this.config;
|
|
514
|
+
if (cg.cache) {
|
|
515
|
+
var req = ctx.request;
|
|
516
|
+
if (cg.client_cache) {
|
|
517
|
+
var etag = req.headers['if-none-match'];
|
|
518
|
+
if (etag) {
|
|
519
|
+
var stamp = Number(etag.replace('"', '').replace('"', ''));
|
|
520
|
+
var cha = stamp * 1000 - Date.parse(new Date());
|
|
521
|
+
if (cha > 0) {
|
|
522
|
+
ctx.response.status = 304;
|
|
523
|
+
return ' ';
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
} else {
|
|
527
|
+
var data = await $.cache.get("api_" + req.url);
|
|
528
|
+
if (data) {
|
|
529
|
+
var obj = JSON.parse(data);
|
|
530
|
+
ctx.response.type = obj.type;
|
|
531
|
+
return obj.body;
|
|
349
532
|
}
|
|
350
533
|
}
|
|
351
534
|
}
|
|
352
|
-
|
|
353
|
-
var id = ctx.cookies.get($.dict.session_id);
|
|
354
|
-
if (id) {
|
|
355
|
-
userID = id;
|
|
356
|
-
}
|
|
357
|
-
var data = await $.cache.get("api_" + userID + ":" + req.url);
|
|
358
|
-
if (data) {
|
|
359
|
-
var obj = JSON.parse(data);
|
|
360
|
-
ctx.response.type = obj.type;
|
|
361
|
-
return obj.body;
|
|
362
|
-
} else {
|
|
363
|
-
return null;
|
|
364
|
-
}
|
|
535
|
+
return null;
|
|
365
536
|
};
|
|
366
537
|
|
|
367
538
|
/**
|
|
@@ -373,20 +544,16 @@ Drive.prototype.setCache = async function(ctx, body) {
|
|
|
373
544
|
var cg = this.config;
|
|
374
545
|
if (cg.cache && ctx.method === 'GET') {
|
|
375
546
|
if (cg.client_cache) {
|
|
376
|
-
|
|
377
|
-
ctx.
|
|
547
|
+
var age = cg.cache * 60;
|
|
548
|
+
ctx.set('Cache-Control', 'max-age=' + age);
|
|
549
|
+
ctx.etag = Date.parse(new Date()) / 1000 + age;
|
|
378
550
|
return " ";
|
|
379
551
|
} else {
|
|
380
552
|
var req = ctx.request;
|
|
381
553
|
var o = {};
|
|
382
554
|
o.body = body;
|
|
383
555
|
o.type = ctx.response.type;
|
|
384
|
-
|
|
385
|
-
var id = ctx.cookies.get($.dict.session_id);
|
|
386
|
-
if (id) {
|
|
387
|
-
userID = id;
|
|
388
|
-
}
|
|
389
|
-
$.cache.set("api_" + userID + ":" + req.url, JSON.stringify(o), cg.cache);
|
|
556
|
+
$.cache.set("api_" + req.url, JSON.stringify(o), cg.cache * 60);
|
|
390
557
|
}
|
|
391
558
|
}
|
|
392
559
|
};
|
|
@@ -459,9 +626,15 @@ Drive.prototype.body = function(ret, res, t) {
|
|
|
459
626
|
*/
|
|
460
627
|
Drive.prototype.checkParam = function(query, body, method) {
|
|
461
628
|
if (this.param) {
|
|
462
|
-
var
|
|
463
|
-
if (
|
|
464
|
-
|
|
629
|
+
var msg = this.param.check(query, body, method);
|
|
630
|
+
if (msg) {
|
|
631
|
+
var code;
|
|
632
|
+
if (msg.indexOf("必须") !== -1 || msg.indexOf("为空") !== -1) {
|
|
633
|
+
code = 30001;
|
|
634
|
+
} else {
|
|
635
|
+
code = 30002;
|
|
636
|
+
}
|
|
637
|
+
return $.ret.error(code, msg);
|
|
465
638
|
}
|
|
466
639
|
}
|
|
467
640
|
return null;
|
|
@@ -480,6 +653,11 @@ Drive.prototype.check = async function(ctx) {
|
|
|
480
653
|
}
|
|
481
654
|
if (!error) {
|
|
482
655
|
error = await this.checkOauth(ctx);
|
|
656
|
+
if (error) {
|
|
657
|
+
error = {
|
|
658
|
+
error
|
|
659
|
+
}
|
|
660
|
+
}
|
|
483
661
|
}
|
|
484
662
|
return error;
|
|
485
663
|
};
|
|
@@ -510,14 +688,12 @@ Drive.prototype.runRPC = async function(db, method, query, body) {
|
|
|
510
688
|
var func = this.methods[method];
|
|
511
689
|
var ret = {};
|
|
512
690
|
try {
|
|
513
|
-
if(func){
|
|
691
|
+
if (func) {
|
|
514
692
|
ret = this.checkParam(query, body, method);
|
|
515
|
-
if(!ret)
|
|
516
|
-
{
|
|
693
|
+
if (!ret) {
|
|
517
694
|
ret = await func(db, query, body);
|
|
518
695
|
}
|
|
519
|
-
}
|
|
520
|
-
else {
|
|
696
|
+
} else {
|
|
521
697
|
ret = {
|
|
522
698
|
error: {
|
|
523
699
|
code: 60000,
|
|
@@ -526,9 +702,8 @@ Drive.prototype.runRPC = async function(db, method, query, body) {
|
|
|
526
702
|
}
|
|
527
703
|
}
|
|
528
704
|
}
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
$.log.debug(err);
|
|
705
|
+
} catch (err) {
|
|
706
|
+
$.log.error(err);
|
|
532
707
|
ret = {
|
|
533
708
|
error: {
|
|
534
709
|
code: 500,
|
|
@@ -539,4 +714,4 @@ Drive.prototype.runRPC = async function(db, method, query, body) {
|
|
|
539
714
|
return ret;
|
|
540
715
|
};
|
|
541
716
|
|
|
542
|
-
module.exports = Drive;
|
|
717
|
+
module.exports = Drive;
|
|
@@ -29,11 +29,9 @@ Api.prototype.sort = function() {
|
|
|
29
29
|
var p1 = o1.config.path;
|
|
30
30
|
var p2 = o2.config.path;
|
|
31
31
|
var n = p2.length - p1.length;
|
|
32
|
-
if(n)
|
|
33
|
-
{
|
|
32
|
+
if (n) {
|
|
34
33
|
return n;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
34
|
+
} else {
|
|
37
35
|
return o1.config.sort - o2.config.sort;
|
|
38
36
|
}
|
|
39
37
|
});
|
|
@@ -53,8 +51,9 @@ Api.prototype.run = async function(ctx, db) {
|
|
|
53
51
|
}
|
|
54
52
|
const path = ctx.request.path;
|
|
55
53
|
var lt = this.list;
|
|
54
|
+
|
|
56
55
|
for (var i = 0, o; o = lt[i++];) {
|
|
57
|
-
if (o.
|
|
56
|
+
if (o.config.state === 1 && path.has(o.config.path)) {
|
|
58
57
|
var ret = await o.run(ctx, db);
|
|
59
58
|
if (ret) {
|
|
60
59
|
db.ret = ret;
|
|
@@ -81,10 +80,10 @@ Api.prototype.runRPC = async function(db, class_name, method, query, body) {
|
|
|
81
80
|
ret: null
|
|
82
81
|
};
|
|
83
82
|
}
|
|
84
|
-
|
|
83
|
+
|
|
85
84
|
var lt = this.list;
|
|
86
85
|
for (var i = 0, o; o = lt[i++];) {
|
|
87
|
-
if (o.
|
|
86
|
+
if (o.config.state === 1 && class_name == o.config.name) {
|
|
88
87
|
var ret = await o.runRPC(db, method, query, body);
|
|
89
88
|
if (ret) {
|
|
90
89
|
db.ret = ret;
|
|
@@ -98,7 +97,7 @@ Api.prototype.runRPC = async function(db, class_name, method, query, body) {
|
|
|
98
97
|
/**
|
|
99
98
|
* @module 导出API类
|
|
100
99
|
*/
|
|
101
|
-
exports
|
|
100
|
+
module.exports = Api;
|
|
102
101
|
|
|
103
102
|
|
|
104
103
|
/**
|
|
@@ -128,4 +127,4 @@ function api_admin(scope, title) {
|
|
|
128
127
|
/**
|
|
129
128
|
* @module 导出API管理器
|
|
130
129
|
*/
|
|
131
|
-
|
|
130
|
+
$.api_admin = api_admin;
|
|
@@ -60,30 +60,28 @@ Oauth.prototype.main = async function(ctx) {
|
|
|
60
60
|
return null;
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* 小校验
|
|
65
|
+
* @param {Object} ctx
|
|
66
|
+
*/
|
|
67
|
+
Oauth.prototype.check_sub = async function(ctx) {
|
|
68
|
+
|
|
69
|
+
};
|
|
70
|
+
|
|
63
71
|
/**
|
|
64
72
|
* 验证身份
|
|
65
73
|
* @param {Object} ctx HTTP请求上下文
|
|
66
74
|
* @return {Object} 验证失败返回错误提示,验证通过返回null
|
|
67
75
|
*/
|
|
68
76
|
Oauth.prototype.check = async function(ctx) {
|
|
69
|
-
|
|
70
77
|
// 无需登录则不验证身份和权限
|
|
71
78
|
var cg = this.config;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
var error = await this.main(ctx);
|
|
76
|
-
if (error) {
|
|
77
|
-
return error;
|
|
78
|
-
}
|
|
79
|
-
var user;
|
|
80
|
-
if (ctx.session.user) {
|
|
81
|
-
user = ctx.session.user;
|
|
82
|
-
} else {
|
|
79
|
+
var user = ctx.session.user;
|
|
80
|
+
if (!user) {
|
|
83
81
|
var token = ctx.headers[$.dict.token];
|
|
84
82
|
if (token) {
|
|
85
83
|
var u = await $.cache.get($.dict.session_id + '_' + token);
|
|
86
|
-
if(u){
|
|
84
|
+
if (u) {
|
|
87
85
|
var type = typeof(u);
|
|
88
86
|
if (type === "string") {
|
|
89
87
|
var o = u.toJson();
|
|
@@ -93,14 +91,25 @@ Oauth.prototype.check = async function(ctx) {
|
|
|
93
91
|
user = u.user;
|
|
94
92
|
}
|
|
95
93
|
}
|
|
94
|
+
if (user) {
|
|
95
|
+
ctx.session.user = user;
|
|
96
|
+
}
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
}
|
|
100
|
+
if (!cg.signIn) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
var error = await this.main(ctx);
|
|
104
|
+
if (error) {
|
|
105
|
+
return error;
|
|
106
|
+
}
|
|
99
107
|
|
|
100
108
|
error = {
|
|
101
109
|
code: 70000,
|
|
102
110
|
message: "没有访问权限"
|
|
103
111
|
};
|
|
112
|
+
|
|
104
113
|
if (user) {
|
|
105
114
|
// 判断特殊用户级别
|
|
106
115
|
if (cg.gm !== 0 && user.gm < cg.gm) {
|
|
@@ -146,4 +155,4 @@ Oauth.prototype.check = async function(ctx) {
|
|
|
146
155
|
return null;
|
|
147
156
|
};
|
|
148
157
|
|
|
149
|
-
module.exports = Oauth;
|
|
158
|
+
module.exports = Oauth;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* 接口主函数
|
|
4
|
+
* @param {Object} ctx HTTP上下文
|
|
5
|
+
* @param {Object} db 数据管理器,如: { next: async function{}, ret: {} }
|
|
6
|
+
* @return {Object} 执行结果
|
|
7
|
+
*/
|
|
8
|
+
async function main(ctx, db) {
|
|
9
|
+
// 获取请求参数
|
|
10
|
+
var req = ctx.request;
|
|
11
|
+
var {
|
|
12
|
+
query,
|
|
13
|
+
body
|
|
14
|
+
} = req;
|
|
15
|
+
// return "hello world" + JSON.stringify(body);
|
|
16
|
+
|
|
17
|
+
// 操作sql模板
|
|
18
|
+
var m = query.method;
|
|
19
|
+
if (m === "add") {
|
|
20
|
+
|
|
21
|
+
} else if (m === "del") {
|
|
22
|
+
|
|
23
|
+
} else if (m === "set") {
|
|
24
|
+
|
|
25
|
+
} else {
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
var ret = await this.sql.run(query, body, db);
|
|
29
|
+
return ret;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.main = main;
|