mm_os 3.3.1 → 4.0.0
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/LICENSE +21 -201
- package/README.md +491 -99
- package/README_EN.md +498 -0
- package/adapter/adapter.js +431 -0
- package/adapter/custom_persistence.js +660 -0
- package/adapter/mqtt.js +273 -0
- package/adapter/socket.js +113 -0
- package/adapter/web.js +67 -0
- package/adapter/websocket.js +146 -0
- package/com/api/com.json +5 -0
- package/{core/com → com}/api/config.tpl.json +8 -8
- package/com/api/drive.js +708 -0
- package/com/api/index.js +198 -0
- package/com/api/oauth.js +200 -0
- package/com/api/script.tpl.js +32 -0
- package/com/cmd/README.md +11 -0
- package/com/cmd/com.json +5 -0
- package/com/cmd/config.tpl.json +122 -0
- package/com/cmd/drive.js +1548 -0
- package/com/cmd/index.js +1066 -0
- package/com/cmd/msg.json +48 -0
- package/com/cmd/nlp.js +525 -0
- package/com/cmd/script.tpl.js +32 -0
- package/com/db/com.json +5 -0
- package/com/db/drive.js +1999 -0
- package/com/db/index.js +242 -0
- package/{core/com → com}/event/README.md +4 -4
- package/com/event/com.json +5 -0
- package/{core/com → com}/event/config.tpl.json +18 -18
- package/com/event/drive.js +59 -0
- package/com/event/index.js +409 -0
- package/com/event/script.tpl.js +23 -0
- package/com/mqtt/com.json +5 -0
- package/{core/com → com}/mqtt/config.tpl.json +3 -5
- package/com/mqtt/drive.js +676 -0
- package/com/mqtt/index.js +822 -0
- package/com/mqtt/mm_mqtt.js +425 -0
- package/com/mqtt/script.tpl.js +723 -0
- package/com/nav/com.json +5 -0
- package/com/nav/config.tpl.json +84 -0
- package/com/nav/drive.js +702 -0
- package/com/nav/index.js +231 -0
- package/{core/com → com}/nav/tpl/admin_pc/page_config.vue +280 -280
- package/{core/com → com}/nav/tpl/admin_pc/page_config_form.vue +194 -194
- package/com/nav/tpl/admin_pc/page_form.vue +180 -0
- package/com/nav/tpl/admin_pc/page_view.vue +124 -0
- package/com/nav/tpl/dev_pc/page_default.vue +247 -0
- package/com/nav/tpl/dev_pc/page_type.vue +313 -0
- package/com/nav/tpl/home_pc/page_default.vue +234 -0
- package/com/nav/tpl/home_pc/page_form.vue +137 -0
- package/com/nav/tpl/home_pc/page_list.vue +234 -0
- package/com/nav/tpl/home_pc/page_nav.vue +221 -0
- package/com/nav/tpl/home_pc/page_type.vue +234 -0
- package/com/nav/tpl/home_pc/page_view.vue +125 -0
- package/com/nav/tpl/home_phone/page_channel.vue +234 -0
- package/com/nav/tpl/home_phone/page_default.vue +234 -0
- package/com/nav/tpl/home_phone/page_form.vue +137 -0
- package/com/nav/tpl/home_phone/page_nav.vue +237 -0
- package/com/nav/tpl/home_phone/page_type.vue +234 -0
- package/com/nav/tpl/home_phone/page_view.vue +125 -0
- package/com/nav/viewmodel.js +446 -0
- package/com/param/com.json +5 -0
- package/{core/com → com}/param/config.tpl.json +7 -1
- package/com/param/drive.js +502 -0
- package/com/param/index.js +155 -0
- package/com/param/script.tpl.js +12 -0
- package/com/pendant/com.json +5 -0
- package/{core/com/component → com/pendant}/config.tpl.json +15 -13
- package/com/pendant/drive.js +204 -0
- package/com/pendant/index.js +441 -0
- package/com/pendant/pendant.html +16 -0
- package/com/pendant/script.tpl.js +18 -0
- package/com/socket/com.json +5 -0
- package/com/socket/config.tpl.json +12 -0
- package/com/socket/drive.js +651 -0
- package/com/socket/index.js +351 -0
- package/com/socket/script.tpl.js +41 -0
- package/com/sql/com.json +5 -0
- package/{core/com → com}/sql/config.tpl.json +13 -9
- package/com/sql/drive.js +1259 -0
- package/com/sql/index.js +150 -0
- package/com/sql/script.tpl.js +47 -0
- package/com/static/com.json +5 -0
- package/{core/com → com}/static/config.tpl.json +10 -6
- package/com/static/drive.js +194 -0
- package/com/static/index.js +226 -0
- package/com/static/script.tpl.js +28 -0
- package/com/task/com.json +5 -0
- package/{core/com → com}/task/config.tpl.json +4 -6
- package/com/task/drive.js +405 -0
- package/com/task/index.js +148 -0
- package/com/task/script.tpl.js +37 -0
- package/com/template/com.json +5 -0
- package/com/template/config.tpl.json +16 -0
- package/com/template/drive.js +80 -0
- package/com/template/index.js +141 -0
- package/com.js +156 -0
- package/common/README.md +2 -0
- package/common/handler/msg/handler.json +22 -0
- package/common/handler/msg/index.js +23 -0
- package/common/handler/player/handler.json +22 -0
- package/common/handler/player/index.js +287 -0
- package/common/handler/user/handler.json +22 -0
- package/common/handler/user/index.js +23 -0
- package/common/middleware/web_after/index.js +29 -0
- package/common/middleware/web_after/middleware.json +9 -0
- package/common/middleware/web_base/index.js +113 -0
- package/common/middleware/web_base/middleware.json +19 -0
- package/common/middleware/web_before/index.js +33 -0
- package/common/middleware/web_before/middleware.json +9 -0
- package/common/middleware/web_cors/index.js +87 -0
- package/common/middleware/web_cors/middleware.json +24 -0
- package/common/middleware/web_error/index.js +119 -0
- package/common/middleware/web_error/middleware.json +18 -0
- package/common/middleware/web_ip/index.js +15 -0
- package/common/middleware/web_ip/middleware.json +14 -0
- package/common/middleware/web_logger/index.js +156 -0
- package/common/middleware/web_logger/middleware.json +14 -0
- package/common/middleware/web_main/index.js +24 -0
- package/common/middleware/web_main/middleware.json +9 -0
- package/common/middleware/web_static/index.js +73 -0
- package/common/middleware/web_static/middleware.json +54 -0
- package/common/middleware/web_waf/index.js +385 -0
- package/common/middleware/web_waf/middleware.json +13 -0
- package/common/model/msg/index.js +88 -0
- package/common/model/msg/model.json +401 -0
- package/common/model/player/index.js +63 -0
- package/common/model/player/model.json +185 -0
- package/common/model/user/index.js +11 -0
- package/common/model/user/model.json +219 -0
- package/core/app/config.tpl.json +67 -0
- package/core/app/index.js +632 -0
- package/core/app/script.tpl.js +52 -0
- package/core/channel/index.js +899 -0
- package/core/channel/matcher.js +585 -0
- package/core/com/config.tpl.json +16 -0
- package/core/com/index.js +74 -0
- package/core/com/script.tpl.js +5 -0
- package/core/component/component.js +42 -0
- package/core/component/config.tpl.json +63 -0
- package/core/component/index.js +273 -0
- package/core/component/script.tpl.js +19 -0
- package/core/controller/config.tpl.json +14 -0
- package/core/controller/index.js +373 -0
- package/core/controller/script.tpl.js +27 -0
- package/core/factory/config.tpl.json +14 -0
- package/core/factory/entity.js +275 -0
- package/core/factory/index.js +241 -0
- package/core/factory/script.tpl.js +16 -0
- package/core/game/bat/index.js +137 -0
- package/core/game/bat/world.js +622 -0
- package/core/game/config.tpl.json +16 -0
- package/core/game/entity_admin.js +230 -0
- package/core/game/index.js +186 -0
- package/core/handler/config.tpl.json +22 -0
- package/core/handler/index.js +181 -0
- package/core/handler/script.tpl.js +23 -0
- package/core/logic/config.tpl.json +14 -0
- package/core/logic/index.js +59 -0
- package/core/logic/script.tpl.js +19 -0
- package/core/middleware/config.tpl.json +16 -0
- package/core/middleware/index.js +125 -0
- package/core/middleware/script.tpl.js +37 -0
- package/core/mod/config.tpl.json +22 -0
- package/core/mod/index.js +130 -0
- package/core/mod/script.tpl.js +34 -0
- package/core/model/config.tpl.json +219 -0
- package/core/model/index.js +272 -0
- package/core/model/model.js +27 -0
- package/core/model/script.tpl.js +20 -0
- package/core/notifier/config.tpl.json +14 -0
- package/core/notifier/index.js +77 -0
- package/core/notifier/script.tpl.js +20 -0
- package/core/plugin/config.tpl.json +24 -0
- package/core/plugin/index.js +232 -0
- package/core/plugin/script.tpl.js +51 -0
- package/core/pusher/config.tpl.json +14 -0
- package/core/pusher/index.js +161 -0
- package/core/pusher/script.tpl.js +20 -0
- package/core/room/bat/index.js +170 -0
- package/core/room/bat/room.js +524 -0
- package/core/room/config.tpl.json +20 -0
- package/core/room/index.js +249 -0
- package/core/room/room.js +61 -0
- package/core/scene/config.tpl.json +14 -0
- package/core/scene/index.js +466 -0
- package/core/scene/loop.js +1255 -0
- package/core/scene/map.js +28 -0
- package/core/scene/script.tpl.js +22 -0
- package/core/sender/config.tpl.json +14 -0
- package/core/sender/index.js +79 -0
- package/core/sender/script.tpl.js +20 -0
- package/core/service/config.tpl.json +14 -0
- package/core/service/index.js +100 -0
- package/core/service/script.tpl.js +25 -0
- package/core/store/config.tpl.json +26 -0
- package/core/store/index.js +1755 -0
- package/core/store/script.tpl.js +22 -0
- package/core/store/sql.js +1464 -0
- package/core/system/config.tpl.json +18 -0
- package/core/system/index.js +312 -0
- package/core/system/script.tpl.js +77 -0
- package/core/view/config.tpl.json +14 -0
- package/core/view/index.js +91 -0
- package/core/view/script.tpl.js +20 -0
- package/core/zone/bat/index.js +725 -0
- package/core/zone/config.tpl.json +54 -0
- package/core/zone/index.js +614 -0
- package/core/zone/script.tpl.js +10 -0
- package/core/zone/zone_bat.js +136 -0
- package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +24 -0
- package/index.js +17 -333
- package/os.js +57 -0
- package/package.json +58 -58
- package/server.js +598 -0
- package/README.en.md +0 -36
- package/conf.json +0 -3
- package/core/base/mqtt/index.js +0 -1110
- package/core/base/mqtt/lib.js +0 -40
- package/core/base/web/index.js +0 -245
- package/core/com/api/com.json +0 -4
- package/core/com/api/drive.js +0 -668
- package/core/com/api/index.js +0 -108
- package/core/com/api/oauth.js +0 -158
- package/core/com/api/script.js +0 -32
- package/core/com/app/README.md +0 -3
- package/core/com/app/com.json +0 -4
- package/core/com/app/config.tpl.json +0 -16
- package/core/com/app/drive.js +0 -309
- package/core/com/app/index.js +0 -211
- package/core/com/app/script.js +0 -155
- package/core/com/cmd/com.json +0 -4
- package/core/com/cmd/config.tpl.json +0 -66
- package/core/com/cmd/drive.js +0 -513
- package/core/com/cmd/index.js +0 -354
- package/core/com/cmd/old/5w2h.js +0 -54
- package/core/com/cmd/old/drive.js +0 -423
- package/core/com/cmd/script.js +0 -11
- package/core/com/component/README.md +0 -3
- package/core/com/component/com.json +0 -4
- package/core/com/component/component.html +0 -16
- package/core/com/component/drive.js +0 -197
- package/core/com/component/index.js +0 -312
- package/core/com/component/script.js +0 -18
- package/core/com/db/com.json +0 -4
- package/core/com/db/drive.js +0 -1160
- package/core/com/db/index.js +0 -176
- package/core/com/event/com.json +0 -4
- package/core/com/event/drive.js +0 -133
- package/core/com/event/index.js +0 -345
- package/core/com/event/script.js +0 -26
- package/core/com/eventer/com.js +0 -477
- package/core/com/eventer/com.json +0 -4
- package/core/com/middleware/com.js +0 -154
- package/core/com/middleware/com.json +0 -4
- package/core/com/middleware/config.tpl.json +0 -8
- package/core/com/middleware/script.js +0 -9
- package/core/com/mqtt/com.json +0 -4
- package/core/com/mqtt/drive.js +0 -600
- package/core/com/mqtt/index.js +0 -572
- package/core/com/mqtt/mm_mqtt.js +0 -330
- package/core/com/mqtt/script.js +0 -604
- package/core/com/msg/com.js +0 -296
- package/core/com/msg/com.json +0 -4
- package/core/com/nav/com.json +0 -4
- package/core/com/nav/config.tpl.json +0 -75
- package/core/com/nav/drive.js +0 -549
- package/core/com/nav/index.js +0 -182
- package/core/com/nav/tpl/admin_pc/page_form.vue +0 -180
- package/core/com/nav/tpl/admin_pc/page_view.vue +0 -124
- package/core/com/nav/tpl/dev_pc/page_default.vue +0 -247
- package/core/com/nav/tpl/dev_pc/page_type.vue +0 -313
- package/core/com/nav/tpl/home_pc/page_default.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_form.vue +0 -137
- package/core/com/nav/tpl/home_pc/page_list.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_nav.vue +0 -221
- package/core/com/nav/tpl/home_pc/page_type.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_view.vue +0 -125
- package/core/com/nav/tpl/home_phone/page_channel.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_default.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_form.vue +0 -137
- package/core/com/nav/tpl/home_phone/page_nav.vue +0 -237
- package/core/com/nav/tpl/home_phone/page_type.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_view.vue +0 -125
- package/core/com/nav/viewmodel.js +0 -296
- package/core/com/param/drive.js +0 -366
- package/core/com/param/index.js +0 -80
- package/core/com/param/script.js +0 -12
- package/core/com/param/test.js +0 -98
- package/core/com/plugin/README.md +0 -3
- package/core/com/plugin/com.json +0 -4
- package/core/com/plugin/config.tpl.json +0 -26
- package/core/com/plugin/drive.js +0 -536
- package/core/com/plugin/index.js +0 -259
- package/core/com/plugin/script.js +0 -213
- package/core/com/rpc/com.json +0 -4
- package/core/com/rpc/drive.js +0 -160
- package/core/com/rpc/index.js +0 -87
- package/core/com/rpc/rpc.js +0 -118
- package/core/com/socket/com.json +0 -4
- package/core/com/socket/config.tpl.json +0 -14
- package/core/com/socket/drive.js +0 -403
- package/core/com/socket/index.js +0 -62
- package/core/com/socket/script.js +0 -42
- package/core/com/sql/drive.js +0 -1087
- package/core/com/sql/index.js +0 -83
- package/core/com/sql/script.js +0 -48
- package/core/com/static/com.json +0 -4
- package/core/com/static/drive.js +0 -220
- package/core/com/static/index.js +0 -149
- package/core/com/static/script.js +0 -28
- package/core/com/task/com.json +0 -4
- package/core/com/task/drive.js +0 -403
- package/core/com/task/index.js +0 -110
- package/core/com/task/script.js +0 -37
- package/core/com/timer/com.js +0 -217
- package/core/com/timer/com.json +0 -4
- package/core/com/tpl/com.js +0 -19
- package/core/com/tpl/com.json +0 -4
- package/lib/actions.js +0 -50
- package/lib/base.js +0 -361
- package/lib/com.js +0 -29
- package/lib/ref.js +0 -121
- package/middleware/cors/index.js +0 -119
- package/middleware/cors/middleware.json +0 -20
- package/middleware/csrf/index.js +0 -202
- package/middleware/csrf/middleware.json +0 -24
- package/middleware/ip_firewall/index.js +0 -476
- package/middleware/ip_firewall/middleware.json +0 -109
- package/middleware/mqtt_base/index.js +0 -10
- package/middleware/mqtt_base/middleware.json +0 -11
- package/middleware/security_audit/index.js +0 -543
- package/middleware/security_audit/middleware.json +0 -48
- package/middleware/waf/index.js +0 -343
- package/middleware/waf/middleware.json +0 -10
- package/middleware/waf_ddos/index.js +0 -520
- package/middleware/waf_ddos/middleware.json +0 -38
- package/middleware/waf_xss/index.js +0 -269
- package/middleware/waf_xss/middleware.json +0 -18
- package/middleware/web_after/index.js +0 -33
- package/middleware/web_after/middleware.json +0 -10
- package/middleware/web_base/index.js +0 -90
- package/middleware/web_base/middleware.json +0 -10
- package/middleware/web_before/index.js +0 -27
- package/middleware/web_before/middleware.json +0 -10
- package/middleware/web_check/index.js +0 -28
- package/middleware/web_check/middleware.json +0 -10
- package/middleware/web_main/index.js +0 -28
- package/middleware/web_main/middleware.json +0 -10
- package/middleware/web_proxy/index.js +0 -37
- package/middleware/web_proxy/middleware.json +0 -10
- package/middleware/web_render/index.js +0 -87
- package/middleware/web_render/middleware.json +0 -10
- package/middleware/web_socket/index.js +0 -34
- package/middleware/web_socket/middleware.json +0 -10
- package/middleware/web_static/index.js +0 -115
- package/middleware/web_static/middleware.json +0 -10
- /package/{core/com → com}/api/README.md +0 -0
- /package/{core/com → com}/db/README.md +0 -0
- /package/{core/com → com}/mqtt/README.md +0 -0
- /package/{core/com → com}/nav/README.md +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_default.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_lang.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_nav.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_table.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_type.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_config.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_form.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_nav.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_table.vue +0 -0
- /package/{core/com → com}/nav/tpl/home_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/home_phone/page_list.vue +0 -0
- /package/{core/com → com}/param/README.md +0 -0
- /package/{core/com/cmd → com/pendant}/README.md +0 -0
- /package/{core/com → com}/socket/README.md +0 -0
- /package/{core/com → com}/sql/README.md +0 -0
- /package/{core/com → com}/static/README.md +0 -0
- /package/{core/com → com}/task/README.md +0 -0
package/core/com/api/drive.js
DELETED
|
@@ -1,668 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const Item = require('mm_machine').Item;
|
|
4
|
-
const Param = require('../param/drive.js'); // 是MM自带的参数机制,可以不使用
|
|
5
|
-
const Sql = require('../sql/drive.js'); // 是MM自带的参数机制,可以不使用
|
|
6
|
-
const Oauth = require('./oauth.js'); // 是MM自带的身份验证机制,基于Oauth2.0,可以不使用
|
|
7
|
-
const Ret = require('mm_ret').Ret;
|
|
8
|
-
|
|
9
|
-
if (!$.dict) {
|
|
10
|
-
if (!$.dict.session_id) {
|
|
11
|
-
$.dict.session_id = "mm:uuid";
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Api接口驱动类
|
|
17
|
-
* @extends {Item}
|
|
18
|
-
* @class
|
|
19
|
-
*/
|
|
20
|
-
class Drive extends Item {
|
|
21
|
-
/**
|
|
22
|
-
* 构造函数
|
|
23
|
-
* @param {String} dir 当前目录
|
|
24
|
-
* @constructor
|
|
25
|
-
*/
|
|
26
|
-
constructor(dir) {
|
|
27
|
-
super(dir, __dirname);
|
|
28
|
-
this.default_file = "./api.json";
|
|
29
|
-
|
|
30
|
-
this.save_dir = './static/file/';
|
|
31
|
-
this.url_path = "./file/";
|
|
32
|
-
|
|
33
|
-
// oauth身份验证配置 + 函数
|
|
34
|
-
this.oauth;
|
|
35
|
-
// param参数配置 + 函数
|
|
36
|
-
this.param;
|
|
37
|
-
// sql模板配置 + 函数
|
|
38
|
-
this.sql;
|
|
39
|
-
|
|
40
|
-
/* 通用项 */
|
|
41
|
-
// 默认启用热更新
|
|
42
|
-
this.mode = 3;
|
|
43
|
-
// 配置参数
|
|
44
|
-
this.config = {
|
|
45
|
-
// 名称, 由中英文和下“_”组成, 用于修改或卸载 例如: demo
|
|
46
|
-
"name": "",
|
|
47
|
-
// 状态 0未启用,1启用
|
|
48
|
-
"state": 1,
|
|
49
|
-
// 标题, 介绍接口作用
|
|
50
|
-
"title": "示例接口",
|
|
51
|
-
// 描述, 用于描述该接口有什么用的
|
|
52
|
-
"description": "暂无描述",
|
|
53
|
-
// 路径 例如:/demo
|
|
54
|
-
"path": "",
|
|
55
|
-
// 接口类型,api表示服务端数据类型,web表示网页类型,app表示第三方应用类型
|
|
56
|
-
"type": "api",
|
|
57
|
-
// 返回的数据类型
|
|
58
|
-
"contentType": "json",
|
|
59
|
-
// 文件路径, 当调用函数不存在时,会先从文件中加载
|
|
60
|
-
"func_file": "",
|
|
61
|
-
// 回调函数名 用于决定调用脚本的哪个函数
|
|
62
|
-
"func_name": "",
|
|
63
|
-
// 请求方式, POST或GET, 为空或ALL表示都可以
|
|
64
|
-
"method": "ALL",
|
|
65
|
-
// 缓存时长 (单位:秒) 默认:60秒,建议600秒
|
|
66
|
-
"cache": 0,
|
|
67
|
-
// 是否用客户端缓存,即 http 304 状态
|
|
68
|
-
"client_cache": false,
|
|
69
|
-
// param参数验证路径 例如: ./param.json
|
|
70
|
-
"param_path": "",
|
|
71
|
-
// sql模板路径 例如: ./sql.json
|
|
72
|
-
"sql_path": "",
|
|
73
|
-
// 是否验证参数
|
|
74
|
-
"check_param": true,
|
|
75
|
-
// 执行顺序, 数字越小,越优先执行
|
|
76
|
-
"sort": 100,
|
|
77
|
-
// oauth身份验证模型, 参考oauth文件
|
|
78
|
-
"oauth": {
|
|
79
|
-
"scope": true,
|
|
80
|
-
"signIn": false,
|
|
81
|
-
"vip": 0,
|
|
82
|
-
"gm": 0,
|
|
83
|
-
"mc": 0,
|
|
84
|
-
"user_admin": [],
|
|
85
|
-
"user_group": []
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* 新建配置
|
|
94
|
-
* @param {String} 文件
|
|
95
|
-
*/
|
|
96
|
-
Drive.prototype.new_config = function(file) {
|
|
97
|
-
var fl = __dirname + "/config.tpl.json";
|
|
98
|
-
if (fl.hasFile()) {
|
|
99
|
-
var text = fl.loadText();
|
|
100
|
-
if (text) {
|
|
101
|
-
var l = $.slash;
|
|
102
|
-
var arr = file.split(l);
|
|
103
|
-
arr = arr.slice(arr.indexOf('app'));
|
|
104
|
-
var app_name = arr[1];
|
|
105
|
-
var name = arr[arr.length - 2];
|
|
106
|
-
var api_name = arr[arr.length - 3];
|
|
107
|
-
var scope = api_name.replace('_manage', '').replace('_client', '').replace('api_', '');
|
|
108
|
-
if (api_name === "api_client") {
|
|
109
|
-
text = text.replaceAll('{path}', `/api/${name}`);
|
|
110
|
-
text = text.replaceAll('{name}', `${scope}_${name}`);
|
|
111
|
-
} else if (api_name === "api_manage") {
|
|
112
|
-
text = text.replaceAll('{path}', `/apis/${name}`);
|
|
113
|
-
text = text.replaceAll('{name}', `${scope}_${name}_manage`);
|
|
114
|
-
} else if (api_name.indexOf('_manage') !== -1) {
|
|
115
|
-
text = text.replaceAll('{path}', `/apis/${scope}/${name}`);
|
|
116
|
-
text = text.replaceAll('{name}', `${scope}_${name}_manage`);
|
|
117
|
-
} else if (api_name.indexOf('_client') !== -1) {
|
|
118
|
-
text = text.replaceAll('{path}', `/api/${scope}/${name}`);
|
|
119
|
-
text = text.replaceAll('{name}', `${scope}_${name}`);
|
|
120
|
-
} else {
|
|
121
|
-
text = text.replaceAll('{path}', `/api/${scope}/${name}`);
|
|
122
|
-
text = text.replaceAll('{name}', `${scope}_${name}`);
|
|
123
|
-
}
|
|
124
|
-
text = text.replaceAll('{0}', name);
|
|
125
|
-
file.saveText(text);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* 加载完成后执行
|
|
133
|
-
*/
|
|
134
|
-
Drive.prototype.load_after = function() {
|
|
135
|
-
var cg = this.config;
|
|
136
|
-
this.loadParam(cg.param_path);
|
|
137
|
-
this.loadSql(cg.sql_path);
|
|
138
|
-
this.loadOauth();
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* 设置参数对象
|
|
143
|
-
* @param {Object} param 参数对象
|
|
144
|
-
*/
|
|
145
|
-
Drive.prototype.setParam = function(param) {
|
|
146
|
-
if ($.param) {
|
|
147
|
-
var lt = $.param.list;
|
|
148
|
-
if (lt) {
|
|
149
|
-
var has = false;
|
|
150
|
-
var len = lt.length;
|
|
151
|
-
for (var i = 0; i < len; i++) {
|
|
152
|
-
var o = lt[i];
|
|
153
|
-
if (param.filename === o.filename) {
|
|
154
|
-
$.param.list[i] = param;
|
|
155
|
-
has = true;
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (!has) {
|
|
160
|
-
$.param.list.push(param);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* 获取现有参数
|
|
168
|
-
* @param {String} file 文件名
|
|
169
|
-
* @return {Object} 获取的对象
|
|
170
|
-
*/
|
|
171
|
-
Drive.prototype.getParam = function(file) {
|
|
172
|
-
if ($.param) {
|
|
173
|
-
var obj = $.param.list.getObj({
|
|
174
|
-
filename: file
|
|
175
|
-
});
|
|
176
|
-
if (obj) {
|
|
177
|
-
return obj;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return null;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* 加载参数
|
|
185
|
-
* @param {String} file_path 文件路径
|
|
186
|
-
*/
|
|
187
|
-
Drive.prototype.loadParam = async function(file_path) {
|
|
188
|
-
if (file_path) {
|
|
189
|
-
var p = file_path.fullname(this.dir);
|
|
190
|
-
var param = this.getParam(p);
|
|
191
|
-
if (param) {
|
|
192
|
-
this.param = param;
|
|
193
|
-
} else {
|
|
194
|
-
this.param = new Param(this.dir);
|
|
195
|
-
await this.param.exec('load_config', p);
|
|
196
|
-
this.setParam(this.param);
|
|
197
|
-
this.param.load('load');
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* 设置Sql
|
|
204
|
-
* @param {Object} param sql对象
|
|
205
|
-
*/
|
|
206
|
-
Drive.prototype.setSql = function(sql) {
|
|
207
|
-
if ($.sql) {
|
|
208
|
-
var lt = $.sql.list;
|
|
209
|
-
if (lt) {
|
|
210
|
-
var has = false;
|
|
211
|
-
var len = lt.length;
|
|
212
|
-
for (var i = 0; i < len; i++) {
|
|
213
|
-
var o = lt[i];
|
|
214
|
-
if (sql.filename === o.filename) {
|
|
215
|
-
$.sql.list[i] = sql;
|
|
216
|
-
has = true;
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
if (!has) {
|
|
221
|
-
$.sql.list.push(sql);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* 获取现有sql模板
|
|
229
|
-
* @param {String} file 文件名
|
|
230
|
-
* @return {Object} 获取的对象
|
|
231
|
-
*/
|
|
232
|
-
Drive.prototype.getSql = function(file) {
|
|
233
|
-
if ($.sql) {
|
|
234
|
-
var lt = $.sql.list;
|
|
235
|
-
if (lt) {
|
|
236
|
-
var obj = lt.getObj({
|
|
237
|
-
filename: file
|
|
238
|
-
});
|
|
239
|
-
if (obj) {
|
|
240
|
-
return obj;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
return null;
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* 加载sql模板
|
|
249
|
-
* @param {String} file_path 文件路径
|
|
250
|
-
*/
|
|
251
|
-
Drive.prototype.loadSql = async function(file_path) {
|
|
252
|
-
if (file_path) {
|
|
253
|
-
var p = file_path.fullname(this.dir);
|
|
254
|
-
var sql = this.getSql(p);
|
|
255
|
-
if (sql) {
|
|
256
|
-
this.sql = sql;
|
|
257
|
-
} else {
|
|
258
|
-
this.sql = new Sql(this.dir);
|
|
259
|
-
await this.sql.exec('load_config', p);
|
|
260
|
-
this.setSql(this.sql);
|
|
261
|
-
this.sql.exec('load');
|
|
262
|
-
}
|
|
263
|
-
// if (this.sql && this.param && this.param.config) {
|
|
264
|
-
// var list = this.param.config.list;
|
|
265
|
-
// if (list && list.length) {
|
|
266
|
-
// this.sql.params = list;
|
|
267
|
-
// }
|
|
268
|
-
// }
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* 加载身份验证配置
|
|
274
|
-
* @param {Object} cg 配置对象
|
|
275
|
-
*/
|
|
276
|
-
Drive.prototype.loadOauth = function() {
|
|
277
|
-
var cg = this.config.oauth;
|
|
278
|
-
if (cg) {
|
|
279
|
-
this.oauth = new Oauth(this.dir);
|
|
280
|
-
this.oauth.loadObj(cg);
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* 保存文件
|
|
286
|
-
* @param {Object} files 上传的文件
|
|
287
|
-
*/
|
|
288
|
-
Drive.prototype.save_file = function(files) {
|
|
289
|
-
var file;
|
|
290
|
-
var url;
|
|
291
|
-
if (files.file) {
|
|
292
|
-
var f = files.file;
|
|
293
|
-
// 创建可读流
|
|
294
|
-
var stamp = Date.now();
|
|
295
|
-
var name = f.name || f.originalFilename;
|
|
296
|
-
file = ("./" + name).fullname(this.save_dir);
|
|
297
|
-
file.addDir();
|
|
298
|
-
// 创建写入流
|
|
299
|
-
var readStream = fs.createReadStream(f.filepath);
|
|
300
|
-
|
|
301
|
-
try {
|
|
302
|
-
const writeStream = fs.createWriteStream(file);
|
|
303
|
-
readStream.pipe(writeStream);
|
|
304
|
-
// writeStream.close();
|
|
305
|
-
url = this.url_path + name;
|
|
306
|
-
} catch (err) {
|
|
307
|
-
$.log.error('保存文件失败', err);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
return {
|
|
311
|
-
file,
|
|
312
|
-
url
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
/* 回调函数集 */
|
|
317
|
-
$.get_state = async function(db, token) {
|
|
318
|
-
var db1 = db.new("user_state", "user_id");
|
|
319
|
-
var state = await db1.getObj({
|
|
320
|
-
token
|
|
321
|
-
}, null, null, false);
|
|
322
|
-
if (!state) {
|
|
323
|
-
return null
|
|
324
|
-
}
|
|
325
|
-
var now = new Date();
|
|
326
|
-
if (state.time_sign.interval(now, 'day') <= 30) {
|
|
327
|
-
db.table = "user_account";
|
|
328
|
-
var user = await db.getObj({
|
|
329
|
-
user_id: state.user_id
|
|
330
|
-
});
|
|
331
|
-
var o = Object.assign({}, user);
|
|
332
|
-
o.password_pay = o.password_pay ? "******" : "";
|
|
333
|
-
o.password = o.password ? "******" : "";
|
|
334
|
-
delete o.salt;
|
|
335
|
-
delete o.time_create;
|
|
336
|
-
return {
|
|
337
|
-
state,
|
|
338
|
-
user: o
|
|
339
|
-
};
|
|
340
|
-
} else {
|
|
341
|
-
return null;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* 获取登录态
|
|
347
|
-
* @param {Object} ctx 请求上下文
|
|
348
|
-
* @param {Object} db 数据管理器
|
|
349
|
-
* @return {Object} 执行结果
|
|
350
|
-
*/
|
|
351
|
-
Drive.prototype.get_state = async function(ctx, db) {
|
|
352
|
-
var o;
|
|
353
|
-
// 获取请求参数
|
|
354
|
-
var u = ctx.session ? ctx.session.user : null;
|
|
355
|
-
if (u) {
|
|
356
|
-
o = Object.assign({}, u);
|
|
357
|
-
o.token = ctx.session.uuid;
|
|
358
|
-
} else {
|
|
359
|
-
var token = ctx.headers[$.dict.token];
|
|
360
|
-
if (token) {
|
|
361
|
-
u = await $.cache.get($.dict.session_id + '_' + token);
|
|
362
|
-
if (u) {
|
|
363
|
-
if (typeof(u) === "string") {
|
|
364
|
-
o = Object.assign({}, u.toJson());
|
|
365
|
-
} else if (Object.keys(u).length > 0) {
|
|
366
|
-
o = Object.assign({}, u);
|
|
367
|
-
}
|
|
368
|
-
if (!o.user_id) {
|
|
369
|
-
var obj = await $.get_state(db, token);
|
|
370
|
-
if (obj) {
|
|
371
|
-
o = Object.assign({}, obj.user);
|
|
372
|
-
ctx.session.user = obj.user;
|
|
373
|
-
o.token = ctx.session.uuid;
|
|
374
|
-
obj.state.token = o.token;
|
|
375
|
-
} else {
|
|
376
|
-
o = null;
|
|
377
|
-
}
|
|
378
|
-
} else {
|
|
379
|
-
o.token = token;
|
|
380
|
-
}
|
|
381
|
-
} else {
|
|
382
|
-
var obj = await $.get_state(db, token);
|
|
383
|
-
if (obj) {
|
|
384
|
-
o = Object.assign({}, obj.user);
|
|
385
|
-
ctx.session.user = obj.user;
|
|
386
|
-
o.token = ctx.session.uuid;
|
|
387
|
-
obj.state.token = o.token;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
if (o) {
|
|
393
|
-
o.password_pay = o.password_pay ? "******" : "";
|
|
394
|
-
o.password = o.password ? "******" : "";
|
|
395
|
-
delete o.salt;
|
|
396
|
-
delete o.time_create;
|
|
397
|
-
}
|
|
398
|
-
return o;
|
|
399
|
-
};
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* 获取登录态
|
|
403
|
-
* @param {Object} ctx 请求上下文
|
|
404
|
-
* @param {Object} db 数据管理器
|
|
405
|
-
* @return {Object} 执行结果
|
|
406
|
-
*/
|
|
407
|
-
Drive.prototype.before = async function(ctx, db) {
|
|
408
|
-
if (this.config.oauth && this.config.oauth.signIn) {
|
|
409
|
-
db.user = await this.get_state(ctx, db);
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* 主要函数
|
|
415
|
-
* @param {Object} ctx 请求上下文
|
|
416
|
-
* @param {Object} db 数据管理器
|
|
417
|
-
* @return {Object} 执行结果
|
|
418
|
-
*/
|
|
419
|
-
Drive.prototype.main = async function(ctx, db) {
|
|
420
|
-
if (ret) {
|
|
421
|
-
console.log("是啥?", this.config.path, this.config.name, this.sql);
|
|
422
|
-
}
|
|
423
|
-
if (this.sql) {
|
|
424
|
-
var req = ctx.request;
|
|
425
|
-
// 获取文件
|
|
426
|
-
if (req.files) {
|
|
427
|
-
var fobj = this.save_file(req.files);
|
|
428
|
-
req.body.file = fobj.file;
|
|
429
|
-
req.body.url = fobj.url;
|
|
430
|
-
}
|
|
431
|
-
var ret = await this.sql.run(req.query, req.body, db);
|
|
432
|
-
return ret;
|
|
433
|
-
} else {
|
|
434
|
-
return $.ret.error(10000, "接口函数未定义");
|
|
435
|
-
}
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* 调用函数
|
|
440
|
-
* @param {Object} ctx 请求上下文
|
|
441
|
-
* @param {Object} db 数据管理器
|
|
442
|
-
* @return {Object} 执行结果
|
|
443
|
-
*/
|
|
444
|
-
Drive.prototype.run = async function(ctx, db) {
|
|
445
|
-
try {
|
|
446
|
-
var body = await this.getCache(ctx);
|
|
447
|
-
if (!body) {
|
|
448
|
-
var req = ctx.request;
|
|
449
|
-
var md = this.config["method"].toLocaleUpperCase();
|
|
450
|
-
if (md !== req.method && md !== "ALL") {
|
|
451
|
-
return null;
|
|
452
|
-
}
|
|
453
|
-
await this.before(ctx, db);
|
|
454
|
-
var ret = await this.check(ctx, db);
|
|
455
|
-
if (!ret) {
|
|
456
|
-
try {
|
|
457
|
-
ret = await this.main(ctx, db);
|
|
458
|
-
} catch (err) {
|
|
459
|
-
$.log.error("脚本文件错误", req.path, err);
|
|
460
|
-
ret = $.ret.error(10000, "脚本文件错误:" + err.toString());
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
var res = ctx.response;
|
|
464
|
-
body = this.body(ret, res, req.type);
|
|
465
|
-
this.setCache(ctx, body, res.type);
|
|
466
|
-
}
|
|
467
|
-
} catch (err) {
|
|
468
|
-
$.log.error("接口错误", ctx.path, err);
|
|
469
|
-
}
|
|
470
|
-
return body;
|
|
471
|
-
};
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
* 获取缓存
|
|
475
|
-
* @param {Object} ctx 请求上下文
|
|
476
|
-
* @return {String} 响应内容
|
|
477
|
-
*/
|
|
478
|
-
Drive.prototype.getCache = async function(ctx) {
|
|
479
|
-
var cg = this.config;
|
|
480
|
-
if (cg.cache) {
|
|
481
|
-
var req = ctx.request;
|
|
482
|
-
if (cg.client_cache) {
|
|
483
|
-
var etag = req.headers['if-none-match'];
|
|
484
|
-
if (etag) {
|
|
485
|
-
var stamp = Number(etag.replace('"', '').replace('"', ''));
|
|
486
|
-
var cha = stamp * 1000 - Date.parse(new Date());
|
|
487
|
-
if (cha > 0) {
|
|
488
|
-
ctx.response.status = 304;
|
|
489
|
-
return ' ';
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
} else {
|
|
493
|
-
var data = await $.cache.get("api_" + req.url);
|
|
494
|
-
if (data) {
|
|
495
|
-
var obj = JSON.parse(data);
|
|
496
|
-
ctx.response.type = obj.type;
|
|
497
|
-
return obj.body;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
return null;
|
|
502
|
-
};
|
|
503
|
-
|
|
504
|
-
/**
|
|
505
|
-
* 设置缓存
|
|
506
|
-
* @param {Object} ctx 请求上下文
|
|
507
|
-
* @param {Object} body 正文参数
|
|
508
|
-
*/
|
|
509
|
-
Drive.prototype.setCache = async function(ctx, body) {
|
|
510
|
-
var cg = this.config;
|
|
511
|
-
if (cg.cache && ctx.method === 'GET') {
|
|
512
|
-
if (cg.client_cache) {
|
|
513
|
-
var age = cg.cache * 60;
|
|
514
|
-
ctx.set('Cache-Control', 'max-age=' + age);
|
|
515
|
-
ctx.etag = Date.parse(new Date()) / 1000 + age;
|
|
516
|
-
return " ";
|
|
517
|
-
} else {
|
|
518
|
-
var req = ctx.request;
|
|
519
|
-
var o = {};
|
|
520
|
-
o.body = body;
|
|
521
|
-
o.type = ctx.response.type;
|
|
522
|
-
$.cache.set("api_" + req.url, JSON.stringify(o), cg.cache * 60);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
};
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
* 调用函数
|
|
529
|
-
* @param {Object} ret 设置响应结果
|
|
530
|
-
* @param {Object} res 响应器
|
|
531
|
-
* @param {String} t 请求类型
|
|
532
|
-
* @return {String} 处理后的响应结果
|
|
533
|
-
*/
|
|
534
|
-
Drive.prototype.body = function(ret, res, t) {
|
|
535
|
-
var type;
|
|
536
|
-
if (res.type) {
|
|
537
|
-
type = res.type;
|
|
538
|
-
}
|
|
539
|
-
if (ret) {
|
|
540
|
-
var tp = typeof(ret);
|
|
541
|
-
if (tp === "object") {
|
|
542
|
-
if (!type) {
|
|
543
|
-
/// 设置响应头
|
|
544
|
-
if (t.indexOf('xml') !== -1) {
|
|
545
|
-
type = t;
|
|
546
|
-
} else {
|
|
547
|
-
type = "application/json; charset=utf-8";
|
|
548
|
-
}
|
|
549
|
-
res.type = type;
|
|
550
|
-
} else {
|
|
551
|
-
if (type.indexOf('json') !== -1) {
|
|
552
|
-
type = "application/json; charset=utf-8";
|
|
553
|
-
} else if (type.indexOf('html') !== -1) {
|
|
554
|
-
type = "text/html";
|
|
555
|
-
} else if (type.indexOf('xml') !== -1) {
|
|
556
|
-
type = "text/xml; charset=utf-8";
|
|
557
|
-
} else {
|
|
558
|
-
type = "text/plain; charset=utf-8";
|
|
559
|
-
}
|
|
560
|
-
res.type = type;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
if (type.indexOf('/xml') !== -1) {
|
|
564
|
-
return $.toXml(ret);
|
|
565
|
-
} else {
|
|
566
|
-
return JSON.stringify(ret);
|
|
567
|
-
}
|
|
568
|
-
} else if (tp === "string") {
|
|
569
|
-
ret = ret.trim();
|
|
570
|
-
if (!type) {
|
|
571
|
-
if (ret.startWith('{') && ret.endWith('}')) {
|
|
572
|
-
res.type = "application/json; charset=utf-8";
|
|
573
|
-
} else if (ret.startWith('[') && ret.endWith(']')) {
|
|
574
|
-
res.type = "application/json; charset=utf-8";
|
|
575
|
-
} else if (ret.endWith("</html>")) {
|
|
576
|
-
res.type = "text/html";
|
|
577
|
-
} else {
|
|
578
|
-
res.type = "text/plain; charset=utf-8";
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
return ret;
|
|
584
|
-
};
|
|
585
|
-
|
|
586
|
-
/**
|
|
587
|
-
* 验证参数
|
|
588
|
-
* @param {Object} query url参数
|
|
589
|
-
* @param {Object} body 内容参数
|
|
590
|
-
* @param {String} method 方法
|
|
591
|
-
* @return {Object} 验证结果
|
|
592
|
-
*/
|
|
593
|
-
Drive.prototype.checkParam = function(query, body, method) {
|
|
594
|
-
if (this.param) {
|
|
595
|
-
var msg = this.param.check(query, body, method);
|
|
596
|
-
if (msg) {
|
|
597
|
-
var code;
|
|
598
|
-
if (msg.indexOf("必须") !== -1 || msg.indexOf("为空") !== -1) {
|
|
599
|
-
code = 30001;
|
|
600
|
-
} else {
|
|
601
|
-
code = 30002;
|
|
602
|
-
}
|
|
603
|
-
return $.ret.error(code, msg);
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
return null;
|
|
607
|
-
};
|
|
608
|
-
|
|
609
|
-
/**
|
|
610
|
-
* 验证参数
|
|
611
|
-
* @param {Object} ctx 内容上下文
|
|
612
|
-
* @return {Object} 验证结果
|
|
613
|
-
*/
|
|
614
|
-
Drive.prototype.check = async function(ctx) {
|
|
615
|
-
var error;
|
|
616
|
-
if (this.config.check_param) {
|
|
617
|
-
var req = ctx.request;
|
|
618
|
-
error = this.checkParam(req.query, req.body, req.method);
|
|
619
|
-
}
|
|
620
|
-
if (!error) {
|
|
621
|
-
error = await this.checkOauth(ctx);
|
|
622
|
-
if (error) {
|
|
623
|
-
error = {
|
|
624
|
-
error
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
return error;
|
|
629
|
-
};
|
|
630
|
-
|
|
631
|
-
/**
|
|
632
|
-
* 验证身份
|
|
633
|
-
* @param {Object} ctx 内容上下文
|
|
634
|
-
* @return {Object} 验证结果
|
|
635
|
-
*/
|
|
636
|
-
Drive.prototype.checkOauth = async function(ctx) {
|
|
637
|
-
var aouth = this.oauth;
|
|
638
|
-
if (aouth) {
|
|
639
|
-
return await aouth.check(ctx);
|
|
640
|
-
} else {
|
|
641
|
-
return null;
|
|
642
|
-
}
|
|
643
|
-
};
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
/**
|
|
647
|
-
* 获取插件
|
|
648
|
-
* @param {String} app 应用名称
|
|
649
|
-
* @param {String} name 插件名称
|
|
650
|
-
* @returns {Object} 返回获取到的插件
|
|
651
|
-
*/
|
|
652
|
-
Drive.prototype.plugin = function(app, name) {
|
|
653
|
-
var plus;
|
|
654
|
-
var l = $.slash;
|
|
655
|
-
if (!app) {
|
|
656
|
-
app = this.filename.between("app" + l, l);
|
|
657
|
-
}
|
|
658
|
-
if (!name) {
|
|
659
|
-
name = this.filename.between("plugin" + l, l);
|
|
660
|
-
}
|
|
661
|
-
var plugins = $.pool.plugin[app];
|
|
662
|
-
if (plugins) {
|
|
663
|
-
plus = plugins.get(name);
|
|
664
|
-
}
|
|
665
|
-
return plus
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
module.exports = Drive;
|