jj.js 0.8.7 → 0.9.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.
@@ -1,65 +1,65 @@
1
- module.exports = `<!doctype html>
2
- <html>
3
- <head>
4
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
- <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
6
- <title>jj.js</title>
7
- <style type="text/css">
8
- * { padding: 0; margin: 0; }
9
- body { background: #fff; font-family: "Microsoft Yahei","Helvetica Neue",Helvetica,Arial,sans-serif; color: #333; font-size: 16px; }
10
- .message { padding: 24px 48px; }
11
- .message h1 { font-size: 36px; font-weight: normal; line-height: 50px; margin-bottom: 12px; }
12
- .message h3 { line-height: 1.8em; font-size: 28px; font-weight: normal; }
13
- .message .code {
14
- line-height: 1.5em;
15
- font-size: 12px;
16
- white-space: pre-wrap;
17
- background: #303030;
18
- color: #f1f1f1;
19
- padding: 10px .2em 10px 3.2em;
20
- border-radius: 2px;
21
- -moz-box-shadow: inset 0 0 10px #000;
22
- box-shadow: inset 0 0 10px #000;
23
- counter-reset: line {$begin};
24
- }
25
- .message .code .line {
26
- display: block;
27
- padding-left: 1em;
28
- padding-right: 1em;
29
- min-height: 1.5em;
30
- position: relative;
31
- }
32
- .message .code .line:before {
33
- counter-increment: line;
34
- content: counter(line);
35
- display: inline-block;
36
- box-sizing: border-box;
37
- border-right: 1px solid #ddd;
38
- width: 3.2em;
39
- padding-right: .5em;
40
- color: #888;
41
- text-align: right;
42
- position: absolute;
43
- left: -3em;
44
- }
45
- .message .code .line:nth-child({$nth}) {
46
- background-color: #efed0b;
47
- color: #303030;
48
- }
49
- .message .code .line:nth-child({$nth}):before {
50
- background-color: #efed0b;
51
- color: #333;
52
- }
53
- .message .stack{ line-height: 1.8em; font-size: 14px; }
54
- </style>
55
- </head>
56
- <body>
57
- <div class="message">
58
- <h1 class="h0">jj.js</h1>
59
- <h3>{$msg}</h3>
60
- <pre class="code">{$code}</pre>
61
- <h3>Call Stack</h3>
62
- <p class="stack">{$stack}</p>
63
- </div>
64
- </body>
1
+ module.exports = `<!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
6
+ <title>jj.js</title>
7
+ <style type="text/css">
8
+ * { padding: 0; margin: 0; }
9
+ body { background: #fff; font-family: "Microsoft Yahei","Helvetica Neue",Helvetica,Arial,sans-serif; color: #333; font-size: 16px; }
10
+ .message { padding: 24px 48px; }
11
+ .message h1 { font-size: 36px; font-weight: normal; line-height: 50px; margin-bottom: 12px; }
12
+ .message h3 { line-height: 1.8em; font-size: 28px; font-weight: normal; }
13
+ .message .code {
14
+ line-height: 1.5em;
15
+ font-size: 12px;
16
+ white-space: pre-wrap;
17
+ background: #303030;
18
+ color: #f1f1f1;
19
+ padding: 10px .2em 10px 3.2em;
20
+ border-radius: 2px;
21
+ -moz-box-shadow: inset 0 0 10px #000;
22
+ box-shadow: inset 0 0 10px #000;
23
+ counter-reset: line {$begin};
24
+ }
25
+ .message .code .line {
26
+ display: block;
27
+ padding-left: 1em;
28
+ padding-right: 1em;
29
+ min-height: 1.5em;
30
+ position: relative;
31
+ }
32
+ .message .code .line:before {
33
+ counter-increment: line;
34
+ content: counter(line);
35
+ display: inline-block;
36
+ box-sizing: border-box;
37
+ border-right: 1px solid #ddd;
38
+ width: 3.2em;
39
+ padding-right: .5em;
40
+ color: #888;
41
+ text-align: right;
42
+ position: absolute;
43
+ left: -3em;
44
+ }
45
+ .message .code .line:nth-child({$nth}) {
46
+ background-color: #efed0b;
47
+ color: #303030;
48
+ }
49
+ .message .code .line:nth-child({$nth}):before {
50
+ background-color: #efed0b;
51
+ color: #333;
52
+ }
53
+ .message .stack{ line-height: 1.8em; font-size: 14px; }
54
+ </style>
55
+ </head>
56
+ <body>
57
+ <div class="message">
58
+ <h1 class="h0">jj.js</h1>
59
+ <h3>{$msg}</h3>
60
+ <pre class="code">{$code}</pre>
61
+ <h3>Call Stack</h3>
62
+ <p class="stack">{$stack}</p>
63
+ </div>
64
+ </body>
65
65
  </html>`;
package/lib/tpl/jump.js CHANGED
@@ -1,41 +1,41 @@
1
- module.exports = `<!doctype html>
2
- <html>
3
- <head>
4
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
- <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
6
- <title>跳转提示</title>
7
- <style type="text/css">
8
- *{ padding: 0; margin: 0; }
9
- body{ background: #fff; font-family: "Microsoft Yahei","Helvetica Neue",Helvetica,Arial,sans-serif; color: #333; font-size: 16px; }
10
- .message{ padding: 24px 48px; }
11
- .message h1{ font-size: 42px; font-weight: normal; line-height: 120px; margin-bottom: 12px; display: none; }
12
- .message .h{$state}{ display: initial; }
13
- .message .text{ line-height: 1.8em; font-size: 36px; }
14
- .message .jump{ padding-top: 10px; }
15
- .message .jump a{ color: #333; }
16
- </style>
17
- </head>
18
- <body>
19
- <div class="message">
20
- <h1 class="h1">◠‿◠</h1>
21
- <h1 class="h0">&gt;﹏&lt;</h1>
22
- <p class="text">{$msg}</p>
23
- <p class="jump">
24
- 页面自动 <a id="href" href="{$url}">跳转</a> 等待时间:<b id="wait">{$wait}</b>
25
- </p>
26
- </div>
27
- <script>
28
- (function(){
29
- var wait = document.getElementById('wait'),
30
- href = document.getElementById('href').href;
31
- var interval = setInterval(function(){
32
- var time = --wait.innerHTML;
33
- if(time <= 0) {
34
- location.href = href;
35
- clearInterval(interval);
36
- };
37
- }, 1000);
38
- })();
39
- </script>
40
- </body>
1
+ module.exports = `<!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
6
+ <title>跳转提示</title>
7
+ <style type="text/css">
8
+ *{ padding: 0; margin: 0; }
9
+ body{ background: #fff; font-family: "Microsoft Yahei","Helvetica Neue",Helvetica,Arial,sans-serif; color: #333; font-size: 16px; }
10
+ .message{ padding: 24px 48px; }
11
+ .message h1{ font-size: 42px; font-weight: normal; line-height: 120px; margin-bottom: 12px; display: none; }
12
+ .message .h{$state}{ display: initial; }
13
+ .message .text{ line-height: 1.8em; font-size: 36px; }
14
+ .message .jump{ padding-top: 10px; }
15
+ .message .jump a{ color: #333; }
16
+ </style>
17
+ </head>
18
+ <body>
19
+ <div class="message">
20
+ <h1 class="h1">◠‿◠</h1>
21
+ <h1 class="h0">&gt;﹏&lt;</h1>
22
+ <p class="text">{$msg}</p>
23
+ <p class="jump">
24
+ 页面自动 <a id="href" href="{$url}">跳转</a> 等待时间:<b id="wait">{$wait}</b>
25
+ </p>
26
+ </div>
27
+ <script>
28
+ (function(){
29
+ var wait = document.getElementById('wait'),
30
+ href = document.getElementById('href').href;
31
+ var interval = setInterval(function(){
32
+ var time = --wait.innerHTML;
33
+ if(time <= 0) {
34
+ location.href = href;
35
+ clearInterval(interval);
36
+ };
37
+ }, 1000);
38
+ })();
39
+ </script>
40
+ </body>
41
41
  </html>`;
package/lib/types.js ADDED
@@ -0,0 +1,286 @@
1
+ //------------------系统核心库------------------
2
+ /**
3
+ * @typedef {Object} Core
4
+ * @property {typeof import('./app')} App
5
+ * @property {typeof import('./cache')} Cache
6
+ * @property {typeof import('./context')} Context
7
+ * @property {typeof import('./controller')} Controller
8
+ * @property {typeof import('./cookie')} Cookie
9
+ * @property {typeof import('./db')} Db
10
+ * @property {typeof import('./logger')} Logger
11
+ * @property {typeof import('./middleware')} Middleware
12
+ * @property {typeof import('./model')} Model
13
+ * @property {typeof import('./pagination')} Pagination
14
+ * @property {typeof import('./response')} Response
15
+ * @property {typeof import('./upload')} Upload
16
+ * @property {typeof import('./url')} Url
17
+ * @property {typeof import('./view')} View
18
+ * @property {Utils} utils
19
+ */
20
+
21
+
22
+ //------------------系统App配置---------------------
23
+ /**
24
+ * @typedef {Object} AppConfig - 系统配置
25
+ * @property {boolean} [app_debug=true] - 调试模式
26
+ * @property {boolean} [app_multi=false] - 是否开启多应用
27
+ * @property {string} [default_app=app] - 默认应用
28
+ * @property {string} [default_controller=index] - 默认控制器
29
+ * @property {string} [default_action=index] - 默认方法
30
+ * @property {string} [common_app=common] - 公共应用,存放公共模型及逻辑
31
+ * @property {string} [controller_folder=controller] - 控制器目录名
32
+ * @property {(string|boolean)} [static_dir=''] - 静态文件目录,相对于应用根目录,为空或false时,关闭静态访问
33
+ * @property {(string|boolean|null|object)} [koa_body=null] - koa-body配置参数,为''、null、false时,关闭koa-body
34
+ * @property {string} [base_dir] - 应用根目录(会自动计算)
35
+ */
36
+
37
+ /**
38
+ * @typedef {Object} ViewConfig - 模板配置
39
+ * @property {string} [view_folder=view] - 模板目录名
40
+ * @property {string} [view_depr='/'] - 模版文件名分割符,'/'代表二级目录
41
+ * @property {string} [view_ext='.htm'] - 模版文件后缀
42
+ * @property {string} [view_engine=art-template] - 默认模版引擎,字符串或引擎类
43
+ * @property {object} [view_filte={}] - 模版函数
44
+ */
45
+
46
+ /**
47
+ * @typedef {Object} DbConfigItem - 数据库参数
48
+ * @property {string} [type=mysql] - 数据库类型
49
+ * @property {string} [host='127.0.0.1'] - 服务器地址
50
+ * @property {string} [database=jj] - 数据库名
51
+ * @property {string} [user=root] - 数据库用户名
52
+ * @property {string} [password=''] - 数据库密码
53
+ * @property {string} [port=''] - 数据库连接端口
54
+ * @property {string} [charset=utf8] - 数据库编码默认采用utf8
55
+ * @property {string} [prefix=jj_] - 数据库表前缀
56
+ */
57
+
58
+ /**
59
+ * @typedef {object} DbConfig - 数据库配置
60
+ * @property {DbConfigItem} default - 数据库参数
61
+ */
62
+
63
+ /**
64
+ * @callback LogHandle - 日志驱动
65
+ * @param {string} level - 日志级别
66
+ * @param {array} args - 日志数据,支持多个,支持对象
67
+ */
68
+
69
+ /**
70
+ * @typedef {object} LogConfig - 日志配置
71
+ * @property {array} [log_level] - 允许输出的日志级别
72
+ * @property {LogHandle} [log_handle] - 日志驱动
73
+ */
74
+
75
+ /**
76
+ * @typedef {Object} CacheConfig - 缓存配置
77
+ * @property {number} [cache_time='60 * 60 * 24'] - 缓存时间,默认1天,为空或false则为10年
78
+ * @property {number} [clear_time=undefined] - 缓存自动清理周期,undefined: 清理一次, 0: 关闭自动清理, >0: 为周期时间,单位秒
79
+ */
80
+
81
+ /**
82
+ * @typedef {Object} PageConfig - 分页配置
83
+ * @property {string} [page_key=page] - 分页标识
84
+ * @property {string} [key_origin=query] - page_key来源
85
+ * @property {number} [page_size=10] - page_key来源
86
+ * @property {number} [page_length=5] - page_key来源
87
+ * @property {string} [url_page] - page_key来源
88
+ * @property {string} [url_index] - page_key来源
89
+ * @property {string} [index_tpl] - 首页模板
90
+ * @property {string} [end_tpl] - 末页模板
91
+ * @property {string} [prev_tpl] - 上一页模板
92
+ * @property {string} [next_tpl] - 下一页模板
93
+ * @property {string} [list_tpl] - 数字页模板
94
+ * @property {string} [active_tpl] - 当前页模板
95
+ * @property {string} [info_tpl] - 分页信息模板
96
+ * @property {string} [template] - 渲染模板
97
+ */
98
+
99
+ /**
100
+ * @typedef {Object} RouteConfigItem - 路由配置
101
+ * @property {string} [method=all] - 请求方法,支持['all', 'get', 'put', 'post', 'patch', 'delete', 'del']
102
+ * @property {string} url - 请求url,支持变量正则,详细参考@koa/router
103
+ * @property {(string|Middleware)} path - 响应地址(支持智能解析)或中间件函数,如果为中间件函数,则不会再执行后续代码
104
+ * @property {string} [type='AppConfig.controller_folder'] - 响应类型,即path对应的类型,支持controller、middleware、view(ViewConfig.view_folder)
105
+ * @property {string} [name] - 路由命名,命一个名字后,可以使用Url类反向编译路由url
106
+ */
107
+
108
+ /**
109
+ * @typedef {RouteConfigItem[]} RouteConfig - 路由配置
110
+ */
111
+
112
+ /**
113
+ * @typedef {import('cookies').SetOption} CookieConfig - Cookie配置,一般不用设置
114
+ */
115
+
116
+ /**
117
+ * @typedef {Object} TplConfig - 跳转、调试模板配置
118
+ * @property {string} [jump] - 跳转模板,默认require('./tpl/jump')
119
+ * @property {string} [exception] - 调试异常输出模板,默认require('./tpl/exception')
120
+ */
121
+
122
+ /**
123
+ * @typedef {Object} Config - 系统配置
124
+ * @property {AppConfig} [app]
125
+ * @property {ViewConfig} [view]
126
+ * @property {DbConfig} [db]
127
+ * @property {LogConfig} [log]
128
+ * @property {CacheConfig} [cache]
129
+ * @property {PageConfig} [page]
130
+ * @property {RouteConfig} [routes]
131
+ * @property {CookieConfig} [cookie]
132
+ * @property {TplConfig} [tpl]
133
+ */
134
+
135
+
136
+ //------------------分页类--------------------
137
+ /**
138
+ * @typedef {typeof import('./pagination')} Pagination - 分页类
139
+ * @typedef {typeof import('./pagination').prototype} PaginationInstance - 分页类实例
140
+ */
141
+
142
+
143
+ //------------------数据库类--------------------
144
+ /**
145
+ * @typedef {import('mysql').Pool} Pool - 连接池
146
+ * @typedef {import('mysql').PoolConfig} PoolConfig - 连接池配置
147
+ * @typedef {import('mysql').PoolConnection} PoolConnection - 连接池连接
148
+ * @typedef {import('mysql').QueryOptions} QueryOptions - 查询参数
149
+ * @typedef {import('mysql').OkPacket} OkPacket - 数据库查询结果
150
+ * @typedef {Object} RowData - 单条数据
151
+ * @typedef {Array<RowData>} ListData - 多条数据
152
+ * @typedef {Object} FieldInfo - 字段信息
153
+ * @property {string} Field
154
+ * @property {string} Type
155
+ * @property {string} Null
156
+ * @property {string} Key
157
+ * @property {string} Default
158
+ * @property {string} Extra
159
+ * @typedef {Map<Pool>} PoolMap
160
+ */
161
+
162
+
163
+ //------------------上传类--------------------
164
+ /**
165
+ * @typedef {Object} UploadData
166
+ * @property {string} [filename]
167
+ * @property {string} [extname]
168
+ * @property {string} [savename]
169
+ * @property {string} [filepath]
170
+ * @property {string} [name]
171
+ * @property {number} [size]
172
+ * @property {string} [mimetype]
173
+ * @property {string} [hash]
174
+ * /
175
+ *
176
+ /**
177
+ * @typedef {Object} ValidateRule
178
+ * @property {number} [size] - 文件大小
179
+ * @property {string} [ext] - 文件名后缀,多个用','隔开
180
+ * @property {string} [type] - 文件mimetype,多个用','隔开
181
+ */
182
+
183
+
184
+ //------------------系统工具--------------------
185
+ /**
186
+ * @typedef {Object} Utils
187
+ * @property {typeof import('./utils/date')} date
188
+ * @property {typeof import('./utils/error')} error
189
+ * @property {typeof import('./utils/fs')} fs
190
+ * @property {typeof import('./utils/md5')} md5
191
+ * @property {typeof import('./utils/str')} str
192
+ */
193
+
194
+
195
+ //------------------系统Context--------------------
196
+ /**
197
+ * @typedef {import('koa').Context} Context
198
+ * @typedef {import('koa').Middleware} Middleware
199
+ */
200
+
201
+
202
+ //------------------Ctx系统基类--------------------
203
+ class Ctx {
204
+ constructor() {
205
+ /**
206
+ * @desc 系统缓存类
207
+ * @type {typeof import('./cache')}
208
+ */
209
+ this.$cache;
210
+
211
+ /**
212
+ * @type {typeof import('./context').prototype}
213
+ */
214
+ this.$context;
215
+
216
+ /**
217
+ * @type {typeof import('./controller').prototype}
218
+ */
219
+ this.$controller;
220
+
221
+ /**
222
+ * @type {typeof import('./cookie').prototype}
223
+ */
224
+ this.$cookie;
225
+
226
+ /**
227
+ * @type {typeof import('./db').prototype}
228
+ */
229
+ this.$db;
230
+
231
+ /**
232
+ * @type {typeof import('./logger')}
233
+ */
234
+ this.$logger;
235
+
236
+ /**
237
+ * @type {typeof import('./middleware').prototype}
238
+ */
239
+ this.$middleware;
240
+
241
+ /**
242
+ * @type {typeof import('./model').prototype}
243
+ */
244
+ this.$model;
245
+
246
+ /**
247
+ * @type {typeof import('./pagination').prototype}
248
+ */
249
+ this.$pagination;
250
+
251
+ /**
252
+ * @type {typeof import('./response').prototype}
253
+ */
254
+ this.$response;
255
+
256
+ /**
257
+ * @type {typeof import('./upload').prototype}
258
+ */
259
+ this.$upload;
260
+
261
+ /**
262
+ * @type {typeof import('./url').prototype}
263
+ */
264
+ this.$url;
265
+
266
+ /**
267
+ * @type {typeof import('./view').prototype}
268
+ */
269
+ this.$view;
270
+
271
+ /**
272
+ * @type {Utils}
273
+ */
274
+ this.$utils;
275
+
276
+ /**
277
+ * @type {import('./config')}
278
+ */
279
+ this.$config;
280
+ }
281
+ }
282
+
283
+ /**
284
+ * @module Types
285
+ */
286
+ module.exports = Ctx;
package/lib/upload.js CHANGED
@@ -2,41 +2,85 @@ const pt = require('path');
2
2
  const fs = require('fs');
3
3
  const utils = require('./utils/utils');
4
4
  const Context = require('./context');
5
-
5
+ const {app: cfg_app} = require('./config');
6
+
7
+ /**
8
+ * @typedef {import('formidable').Files} Files
9
+ * @typedef {import('formidable').File} File
10
+ * @typedef {import('./types').UploadData} UploadData
11
+ * @typedef {import('./types').ValidateRule} ValidateRule
12
+ */
13
+
14
+ /**
15
+ * @extends Context
16
+ */
6
17
  class Upload extends Context
7
18
  {
19
+ /**
20
+ * 设置上传文件
21
+ * @public
22
+ * @param {(string|File)} file
23
+ * @returns {this}
24
+ */
8
25
  file(file) {
9
- this._file = typeof file == 'string' ? this.getFile(file) : file;
26
+ /**
27
+ * @private
28
+ */
29
+ this._file = /** @type {File} */ (typeof file == 'string' ? this.getFile(file) : file);
10
30
  return this;
11
31
  }
12
32
 
33
+ /**
34
+ * 设置检查规则
35
+ * @public
36
+ * @param {ValidateRule} [rule]
37
+ * @returns {this}
38
+ */
13
39
  validate(rule={}) {
40
+ /**
41
+ * @private
42
+ */
14
43
  this._rule = rule;
15
44
  return this;
16
45
  }
17
46
 
47
+ /**
48
+ * 设置存储文件名或函数
49
+ * @public
50
+ * @param {(string|function)} [name]
51
+ * @returns {this}
52
+ */
18
53
  rule(name) {
54
+ /**
55
+ * @private
56
+ */
19
57
  this._name = name;
20
58
  return this;
21
59
  }
22
60
 
61
+ /**
62
+ * 保存文件到目录
63
+ * @public
64
+ * @param {string} [dir]
65
+ * @returns {Promise<(boolean|UploadData)>}
66
+ */
23
67
  async save(dir) {
24
68
  if(!this.check()) {
25
69
  return false;
26
70
  }
27
71
 
28
72
  let savename = '';
29
- if(this._name || this._name === 0) {
73
+ if(this._name) {
30
74
  savename = (typeof this._name == 'function' ? this._name() : this._name) + '';
31
75
  } else {
32
- savename = utils.date.format('YYYY/mmdd/') + utils.md5(new Date().getTime() + Math.random().toString(36).substr(2));
76
+ savename = utils.date.format('YYYY/mmdd/') + utils.md5(Date.now() + Math.random().toString(36).substr(2));
33
77
  }
34
78
  if(!pt.extname(savename)) {
35
79
  savename += pt.extname(this._file.originalFilename);
36
80
  }
37
81
 
38
82
  try {
39
- const filePath = pt.join(this.$config.app.base_dir, dir, savename);
83
+ const filePath = pt.join(cfg_app.base_dir, dir, savename);
40
84
  await utils.fs.mkdirs(pt.dirname(filePath));
41
85
  const reader = fs.createReadStream(this._file.filepath);
42
86
  const writer = fs.createWriteStream(filePath);
@@ -65,14 +109,30 @@ class Upload extends Context
65
109
  }
66
110
  }
67
111
 
112
+ /**
113
+ * 获取上传文件
114
+ * @public
115
+ * @param {string} [name] - 为空时,获取所有上传文件
116
+ * @returns {(File|File[]|Files)}
117
+ */
68
118
  getFile(name) {
69
119
  return typeof name == 'string' ? this.ctx.request.files[name] : this.ctx.request.files;
70
120
  }
71
121
 
122
+ /**
123
+ * 获取错误信息
124
+ * @public
125
+ * @returns {string}
126
+ */
72
127
  getError() {
73
128
  return this._error;
74
129
  }
75
130
 
131
+ /**
132
+ * 检查上传文件
133
+ * @public
134
+ * @returns {boolean}
135
+ */
76
136
  check() {
77
137
  if(!this._file) {
78
138
  this._error = '上传文件为找到!';
@@ -104,6 +164,12 @@ class Upload extends Context
104
164
  return true;
105
165
  }
106
166
 
167
+ /**
168
+ * 检查上传文件后缀
169
+ * @public
170
+ * @param {(string|array)} ext
171
+ * @returns {boolean}
172
+ */
107
173
  checkExt(ext) {
108
174
  if(typeof ext == 'string') {
109
175
  ext = ext.split(',');
@@ -114,6 +180,12 @@ class Upload extends Context
114
180
  return true;
115
181
  }
116
182
 
183
+ /**
184
+ * 检查上传文件mimetype
185
+ * @public
186
+ * @param {(string|array)} type
187
+ * @returns {boolean}
188
+ */
117
189
  checkType(type) {
118
190
  if(typeof type == 'string') {
119
191
  type = type.split(',');
@@ -124,6 +196,11 @@ class Upload extends Context
124
196
  return true;
125
197
  }
126
198
 
199
+ /**
200
+ * 检查上传图片
201
+ * @public
202
+ * @returns {boolean}
203
+ */
127
204
  checkImg() {
128
205
  const fileExt = pt.extname(this._file.originalFilename).slice(1).toLowerCase();
129
206
  const fileType = this._file.mimetype.toLowerCase().split('/');