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.
- package/CHANGELOG.md +13 -0
- package/LICENSE +21 -21
- package/README.md +22 -551
- package/jj.js +14 -8
- package/jsconfig.json +9 -0
- package/jsdoc.conf.js +17 -0
- package/lib/app.js +53 -48
- package/lib/cache.js +118 -65
- package/lib/config.js +98 -94
- package/lib/context.js +18 -10
- package/lib/controller.js +34 -8
- package/lib/cookie.js +82 -40
- package/lib/ctx.js +9 -0
- package/lib/db.js +352 -11
- package/lib/loader.js +10 -4
- package/lib/logger.js +116 -47
- package/lib/middleware.js +58 -26
- package/lib/model.js +54 -1
- package/lib/pagination.js +221 -182
- package/lib/response.js +62 -8
- package/lib/router.js +3 -3
- package/lib/tpl/exception.js +64 -64
- package/lib/tpl/jump.js +40 -40
- package/lib/types.js +286 -0
- package/lib/upload.js +82 -5
- package/lib/url.js +28 -8
- package/lib/utils/date.js +50 -39
- package/lib/utils/error.js +8 -4
- package/lib/utils/fs.js +77 -77
- package/lib/utils/md5.js +9 -7
- package/lib/utils/str.js +20 -10
- package/lib/utils/utils.js +16 -10
- package/lib/view.js +79 -12
- package/package.json +8 -6
package/lib/cookie.js
CHANGED
|
@@ -1,41 +1,83 @@
|
|
|
1
|
-
const {cookie: cfg_cookie} = require('./config');
|
|
2
|
-
const Context = require('./context');
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
1
|
+
const {cookie: cfg_cookie} = require('./config');
|
|
2
|
+
const Context = require('./context');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @extends Context
|
|
6
|
+
*/
|
|
7
|
+
class Cookie extends Context
|
|
8
|
+
{
|
|
9
|
+
/**
|
|
10
|
+
* 设置cookie
|
|
11
|
+
* @public
|
|
12
|
+
* @param {string} key
|
|
13
|
+
* @param {(string|null)} [value]
|
|
14
|
+
* @param {import('cookies').SetOption} [options]
|
|
15
|
+
* @returns {this}
|
|
16
|
+
*/
|
|
17
|
+
set(key, value, options) {
|
|
18
|
+
this.ctx.cookies.set(key, value, {...cfg_cookie, ...options});
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 获取cookie
|
|
24
|
+
* @public
|
|
25
|
+
* @param {string} [key] - 为空,则获取所有cookie
|
|
26
|
+
* @param {import('cookies').GetOption} [options]
|
|
27
|
+
* @returns {string}
|
|
28
|
+
*/
|
|
29
|
+
get(key, options) {
|
|
30
|
+
if(key === undefined) {
|
|
31
|
+
return this.all();
|
|
32
|
+
}
|
|
33
|
+
return this.ctx.cookies.get(key, options);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 删除或清理cookie
|
|
38
|
+
* @public
|
|
39
|
+
* @param {*} [key] - 为空则清理所有cookie
|
|
40
|
+
* @returns {this}
|
|
41
|
+
*/
|
|
42
|
+
delete(key) {
|
|
43
|
+
if(key === undefined) {
|
|
44
|
+
this.clear();
|
|
45
|
+
} else {
|
|
46
|
+
this.ctx.cookies.set(key, '', {maxAge: 0});
|
|
47
|
+
}
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 获取所有cookie
|
|
53
|
+
* @public
|
|
54
|
+
* @returns {object}
|
|
55
|
+
*/
|
|
56
|
+
all() {
|
|
57
|
+
const cookies = {};
|
|
58
|
+
this.keys().forEach(key => cookies[key] = this.get(key));
|
|
59
|
+
return cookies;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 清理所有cookie
|
|
64
|
+
* @public
|
|
65
|
+
* @returns {this}
|
|
66
|
+
*/
|
|
67
|
+
clear() {
|
|
68
|
+
this.keys().forEach(key => this.delete(key));
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 获取所有cookie key
|
|
74
|
+
* @public
|
|
75
|
+
* @returns {array}
|
|
76
|
+
*/
|
|
77
|
+
keys() {
|
|
78
|
+
const cookie_header = this.ctx.request.headers.cookie || '';
|
|
79
|
+
return cookie_header ? cookie_header.split(';').map(value => value.split('=')[0].trim()) : [];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
41
83
|
module.exports = Cookie;
|
package/lib/ctx.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
1
2
|
const loader = require('./loader');
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {typeof import('./types')} Ctx
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @class Ctx
|
|
10
|
+
* @type {Ctx}
|
|
11
|
+
*/
|
|
3
12
|
const Ctx = new Proxy(class {}, {
|
|
4
13
|
construct() {
|
|
5
14
|
return new Proxy({__proto__: arguments[2].prototype}, {
|