@mx-space/api-client 0.3.7 → 0.4.3
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/build/index.cjs.js +900 -899
- package/build/index.cjs.js.map +1 -1
- package/build/index.cjs.min.js +1 -1
- package/build/index.cjs.min.js.map +1 -1
- package/build/index.d.ts +70 -69
- package/build/index.esm.js +900 -899
- package/build/index.esm.js.map +1 -1
- package/build/index.esm.min.js +1 -1
- package/build/index.esm.min.js.map +1 -1
- package/build/index.umd.js +1179 -1178
- package/build/index.umd.js.map +1 -1
- package/build/index.umd.min.js +1 -1
- package/build/index.umd.min.js.map +1 -1
- package/esm/adaptors/axios.js +2 -2
- package/esm/adaptors/axios.js.map +1 -1
- package/esm/adaptors/umi-request.js +2 -2
- package/esm/adaptors/umi-request.js.map +1 -1
- package/esm/{core/controllers → controllers}/aggregate.d.ts +5 -5
- package/esm/{core/controllers → controllers}/aggregate.js +2 -2
- package/esm/controllers/aggregate.js.map +1 -0
- package/esm/{core/controllers → controllers}/base.d.ts +3 -3
- package/esm/{core/controllers → controllers}/base.js +1 -1
- package/esm/controllers/base.js.map +1 -0
- package/{lib/core → esm}/controllers/category.d.ts +5 -5
- package/esm/{core/controllers → controllers}/category.js +4 -4
- package/esm/controllers/category.js.map +1 -0
- package/{lib/core → esm}/controllers/comment.d.ts +6 -6
- package/esm/{core/controllers → controllers}/comment.js +1 -1
- package/esm/controllers/comment.js.map +1 -0
- package/esm/{core/controllers/all.d.ts → controllers/index.d.ts} +0 -0
- package/esm/{core/controllers/all.js → controllers/index.js} +1 -1
- package/esm/controllers/index.js.map +1 -0
- package/{lib/core → esm}/controllers/link.d.ts +2 -2
- package/esm/{core/controllers → controllers}/link.js +1 -1
- package/esm/controllers/link.js.map +1 -0
- package/{lib/core → esm}/controllers/note.d.ts +6 -6
- package/esm/{core/controllers → controllers}/note.js +1 -1
- package/esm/controllers/note.js.map +1 -0
- package/esm/{core/controllers → controllers}/page.d.ts +9 -9
- package/esm/{core/controllers → controllers}/page.js +1 -1
- package/esm/controllers/page.js.map +1 -0
- package/esm/{core/controllers → controllers}/post.d.ts +6 -6
- package/esm/{core/controllers → controllers}/post.js +1 -1
- package/esm/controllers/post.js.map +1 -0
- package/{lib/core → esm}/controllers/project.d.ts +2 -2
- package/esm/{core/controllers → controllers}/project.js +1 -1
- package/esm/controllers/project.js.map +1 -0
- package/{lib/core → esm}/controllers/recently.d.ts +7 -7
- package/esm/{core/controllers → controllers}/recently.js +1 -1
- package/esm/controllers/recently.js.map +1 -0
- package/{lib/core → esm}/controllers/say.d.ts +5 -5
- package/esm/{core/controllers → controllers}/say.js +1 -1
- package/esm/controllers/say.js.map +1 -0
- package/esm/{core/controllers → controllers}/search.d.ts +6 -6
- package/esm/{core/controllers → controllers}/search.js +1 -1
- package/esm/controllers/search.js.map +1 -0
- package/esm/controllers/snippet.d.ts +18 -0
- package/esm/{core/controllers → controllers}/snippet.js +1 -1
- package/esm/controllers/snippet.js.map +1 -0
- package/esm/controllers/user.d.ts +28 -0
- package/esm/{core/controllers → controllers}/user.js +1 -1
- package/esm/controllers/user.js.map +1 -0
- package/esm/core/attachRequest.js +6 -4
- package/esm/core/attachRequest.js.map +1 -1
- package/esm/core/client.d.ts +5 -5
- package/esm/core/client.js +4 -5
- package/esm/core/client.js.map +1 -1
- package/esm/core/define.d.ts +1 -1
- package/esm/core/index.d.ts +0 -1
- package/esm/core/index.js +0 -1
- package/esm/core/index.js.map +1 -1
- package/esm/{core/dtos → dtos}/comment.d.ts +0 -0
- package/esm/{core/dtos → dtos}/comment.js +0 -0
- package/esm/dtos/comment.js.map +1 -0
- package/esm/index.d.ts +2 -2
- package/esm/index.js +2 -2
- package/esm/index.js.map +1 -1
- package/esm/interfaces/instance.d.ts +2 -2
- package/esm/models/base.d.ts +6 -0
- package/esm/models/note.d.ts +2 -2
- package/esm/models/page.d.ts +2 -6
- package/esm/models/page.js.map +1 -1
- package/esm/models/post.d.ts +2 -3
- package/esm/models/snippet.d.ts +4 -2
- package/esm/models/snippet.js +1 -0
- package/esm/models/snippet.js.map +1 -1
- package/lib/adaptors/axios.js +2 -2
- package/lib/adaptors/axios.js.map +1 -1
- package/lib/adaptors/umi-request.js +2 -2
- package/lib/adaptors/umi-request.js.map +1 -1
- package/lib/{core/controllers → controllers}/aggregate.d.ts +5 -5
- package/lib/{core/controllers → controllers}/aggregate.js +2 -2
- package/lib/controllers/aggregate.js.map +1 -0
- package/lib/{core/controllers → controllers}/base.d.ts +3 -3
- package/lib/{core/controllers → controllers}/base.js +1 -1
- package/lib/controllers/base.js.map +1 -0
- package/{esm/core → lib}/controllers/category.d.ts +5 -5
- package/lib/{core/controllers → controllers}/category.js +4 -4
- package/lib/controllers/category.js.map +1 -0
- package/{esm/core → lib}/controllers/comment.d.ts +6 -6
- package/lib/{core/controllers → controllers}/comment.js +1 -1
- package/lib/controllers/comment.js.map +1 -0
- package/lib/{core/controllers/all.d.ts → controllers/index.d.ts} +0 -0
- package/lib/{core/controllers/all.js → controllers/index.js} +1 -1
- package/lib/controllers/index.js.map +1 -0
- package/{esm/core → lib}/controllers/link.d.ts +2 -2
- package/lib/{core/controllers → controllers}/link.js +1 -1
- package/lib/controllers/link.js.map +1 -0
- package/{esm/core → lib}/controllers/note.d.ts +6 -6
- package/lib/{core/controllers → controllers}/note.js +1 -1
- package/lib/controllers/note.js.map +1 -0
- package/lib/{core/controllers → controllers}/page.d.ts +9 -9
- package/lib/{core/controllers → controllers}/page.js +1 -1
- package/lib/controllers/page.js.map +1 -0
- package/lib/{core/controllers → controllers}/post.d.ts +6 -6
- package/lib/{core/controllers → controllers}/post.js +1 -1
- package/lib/controllers/post.js.map +1 -0
- package/{esm/core → lib}/controllers/project.d.ts +2 -2
- package/lib/{core/controllers → controllers}/project.js +1 -1
- package/lib/controllers/project.js.map +1 -0
- package/{esm/core → lib}/controllers/recently.d.ts +7 -7
- package/lib/{core/controllers → controllers}/recently.js +1 -1
- package/lib/controllers/recently.js.map +1 -0
- package/{esm/core → lib}/controllers/say.d.ts +5 -5
- package/lib/{core/controllers → controllers}/say.js +1 -1
- package/lib/controllers/say.js.map +1 -0
- package/lib/{core/controllers → controllers}/search.d.ts +6 -6
- package/lib/{core/controllers → controllers}/search.js +1 -1
- package/lib/controllers/search.js.map +1 -0
- package/lib/controllers/snippet.d.ts +18 -0
- package/lib/{core/controllers → controllers}/snippet.js +1 -1
- package/lib/controllers/snippet.js.map +1 -0
- package/lib/controllers/user.d.ts +28 -0
- package/lib/{core/controllers → controllers}/user.js +1 -1
- package/lib/controllers/user.js.map +1 -0
- package/lib/core/attachRequest.js +6 -4
- package/lib/core/attachRequest.js.map +1 -1
- package/lib/core/client.d.ts +5 -5
- package/lib/core/client.js +4 -5
- package/lib/core/client.js.map +1 -1
- package/lib/core/define.d.ts +1 -1
- package/lib/core/index.d.ts +0 -1
- package/lib/core/index.js +0 -1
- package/lib/core/index.js.map +1 -1
- package/lib/{core/dtos → dtos}/comment.d.ts +0 -0
- package/lib/{core/dtos → dtos}/comment.js +0 -0
- package/lib/dtos/comment.js.map +1 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -4
- package/lib/index.js.map +1 -1
- package/lib/interfaces/instance.d.ts +2 -2
- package/lib/models/base.d.ts +6 -0
- package/lib/models/note.d.ts +2 -2
- package/lib/models/page.d.ts +2 -6
- package/lib/models/page.js.map +1 -1
- package/lib/models/post.d.ts +2 -3
- package/lib/models/snippet.d.ts +4 -2
- package/lib/models/snippet.js +1 -0
- package/lib/models/snippet.js.map +1 -1
- package/package.json +9 -9
- package/esm/core/controllers/aggregate.js.map +0 -1
- package/esm/core/controllers/all.js.map +0 -1
- package/esm/core/controllers/base.js.map +0 -1
- package/esm/core/controllers/category.js.map +0 -1
- package/esm/core/controllers/comment.js.map +0 -1
- package/esm/core/controllers/index.d.ts +0 -1
- package/esm/core/controllers/index.js +0 -2
- package/esm/core/controllers/index.js.map +0 -1
- package/esm/core/controllers/link.js.map +0 -1
- package/esm/core/controllers/note.js.map +0 -1
- package/esm/core/controllers/page.js.map +0 -1
- package/esm/core/controllers/post.js.map +0 -1
- package/esm/core/controllers/project.js.map +0 -1
- package/esm/core/controllers/recently.js.map +0 -1
- package/esm/core/controllers/say.js.map +0 -1
- package/esm/core/controllers/search.js.map +0 -1
- package/esm/core/controllers/snippet.d.ts +0 -18
- package/esm/core/controllers/snippet.js.map +0 -1
- package/esm/core/controllers/user.d.ts +0 -28
- package/esm/core/controllers/user.js.map +0 -1
- package/esm/core/dtos/comment.js.map +0 -1
- package/lib/core/controllers/aggregate.js.map +0 -1
- package/lib/core/controllers/all.js.map +0 -1
- package/lib/core/controllers/base.js.map +0 -1
- package/lib/core/controllers/category.js.map +0 -1
- package/lib/core/controllers/comment.js.map +0 -1
- package/lib/core/controllers/index.d.ts +0 -1
- package/lib/core/controllers/index.js +0 -14
- package/lib/core/controllers/index.js.map +0 -1
- package/lib/core/controllers/link.js.map +0 -1
- package/lib/core/controllers/note.js.map +0 -1
- package/lib/core/controllers/page.js.map +0 -1
- package/lib/core/controllers/post.js.map +0 -1
- package/lib/core/controllers/project.js.map +0 -1
- package/lib/core/controllers/recently.js.map +0 -1
- package/lib/core/controllers/say.js.map +0 -1
- package/lib/core/controllers/search.js.map +0 -1
- package/lib/core/controllers/snippet.d.ts +0 -18
- package/lib/core/controllers/snippet.js.map +0 -1
- package/lib/core/controllers/user.d.ts +0 -28
- package/lib/core/controllers/user.js.map +0 -1
- package/lib/core/dtos/comment.js.map +0 -1
package/build/index.esm.js
CHANGED
|
@@ -1,144 +1,743 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
isObject$1(value) &&
|
|
9
|
-
!(value instanceof RegExp) &&
|
|
10
|
-
!(value instanceof Error) &&
|
|
11
|
-
!(value instanceof Date);
|
|
12
|
-
|
|
13
|
-
const mapObject = (object, mapper, options, isSeen = new WeakMap()) => {
|
|
14
|
-
options = {
|
|
15
|
-
deep: false,
|
|
16
|
-
target: {},
|
|
17
|
-
...options
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
if (isSeen.has(object)) {
|
|
21
|
-
return isSeen.get(object);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
isSeen.set(object, options.target);
|
|
25
|
-
|
|
26
|
-
const {target} = options;
|
|
27
|
-
delete options.target;
|
|
28
|
-
|
|
29
|
-
const mapArray = array => array.map(element => isObjectCustom(element) ? mapObject(element, mapper, options, isSeen) : element);
|
|
30
|
-
if (Array.isArray(object)) {
|
|
31
|
-
return mapArray(object);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
for (const [key, value] of Object.entries(object)) {
|
|
35
|
-
const mapResult = mapper(key, value, object);
|
|
36
|
-
|
|
37
|
-
if (mapResult === mapObjectSkip) {
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let [newKey, newValue, {shouldRecurse = true} = {}] = mapResult;
|
|
42
|
-
|
|
43
|
-
// Drop `__proto__` keys.
|
|
44
|
-
if (newKey === '__proto__') {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (options.deep && shouldRecurse && isObjectCustom(newValue)) {
|
|
49
|
-
newValue = Array.isArray(newValue) ?
|
|
50
|
-
mapArray(newValue) :
|
|
51
|
-
mapObject(newValue, mapper, options, isSeen);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
target[newKey] = newValue;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return target;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
mapObj$1.exports = (object, mapper, options) => {
|
|
61
|
-
if (!isObject$1(object)) {
|
|
62
|
-
throw new TypeError(`Expected an object, got \`${object}\` (${typeof object})`);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return mapObject(object, mapper, options);
|
|
1
|
+
const isPlainObject = (obj) => typeof obj === 'object' &&
|
|
2
|
+
Object.prototype.toString.call(obj) === '[object Object]';
|
|
3
|
+
const sortOrderToNumber = (order) => {
|
|
4
|
+
return ({
|
|
5
|
+
asc: 1,
|
|
6
|
+
desc: -1,
|
|
7
|
+
}[order] || 1);
|
|
66
8
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
isLastLastCharUpper = isLastCharUpper;
|
|
84
|
-
isLastCharUpper = true;
|
|
85
|
-
i++;
|
|
86
|
-
} else if (isLastCharUpper && isLastLastCharUpper && /[\p{Ll}]/u.test(character)) {
|
|
87
|
-
string = string.slice(0, i - 1) + '-' + string.slice(i - 1);
|
|
88
|
-
isLastLastCharUpper = isLastCharUpper;
|
|
89
|
-
isLastCharUpper = false;
|
|
90
|
-
isLastCharLower = true;
|
|
91
|
-
} else {
|
|
92
|
-
isLastCharLower = character.toLocaleLowerCase(locale) === character && character.toLocaleUpperCase(locale) !== character;
|
|
93
|
-
isLastLastCharUpper = isLastCharUpper;
|
|
94
|
-
isLastCharUpper = character.toLocaleUpperCase(locale) === character && character.toLocaleLowerCase(locale) !== character;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return string;
|
|
9
|
+
const destructureData = (payload) => {
|
|
10
|
+
if (typeof payload !== 'object') {
|
|
11
|
+
return payload;
|
|
12
|
+
}
|
|
13
|
+
if (payload === null) {
|
|
14
|
+
return payload;
|
|
15
|
+
}
|
|
16
|
+
const data = payload.data;
|
|
17
|
+
const dataIsPlainObject = Object.prototype.toString.call(data) === '[object Object]';
|
|
18
|
+
if (dataIsPlainObject && Object.keys(payload).length === 1) {
|
|
19
|
+
const d = Object.assign({}, data);
|
|
20
|
+
// attach raw onto new data
|
|
21
|
+
attachRawFromOneToAnthor(payload, d);
|
|
22
|
+
return d;
|
|
23
|
+
}
|
|
24
|
+
return payload;
|
|
99
25
|
};
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
26
|
+
const attachRawFromOneToAnthor = (from, to) => {
|
|
27
|
+
if (!from) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
from.$raw &&
|
|
31
|
+
Object.defineProperty(to, '$raw', {
|
|
32
|
+
value: Object.assign({}, from.$raw),
|
|
33
|
+
enumerable: false,
|
|
34
|
+
});
|
|
35
|
+
from.$request &&
|
|
36
|
+
Object.defineProperty(to, '$request', {
|
|
37
|
+
value: Object.assign({}, from.$request),
|
|
38
|
+
enumerable: false,
|
|
39
|
+
});
|
|
103
40
|
};
|
|
104
41
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
42
|
+
// @ts-nocheck
|
|
43
|
+
// @copy: https://github.com/sindresorhus/auto-bind/blob/main/index.js
|
|
44
|
+
// Gets all non-builtin properties up the prototype chain.
|
|
45
|
+
const getAllProperties = (object) => {
|
|
46
|
+
const properties = new Set();
|
|
47
|
+
do {
|
|
48
|
+
for (const key of Reflect.ownKeys(object)) {
|
|
49
|
+
properties.add([object, key]);
|
|
50
|
+
}
|
|
51
|
+
} while ((object = Reflect.getPrototypeOf(object)) &&
|
|
52
|
+
object !== Object.prototype);
|
|
53
|
+
return properties;
|
|
108
54
|
};
|
|
55
|
+
function autoBind(self, { include, exclude } = {}) {
|
|
56
|
+
const filter = (key) => {
|
|
57
|
+
const match = (pattern) => typeof pattern === 'string' ? key === pattern : pattern.test(key);
|
|
58
|
+
if (include) {
|
|
59
|
+
return include.some(match);
|
|
60
|
+
}
|
|
61
|
+
if (exclude) {
|
|
62
|
+
return !exclude.some(match);
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
};
|
|
66
|
+
for (const [object, key] of getAllProperties(self.constructor.prototype)) {
|
|
67
|
+
if (key === 'constructor' || !filter(key)) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(object, key);
|
|
71
|
+
if (descriptor && typeof descriptor.value === 'function') {
|
|
72
|
+
self[key] = self[key].bind(self);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return self;
|
|
76
|
+
}
|
|
109
77
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
78
|
+
class AggregateController {
|
|
79
|
+
constructor(client) {
|
|
80
|
+
this.client = client;
|
|
81
|
+
this.base = 'aggregate';
|
|
82
|
+
this.name = 'aggregate';
|
|
83
|
+
autoBind(this);
|
|
84
|
+
}
|
|
85
|
+
get proxy() {
|
|
86
|
+
return this.client.proxy(this.base);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 获取聚合数据
|
|
90
|
+
*/
|
|
91
|
+
getAggregateData() {
|
|
92
|
+
return this.proxy.get();
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 获取最新发布的内容
|
|
96
|
+
*/
|
|
97
|
+
getTop(size = 5) {
|
|
98
|
+
return this.proxy.top.get({ params: { size } });
|
|
99
|
+
}
|
|
100
|
+
getTimeline(options) {
|
|
101
|
+
const { sort, type, year } = options || {};
|
|
102
|
+
return this.proxy.timeline.get({
|
|
103
|
+
params: {
|
|
104
|
+
sort: sort && sortOrderToNumber(sort),
|
|
105
|
+
type,
|
|
106
|
+
year,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 获取聚合数据统计
|
|
112
|
+
*/
|
|
113
|
+
getStat() {
|
|
114
|
+
return this.proxy.stat.get();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
136
117
|
|
|
137
|
-
|
|
118
|
+
class RequestError extends Error {
|
|
119
|
+
constructor(message, status, path, raw) {
|
|
120
|
+
super(message);
|
|
121
|
+
this.status = status;
|
|
122
|
+
this.path = path;
|
|
123
|
+
this.raw = raw;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
138
126
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
127
|
+
var CategoryType;
|
|
128
|
+
(function (CategoryType) {
|
|
129
|
+
CategoryType[CategoryType["Category"] = 0] = "Category";
|
|
130
|
+
CategoryType[CategoryType["Tag"] = 1] = "Tag";
|
|
131
|
+
})(CategoryType || (CategoryType = {}));
|
|
132
|
+
|
|
133
|
+
class CategoryController {
|
|
134
|
+
constructor(client) {
|
|
135
|
+
this.client = client;
|
|
136
|
+
this.name = 'category';
|
|
137
|
+
this.base = 'categories';
|
|
138
|
+
autoBind(this);
|
|
139
|
+
}
|
|
140
|
+
get proxy() {
|
|
141
|
+
return this.client.proxy(this.base);
|
|
142
|
+
}
|
|
143
|
+
getAllCategories() {
|
|
144
|
+
return this.proxy.get({
|
|
145
|
+
params: {
|
|
146
|
+
type: CategoryType.Category,
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
getAllTags() {
|
|
151
|
+
return this.proxy.get({
|
|
152
|
+
params: {
|
|
153
|
+
type: CategoryType.Tag,
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
async getCategoryDetail(ids) {
|
|
158
|
+
if (typeof ids === 'string') {
|
|
159
|
+
const data = await this.proxy.get({
|
|
160
|
+
params: {
|
|
161
|
+
ids: ids,
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
const result = Object.values(data.entries)[0];
|
|
165
|
+
attachRawFromOneToAnthor(data, result);
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
else if (Array.isArray(ids)) {
|
|
169
|
+
const data = await this.proxy.get({
|
|
170
|
+
params: {
|
|
171
|
+
ids: ids.join(','),
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
const entries = data === null || data === void 0 ? void 0 : data.entries;
|
|
175
|
+
if (!entries) {
|
|
176
|
+
throw new RequestError('data structure error', 500, data.$request.path, data);
|
|
177
|
+
}
|
|
178
|
+
const map = new Map(Object.entries(entries).map(([id, value]) => [id.toLowerCase(), value]));
|
|
179
|
+
attachRawFromOneToAnthor(data, map);
|
|
180
|
+
return map;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async getCategoryByIdOrSlug(idOrSlug) {
|
|
184
|
+
const res = await this.proxy(idOrSlug).get();
|
|
185
|
+
return destructureData(res);
|
|
186
|
+
}
|
|
187
|
+
async getTagByName(name) {
|
|
188
|
+
const res = await this.proxy(name).get({
|
|
189
|
+
params: {
|
|
190
|
+
tag: 1,
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
return res;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
class CommentController {
|
|
198
|
+
constructor(client) {
|
|
199
|
+
this.client = client;
|
|
200
|
+
this.base = 'comments';
|
|
201
|
+
this.name = 'comment';
|
|
202
|
+
autoBind(this);
|
|
203
|
+
}
|
|
204
|
+
get proxy() {
|
|
205
|
+
return this.client.proxy(this.base);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* 根据 comment id 获取评论, 包括子评论
|
|
209
|
+
*/
|
|
210
|
+
getById(id) {
|
|
211
|
+
return this.proxy(id).get();
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* 获取文章的评论列表
|
|
215
|
+
* @param refId 文章 Id
|
|
216
|
+
*/
|
|
217
|
+
getByRefId(refId, pagination = {}) {
|
|
218
|
+
const { page, size } = pagination;
|
|
219
|
+
return this.proxy.ref(refId).get({
|
|
220
|
+
params: { page: page || 1, size: size || 10 },
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* 评论
|
|
225
|
+
*/
|
|
226
|
+
comment(refId, data) {
|
|
227
|
+
return this.proxy(refId).post({
|
|
228
|
+
data,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* 回复评论
|
|
233
|
+
*/
|
|
234
|
+
reply(commentId, data) {
|
|
235
|
+
return this.proxy.reply(commentId).post({
|
|
236
|
+
data,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
class BaseCrudController {
|
|
242
|
+
constructor(client) {
|
|
243
|
+
this.client = client;
|
|
244
|
+
autoBind(this);
|
|
245
|
+
}
|
|
246
|
+
get proxy() {
|
|
247
|
+
return this.client.proxy(this.base);
|
|
248
|
+
}
|
|
249
|
+
getById(id) {
|
|
250
|
+
return this.proxy(id).get();
|
|
251
|
+
}
|
|
252
|
+
getAll() {
|
|
253
|
+
return this.proxy.all.get();
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* 带分页的查询
|
|
257
|
+
* @param page
|
|
258
|
+
* @param perPage
|
|
259
|
+
*/
|
|
260
|
+
getAllPaginated(page, perPage) {
|
|
261
|
+
return this.proxy.get({
|
|
262
|
+
params: { page, size: perPage },
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
class LinkController extends BaseCrudController {
|
|
268
|
+
constructor(client) {
|
|
269
|
+
super(client);
|
|
270
|
+
this.client = client;
|
|
271
|
+
this.name = 'link';
|
|
272
|
+
this.base = 'links';
|
|
273
|
+
autoBind(this);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
class NoteController {
|
|
278
|
+
constructor(client) {
|
|
279
|
+
this.client = client;
|
|
280
|
+
this.base = 'notes';
|
|
281
|
+
this.name = 'note';
|
|
282
|
+
autoBind(this);
|
|
283
|
+
}
|
|
284
|
+
get proxy() {
|
|
285
|
+
return this.client.proxy(this.base);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* 最新日记
|
|
289
|
+
*/
|
|
290
|
+
getLatest() {
|
|
291
|
+
return this.proxy.latest.get();
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* 获取一篇日记
|
|
295
|
+
* @param id id | nid
|
|
296
|
+
* @param password 访问密码
|
|
297
|
+
*/
|
|
298
|
+
getNoteById(id, password) {
|
|
299
|
+
if (typeof id === 'number') {
|
|
300
|
+
return this.proxy.nid(id.toString()).get({
|
|
301
|
+
params: { password },
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
return this.proxy(id).get({ params: { password } });
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* 日记列表分页
|
|
310
|
+
*/
|
|
311
|
+
getList(page = 1, perPage = 10, options = {}) {
|
|
312
|
+
const { select, sortBy, sortOrder, year } = options;
|
|
313
|
+
return this.proxy.get({
|
|
314
|
+
params: {
|
|
315
|
+
page,
|
|
316
|
+
size: perPage,
|
|
317
|
+
select: select === null || select === void 0 ? void 0 : select.join(' '),
|
|
318
|
+
sortBy,
|
|
319
|
+
sortOrder,
|
|
320
|
+
year,
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* 获取当前日记的上下各 n / 2 篇日记
|
|
326
|
+
*/
|
|
327
|
+
getMiddleList(id, size = 5) {
|
|
328
|
+
return this.proxy.list(id).get({
|
|
329
|
+
params: { size },
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* 喜欢这篇日记
|
|
334
|
+
*/
|
|
335
|
+
likeIt(id) {
|
|
336
|
+
return this.proxy.like(id).get();
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
class PageController {
|
|
341
|
+
constructor(client) {
|
|
342
|
+
this.client = client;
|
|
343
|
+
this.base = 'pages';
|
|
344
|
+
this.name = 'page';
|
|
345
|
+
autoBind(this);
|
|
346
|
+
}
|
|
347
|
+
get proxy() {
|
|
348
|
+
return this.client.proxy(this.base);
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* 页面列表
|
|
352
|
+
*/
|
|
353
|
+
getList(page = 1, perPage = 10, options = {}) {
|
|
354
|
+
const { select, sortBy, sortOrder } = options;
|
|
355
|
+
return this.proxy.get({
|
|
356
|
+
params: {
|
|
357
|
+
page,
|
|
358
|
+
size: perPage,
|
|
359
|
+
select: select === null || select === void 0 ? void 0 : select.join(' '),
|
|
360
|
+
sortBy,
|
|
361
|
+
sortOrder,
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* 页面详情
|
|
367
|
+
*/
|
|
368
|
+
getById(id) {
|
|
369
|
+
return this.proxy(id).get();
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* 根据路径获取页面
|
|
373
|
+
* @param slug 路径
|
|
374
|
+
* @returns
|
|
375
|
+
*/
|
|
376
|
+
getBySlug(slug) {
|
|
377
|
+
return this.proxy.slug(slug).get({});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
class PostController {
|
|
382
|
+
constructor(client) {
|
|
383
|
+
this.client = client;
|
|
384
|
+
this.base = 'posts';
|
|
385
|
+
this.name = 'post';
|
|
386
|
+
autoBind(this);
|
|
387
|
+
}
|
|
388
|
+
get proxy() {
|
|
389
|
+
return this.client.proxy(this.base);
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* 获取文章列表分页
|
|
393
|
+
* @param page
|
|
394
|
+
* @param perPage
|
|
395
|
+
* @returns
|
|
396
|
+
*/
|
|
397
|
+
getList(page = 1, perPage = 10, options = {}) {
|
|
398
|
+
const { select, sortBy, sortOrder, year } = options;
|
|
399
|
+
return this.proxy.get({
|
|
400
|
+
params: {
|
|
401
|
+
page,
|
|
402
|
+
size: perPage,
|
|
403
|
+
select: select === null || select === void 0 ? void 0 : select.join(' '),
|
|
404
|
+
sortBy,
|
|
405
|
+
sortOrder,
|
|
406
|
+
year,
|
|
407
|
+
},
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
getPost(idOrCategoryName, slug) {
|
|
411
|
+
if (arguments.length == 1) {
|
|
412
|
+
return this.proxy(idOrCategoryName).get();
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
return this.proxy(idOrCategoryName)(slug).get();
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* 获取最新的文章
|
|
420
|
+
*/
|
|
421
|
+
getLatest() {
|
|
422
|
+
return this.proxy.latest.get();
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* 点赞
|
|
426
|
+
*/
|
|
427
|
+
thumbsUp(id) {
|
|
428
|
+
return this.proxy('_thumbs-up').get({ params: { id } });
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
class ProjectController extends BaseCrudController {
|
|
433
|
+
constructor(client) {
|
|
434
|
+
super(client);
|
|
435
|
+
this.client = client;
|
|
436
|
+
this.base = 'projects';
|
|
437
|
+
this.name = 'project';
|
|
438
|
+
autoBind(this);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
class RecentlyController {
|
|
443
|
+
constructor(client) {
|
|
444
|
+
this.client = client;
|
|
445
|
+
this.base = 'recently';
|
|
446
|
+
this.name = 'recently';
|
|
447
|
+
autoBind(this);
|
|
448
|
+
}
|
|
449
|
+
get proxy() {
|
|
450
|
+
return this.client.proxy(this.base);
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* 获取最新一条
|
|
454
|
+
*/
|
|
455
|
+
getLatestOne() {
|
|
456
|
+
return this.proxy.latest.get();
|
|
457
|
+
}
|
|
458
|
+
getAll() {
|
|
459
|
+
return this.proxy.all.get();
|
|
460
|
+
}
|
|
461
|
+
getList(before, after, size) {
|
|
462
|
+
if (!before && !after) {
|
|
463
|
+
throw new Error('you can only choose `before` or `after`');
|
|
464
|
+
}
|
|
465
|
+
return this.proxy.get({
|
|
466
|
+
params: {
|
|
467
|
+
before,
|
|
468
|
+
after,
|
|
469
|
+
size,
|
|
470
|
+
},
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
class SayController extends BaseCrudController {
|
|
476
|
+
constructor(client) {
|
|
477
|
+
super(client);
|
|
478
|
+
this.client = client;
|
|
479
|
+
this.base = 'says';
|
|
480
|
+
this.name = 'say';
|
|
481
|
+
autoBind(this);
|
|
482
|
+
}
|
|
483
|
+
get proxy() {
|
|
484
|
+
return this.client.proxy(this.base);
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* 获取随机一条
|
|
488
|
+
*/
|
|
489
|
+
getRandom() {
|
|
490
|
+
return this.proxy.random.get();
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
class SearchController {
|
|
495
|
+
constructor(client) {
|
|
496
|
+
this.client = client;
|
|
497
|
+
this.base = 'search';
|
|
498
|
+
this.name = 'search';
|
|
499
|
+
autoBind(this);
|
|
500
|
+
}
|
|
501
|
+
get proxy() {
|
|
502
|
+
return this.client.proxy(this.base);
|
|
503
|
+
}
|
|
504
|
+
search(type, keyword, options = {}) {
|
|
505
|
+
return this.proxy(type).get({
|
|
506
|
+
params: Object.assign({ keyword }, options),
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* 从 algolya 搜索
|
|
511
|
+
* https://www.algolia.com/doc/api-reference/api-methods/search/
|
|
512
|
+
* @param keyword
|
|
513
|
+
* @param options
|
|
514
|
+
* @returns
|
|
515
|
+
*/
|
|
516
|
+
searchByAlgolia(keyword, options) {
|
|
517
|
+
return this.proxy('algolia').get({ params: Object.assign({ keyword }, options) });
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
class SnippetController {
|
|
522
|
+
constructor(client) {
|
|
523
|
+
this.client = client;
|
|
524
|
+
this.base = 'snippets';
|
|
525
|
+
this.name = 'snippet';
|
|
526
|
+
autoBind(this);
|
|
527
|
+
}
|
|
528
|
+
get proxy() {
|
|
529
|
+
return this.client.proxy(this.base);
|
|
530
|
+
}
|
|
531
|
+
getById(id) {
|
|
532
|
+
return this.proxy(id).get();
|
|
533
|
+
}
|
|
534
|
+
getByReferenceAndName(reference, name) {
|
|
535
|
+
return this.proxy(reference)(name).get();
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
class UserController {
|
|
540
|
+
constructor(client) {
|
|
541
|
+
this.client = client;
|
|
542
|
+
this.base = 'master';
|
|
543
|
+
this.name = 'user';
|
|
544
|
+
autoBind(this);
|
|
545
|
+
}
|
|
546
|
+
get proxy() {
|
|
547
|
+
return this.client.proxy(this.base);
|
|
548
|
+
}
|
|
549
|
+
getMasterInfo() {
|
|
550
|
+
return this.proxy.get();
|
|
551
|
+
}
|
|
552
|
+
login(username, password) {
|
|
553
|
+
return this.proxy.login.post({
|
|
554
|
+
data: {
|
|
555
|
+
username,
|
|
556
|
+
password,
|
|
557
|
+
},
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
checkTokenValid(token) {
|
|
561
|
+
return this.proxy.check_logged.get({
|
|
562
|
+
params: {
|
|
563
|
+
token,
|
|
564
|
+
},
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
const allControllers = [
|
|
570
|
+
AggregateController,
|
|
571
|
+
CategoryController,
|
|
572
|
+
CommentController,
|
|
573
|
+
LinkController,
|
|
574
|
+
NoteController,
|
|
575
|
+
PageController,
|
|
576
|
+
PostController,
|
|
577
|
+
ProjectController,
|
|
578
|
+
RecentlyController,
|
|
579
|
+
SayController,
|
|
580
|
+
SearchController,
|
|
581
|
+
SnippetController,
|
|
582
|
+
UserController,
|
|
583
|
+
];
|
|
584
|
+
const allContollerNames = [
|
|
585
|
+
'aggregate',
|
|
586
|
+
'category',
|
|
587
|
+
'comment',
|
|
588
|
+
'link',
|
|
589
|
+
'note',
|
|
590
|
+
'page',
|
|
591
|
+
'post',
|
|
592
|
+
'project',
|
|
593
|
+
'recently',
|
|
594
|
+
'say',
|
|
595
|
+
'search',
|
|
596
|
+
'snippet',
|
|
597
|
+
'user',
|
|
598
|
+
];
|
|
599
|
+
|
|
600
|
+
var mapObj$1 = {exports: {}};
|
|
601
|
+
|
|
602
|
+
const isObject$1 = value => typeof value === 'object' && value !== null;
|
|
603
|
+
const mapObjectSkip = Symbol('skip');
|
|
604
|
+
|
|
605
|
+
// Customized for this use-case
|
|
606
|
+
const isObjectCustom = value =>
|
|
607
|
+
isObject$1(value) &&
|
|
608
|
+
!(value instanceof RegExp) &&
|
|
609
|
+
!(value instanceof Error) &&
|
|
610
|
+
!(value instanceof Date);
|
|
611
|
+
|
|
612
|
+
const mapObject = (object, mapper, options, isSeen = new WeakMap()) => {
|
|
613
|
+
options = {
|
|
614
|
+
deep: false,
|
|
615
|
+
target: {},
|
|
616
|
+
...options
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
if (isSeen.has(object)) {
|
|
620
|
+
return isSeen.get(object);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
isSeen.set(object, options.target);
|
|
624
|
+
|
|
625
|
+
const {target} = options;
|
|
626
|
+
delete options.target;
|
|
627
|
+
|
|
628
|
+
const mapArray = array => array.map(element => isObjectCustom(element) ? mapObject(element, mapper, options, isSeen) : element);
|
|
629
|
+
if (Array.isArray(object)) {
|
|
630
|
+
return mapArray(object);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
for (const [key, value] of Object.entries(object)) {
|
|
634
|
+
const mapResult = mapper(key, value, object);
|
|
635
|
+
|
|
636
|
+
if (mapResult === mapObjectSkip) {
|
|
637
|
+
continue;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
let [newKey, newValue, {shouldRecurse = true} = {}] = mapResult;
|
|
641
|
+
|
|
642
|
+
// Drop `__proto__` keys.
|
|
643
|
+
if (newKey === '__proto__') {
|
|
644
|
+
continue;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
if (options.deep && shouldRecurse && isObjectCustom(newValue)) {
|
|
648
|
+
newValue = Array.isArray(newValue) ?
|
|
649
|
+
mapArray(newValue) :
|
|
650
|
+
mapObject(newValue, mapper, options, isSeen);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
target[newKey] = newValue;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
return target;
|
|
657
|
+
};
|
|
658
|
+
|
|
659
|
+
mapObj$1.exports = (object, mapper, options) => {
|
|
660
|
+
if (!isObject$1(object)) {
|
|
661
|
+
throw new TypeError(`Expected an object, got \`${object}\` (${typeof object})`);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
return mapObject(object, mapper, options);
|
|
665
|
+
};
|
|
666
|
+
|
|
667
|
+
mapObj$1.exports.mapObjectSkip = mapObjectSkip;
|
|
668
|
+
|
|
669
|
+
var camelcase = {exports: {}};
|
|
670
|
+
|
|
671
|
+
const preserveCamelCase = (string, locale) => {
|
|
672
|
+
let isLastCharLower = false;
|
|
673
|
+
let isLastCharUpper = false;
|
|
674
|
+
let isLastLastCharUpper = false;
|
|
675
|
+
|
|
676
|
+
for (let i = 0; i < string.length; i++) {
|
|
677
|
+
const character = string[i];
|
|
678
|
+
|
|
679
|
+
if (isLastCharLower && /[\p{Lu}]/u.test(character)) {
|
|
680
|
+
string = string.slice(0, i) + '-' + string.slice(i);
|
|
681
|
+
isLastCharLower = false;
|
|
682
|
+
isLastLastCharUpper = isLastCharUpper;
|
|
683
|
+
isLastCharUpper = true;
|
|
684
|
+
i++;
|
|
685
|
+
} else if (isLastCharUpper && isLastLastCharUpper && /[\p{Ll}]/u.test(character)) {
|
|
686
|
+
string = string.slice(0, i - 1) + '-' + string.slice(i - 1);
|
|
687
|
+
isLastLastCharUpper = isLastCharUpper;
|
|
688
|
+
isLastCharUpper = false;
|
|
689
|
+
isLastCharLower = true;
|
|
690
|
+
} else {
|
|
691
|
+
isLastCharLower = character.toLocaleLowerCase(locale) === character && character.toLocaleUpperCase(locale) !== character;
|
|
692
|
+
isLastLastCharUpper = isLastCharUpper;
|
|
693
|
+
isLastCharUpper = character.toLocaleUpperCase(locale) === character && character.toLocaleLowerCase(locale) !== character;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
return string;
|
|
698
|
+
};
|
|
699
|
+
|
|
700
|
+
const preserveConsecutiveUppercase = input => {
|
|
701
|
+
return input.replace(/^[\p{Lu}](?![\p{Lu}])/gu, m1 => m1.toLowerCase());
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
const postProcess = (input, options) => {
|
|
705
|
+
return input.replace(/[_.\- ]+([\p{Alpha}\p{N}_]|$)/gu, (_, p1) => p1.toLocaleUpperCase(options.locale))
|
|
706
|
+
.replace(/\d+([\p{Alpha}\p{N}_]|$)/gu, m => m.toLocaleUpperCase(options.locale));
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
const camelCase$1 = (input, options) => {
|
|
710
|
+
if (!(typeof input === 'string' || Array.isArray(input))) {
|
|
711
|
+
throw new TypeError('Expected the input to be `string | string[]`');
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
options = {
|
|
715
|
+
pascalCase: false,
|
|
716
|
+
preserveConsecutiveUppercase: false,
|
|
717
|
+
...options
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
if (Array.isArray(input)) {
|
|
721
|
+
input = input.map(x => x.trim())
|
|
722
|
+
.filter(x => x.length)
|
|
723
|
+
.join('-');
|
|
724
|
+
} else {
|
|
725
|
+
input = input.trim();
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
if (input.length === 0) {
|
|
729
|
+
return '';
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
if (input.length === 1) {
|
|
733
|
+
return options.pascalCase ? input.toLocaleUpperCase(options.locale) : input.toLocaleLowerCase(options.locale);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
const hasUpperCase = input !== input.toLocaleLowerCase(options.locale);
|
|
737
|
+
|
|
738
|
+
if (hasUpperCase) {
|
|
739
|
+
input = preserveCamelCase(input, options.locale);
|
|
740
|
+
}
|
|
142
741
|
|
|
143
742
|
input = input.replace(/^[_.\- ]+/, '');
|
|
144
743
|
|
|
@@ -203,794 +802,197 @@ class QuickLRU {
|
|
|
203
802
|
}
|
|
204
803
|
}
|
|
205
804
|
|
|
206
|
-
set(key, value) {
|
|
207
|
-
if (this.cache.has(key)) {
|
|
208
|
-
this.cache.set(key, value);
|
|
209
|
-
} else {
|
|
210
|
-
this._set(key, value);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return this;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
has(key) {
|
|
217
|
-
return this.cache.has(key) || this.oldCache.has(key);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
peek(key) {
|
|
221
|
-
if (this.cache.has(key)) {
|
|
222
|
-
return this.cache.get(key);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (this.oldCache.has(key)) {
|
|
226
|
-
return this.oldCache.get(key);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
delete(key) {
|
|
231
|
-
const deleted = this.cache.delete(key);
|
|
232
|
-
if (deleted) {
|
|
233
|
-
this._size--;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return this.oldCache.delete(key) || deleted;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
clear() {
|
|
240
|
-
this.cache.clear();
|
|
241
|
-
this.oldCache.clear();
|
|
242
|
-
this._size = 0;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
* keys() {
|
|
246
|
-
for (const [key] of this) {
|
|
247
|
-
yield key;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
* values() {
|
|
252
|
-
for (const [, value] of this) {
|
|
253
|
-
yield value;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
* [Symbol.iterator]() {
|
|
258
|
-
for (const item of this.cache) {
|
|
259
|
-
yield item;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
for (const item of this.oldCache) {
|
|
263
|
-
const [key] = item;
|
|
264
|
-
if (!this.cache.has(key)) {
|
|
265
|
-
yield item;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
get size() {
|
|
271
|
-
let oldCacheSize = 0;
|
|
272
|
-
for (const key of this.oldCache.keys()) {
|
|
273
|
-
if (!this.cache.has(key)) {
|
|
274
|
-
oldCacheSize++;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
return Math.min(this._size + oldCacheSize, this.maxSize);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
var quickLru = QuickLRU;
|
|
283
|
-
|
|
284
|
-
const mapObj = mapObj$1.exports;
|
|
285
|
-
const camelCase = camelcase.exports;
|
|
286
|
-
const QuickLru = quickLru;
|
|
287
|
-
|
|
288
|
-
const has = (array, key) => array.some(x => {
|
|
289
|
-
if (typeof x === 'string') {
|
|
290
|
-
return x === key;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
x.lastIndex = 0;
|
|
294
|
-
return x.test(key);
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
const cache = new QuickLru({maxSize: 100000});
|
|
298
|
-
|
|
299
|
-
// Reproduces behavior from `map-obj`
|
|
300
|
-
const isObject = value =>
|
|
301
|
-
typeof value === 'object' &&
|
|
302
|
-
value !== null &&
|
|
303
|
-
!(value instanceof RegExp) &&
|
|
304
|
-
!(value instanceof Error) &&
|
|
305
|
-
!(value instanceof Date);
|
|
306
|
-
|
|
307
|
-
const camelCaseConvert = (input, options) => {
|
|
308
|
-
if (!isObject(input)) {
|
|
309
|
-
return input;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
options = {
|
|
313
|
-
deep: false,
|
|
314
|
-
pascalCase: false,
|
|
315
|
-
...options
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
const {exclude, pascalCase, stopPaths, deep} = options;
|
|
319
|
-
|
|
320
|
-
const stopPathsSet = new Set(stopPaths);
|
|
321
|
-
|
|
322
|
-
const makeMapper = parentPath => (key, value) => {
|
|
323
|
-
if (deep && isObject(value)) {
|
|
324
|
-
const path = parentPath === undefined ? key : `${parentPath}.${key}`;
|
|
325
|
-
|
|
326
|
-
if (!stopPathsSet.has(path)) {
|
|
327
|
-
value = mapObj(value, makeMapper(path));
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
if (!(exclude && has(exclude, key))) {
|
|
332
|
-
const cacheKey = pascalCase ? `${key}_` : key;
|
|
333
|
-
|
|
334
|
-
if (cache.has(cacheKey)) {
|
|
335
|
-
key = cache.get(cacheKey);
|
|
336
|
-
} else {
|
|
337
|
-
const returnValue = camelCase(key, {pascalCase});
|
|
338
|
-
|
|
339
|
-
if (key.length < 100) { // Prevent abuse
|
|
340
|
-
cache.set(cacheKey, returnValue);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
key = returnValue;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
return [key, value];
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
return mapObj(input, makeMapper(undefined));
|
|
351
|
-
};
|
|
352
|
-
|
|
353
|
-
var camelcaseKeys = (input, options) => {
|
|
354
|
-
if (Array.isArray(input)) {
|
|
355
|
-
return Object.keys(input).map(key => camelCaseConvert(input[key], options));
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
return camelCaseConvert(input, options);
|
|
359
|
-
};
|
|
805
|
+
set(key, value) {
|
|
806
|
+
if (this.cache.has(key)) {
|
|
807
|
+
this.cache.set(key, value);
|
|
808
|
+
} else {
|
|
809
|
+
this._set(key, value);
|
|
810
|
+
}
|
|
360
811
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
const sortOrderToNumber = (order) => {
|
|
364
|
-
return ({
|
|
365
|
-
asc: 1,
|
|
366
|
-
desc: -1,
|
|
367
|
-
}[order] || 1);
|
|
368
|
-
};
|
|
369
|
-
const destructureData = (payload) => {
|
|
370
|
-
if (typeof payload !== 'object') {
|
|
371
|
-
return payload;
|
|
372
|
-
}
|
|
373
|
-
if (payload === null) {
|
|
374
|
-
return payload;
|
|
375
|
-
}
|
|
376
|
-
const data = payload.data;
|
|
377
|
-
const dataIsPlainObject = Object.prototype.toString.call(data) === '[object Object]';
|
|
378
|
-
if (dataIsPlainObject && Object.keys(payload).length === 1) {
|
|
379
|
-
const d = Object.assign({}, data);
|
|
380
|
-
// attach raw onto new data
|
|
381
|
-
attachRawFromOneToAnthor(payload, d);
|
|
382
|
-
return d;
|
|
383
|
-
}
|
|
384
|
-
return payload;
|
|
385
|
-
};
|
|
386
|
-
const attachRawFromOneToAnthor = (from, to) => {
|
|
387
|
-
if (!from) {
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
from.$raw &&
|
|
391
|
-
Object.defineProperty(to, '$raw', {
|
|
392
|
-
value: Object.assign({}, from.$raw),
|
|
393
|
-
enumerable: false,
|
|
394
|
-
});
|
|
395
|
-
from.$request &&
|
|
396
|
-
Object.defineProperty(to, '$request', {
|
|
397
|
-
value: Object.assign({}, from.$request),
|
|
398
|
-
enumerable: false,
|
|
399
|
-
});
|
|
400
|
-
};
|
|
812
|
+
return this;
|
|
813
|
+
}
|
|
401
814
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
// HINT: method get only accept search params;
|
|
406
|
-
const { params = {} } = options;
|
|
407
|
-
const qs = handleSearchParams(params);
|
|
408
|
-
return target.instance.get(url + `${qs ? `${'?' + qs}` : ''}`);
|
|
409
|
-
},
|
|
410
|
-
});
|
|
411
|
-
Object.defineProperty(target, '$$post', {
|
|
412
|
-
value: function (path, options) {
|
|
413
|
-
return target.instance.post(path, options);
|
|
414
|
-
},
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
// FIXME: only support string value
|
|
418
|
-
function handleSearchParams(obj) {
|
|
419
|
-
if (!obj && typeof obj !== 'object') {
|
|
420
|
-
throw new TypeError('params must be object.');
|
|
421
|
-
}
|
|
422
|
-
if (obj instanceof URLSearchParams) {
|
|
423
|
-
return obj.toString();
|
|
424
|
-
}
|
|
425
|
-
const search = new URLSearchParams();
|
|
426
|
-
Object.entries(obj).forEach(([k, v]) => {
|
|
427
|
-
if (typeof v === 'undefined' ||
|
|
428
|
-
Object.prototype.toString.call(v) === '[object Null]') {
|
|
429
|
-
return;
|
|
430
|
-
}
|
|
431
|
-
search.set(k, v);
|
|
432
|
-
});
|
|
433
|
-
return search.toString();
|
|
434
|
-
}
|
|
815
|
+
has(key) {
|
|
816
|
+
return this.cache.has(key) || this.oldCache.has(key);
|
|
817
|
+
}
|
|
435
818
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
const properties = new Set();
|
|
441
|
-
do {
|
|
442
|
-
for (const key of Reflect.ownKeys(object)) {
|
|
443
|
-
properties.add([object, key]);
|
|
444
|
-
}
|
|
445
|
-
} while ((object = Reflect.getPrototypeOf(object)) &&
|
|
446
|
-
object !== Object.prototype);
|
|
447
|
-
return properties;
|
|
448
|
-
};
|
|
449
|
-
function autoBind(self, { include, exclude } = {}) {
|
|
450
|
-
const filter = (key) => {
|
|
451
|
-
const match = (pattern) => typeof pattern === 'string' ? key === pattern : pattern.test(key);
|
|
452
|
-
if (include) {
|
|
453
|
-
return include.some(match);
|
|
454
|
-
}
|
|
455
|
-
if (exclude) {
|
|
456
|
-
return !exclude.some(match);
|
|
457
|
-
}
|
|
458
|
-
return true;
|
|
459
|
-
};
|
|
460
|
-
for (const [object, key] of getAllProperties(self.constructor.prototype)) {
|
|
461
|
-
if (key === 'constructor' || !filter(key)) {
|
|
462
|
-
continue;
|
|
463
|
-
}
|
|
464
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(object, key);
|
|
465
|
-
if (descriptor && typeof descriptor.value === 'function') {
|
|
466
|
-
self[key] = self[key].bind(self);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
return self;
|
|
470
|
-
}
|
|
819
|
+
peek(key) {
|
|
820
|
+
if (this.cache.has(key)) {
|
|
821
|
+
return this.cache.get(key);
|
|
822
|
+
}
|
|
471
823
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
this.name = 'aggregate';
|
|
477
|
-
autoBind(this);
|
|
478
|
-
}
|
|
479
|
-
get proxy() {
|
|
480
|
-
return this.client.proxy(this.base);
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* 获取聚合数据
|
|
484
|
-
*/
|
|
485
|
-
getAggregateData() {
|
|
486
|
-
return this.proxy.get();
|
|
487
|
-
}
|
|
488
|
-
/**
|
|
489
|
-
* 获取最新发布的内容
|
|
490
|
-
*/
|
|
491
|
-
getTop(size = 5) {
|
|
492
|
-
return this.proxy.top.get({ params: { size } });
|
|
493
|
-
}
|
|
494
|
-
getTimeline(options) {
|
|
495
|
-
const { sort, type, year } = options || {};
|
|
496
|
-
return this.proxy.timeline.get({
|
|
497
|
-
params: {
|
|
498
|
-
sort: sort && sortOrderToNumber(sort),
|
|
499
|
-
type,
|
|
500
|
-
year,
|
|
501
|
-
},
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
/**
|
|
505
|
-
* 获取聚合数据统计
|
|
506
|
-
*/
|
|
507
|
-
getStat() {
|
|
508
|
-
return this.proxy.stat.get();
|
|
509
|
-
}
|
|
510
|
-
}
|
|
824
|
+
if (this.oldCache.has(key)) {
|
|
825
|
+
return this.oldCache.get(key);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
511
828
|
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
}
|
|
829
|
+
delete(key) {
|
|
830
|
+
const deleted = this.cache.delete(key);
|
|
831
|
+
if (deleted) {
|
|
832
|
+
this._size--;
|
|
833
|
+
}
|
|
517
834
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
super(message);
|
|
521
|
-
this.status = status;
|
|
522
|
-
this.path = path;
|
|
523
|
-
this.raw = raw;
|
|
524
|
-
}
|
|
525
|
-
}
|
|
835
|
+
return this.oldCache.delete(key) || deleted;
|
|
836
|
+
}
|
|
526
837
|
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
return this.proxy.get({
|
|
539
|
-
params: {
|
|
540
|
-
type: CategoryType.Category,
|
|
541
|
-
},
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
getAllTags() {
|
|
545
|
-
return this.proxy.get({
|
|
546
|
-
params: {
|
|
547
|
-
type: CategoryType.Tag,
|
|
548
|
-
},
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
async getCategoryDetail(ids) {
|
|
552
|
-
if (typeof ids === 'string') {
|
|
553
|
-
const data = await this.proxy.get({
|
|
554
|
-
params: {
|
|
555
|
-
ids: ids,
|
|
556
|
-
},
|
|
557
|
-
});
|
|
558
|
-
const result = Object.values(data.entries)[0];
|
|
559
|
-
attachRawFromOneToAnthor(data, result);
|
|
560
|
-
return result;
|
|
561
|
-
}
|
|
562
|
-
else if (Array.isArray(ids)) {
|
|
563
|
-
const data = await this.proxy.get({
|
|
564
|
-
params: {
|
|
565
|
-
ids: ids.join(','),
|
|
566
|
-
},
|
|
567
|
-
});
|
|
568
|
-
const entries = data === null || data === void 0 ? void 0 : data.entries;
|
|
569
|
-
if (!entries) {
|
|
570
|
-
throw new RequestError('data structure error', 500, data.$request.path, data);
|
|
571
|
-
}
|
|
572
|
-
const map = new Map(Object.entries(entries).map(([id, value]) => [id.toLowerCase(), value]));
|
|
573
|
-
attachRawFromOneToAnthor(data, map);
|
|
574
|
-
return map;
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
async getCategoryByIdOrSlug(idOrSlug) {
|
|
578
|
-
const res = await this.proxy(idOrSlug).get();
|
|
579
|
-
return destructureData(res);
|
|
580
|
-
}
|
|
581
|
-
async getTagByName(name) {
|
|
582
|
-
const res = await this.proxy(name).get({
|
|
583
|
-
params: {
|
|
584
|
-
tag: 1,
|
|
585
|
-
},
|
|
586
|
-
});
|
|
587
|
-
return res;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
838
|
+
clear() {
|
|
839
|
+
this.cache.clear();
|
|
840
|
+
this.oldCache.clear();
|
|
841
|
+
this._size = 0;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
* keys() {
|
|
845
|
+
for (const [key] of this) {
|
|
846
|
+
yield key;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
590
849
|
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
autoBind(this);
|
|
597
|
-
}
|
|
598
|
-
get proxy() {
|
|
599
|
-
return this.client.proxy(this.base);
|
|
600
|
-
}
|
|
601
|
-
/**
|
|
602
|
-
* 根据 comment id 获取评论, 包括子评论
|
|
603
|
-
*/
|
|
604
|
-
getById(id) {
|
|
605
|
-
return this.proxy(id).get();
|
|
606
|
-
}
|
|
607
|
-
/**
|
|
608
|
-
* 获取文章的评论列表
|
|
609
|
-
* @param refId 文章 Id
|
|
610
|
-
*/
|
|
611
|
-
getByRefId(refId, pagination = {}) {
|
|
612
|
-
const { page, size } = pagination;
|
|
613
|
-
return this.proxy.ref(refId).get({
|
|
614
|
-
params: { page: page || 1, size: size || 10 },
|
|
615
|
-
});
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* 评论
|
|
619
|
-
*/
|
|
620
|
-
comment(refId, data) {
|
|
621
|
-
return this.proxy(refId).post({
|
|
622
|
-
data,
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* 回复评论
|
|
627
|
-
*/
|
|
628
|
-
reply(commentId, data) {
|
|
629
|
-
return this.proxy.reply(commentId).post({
|
|
630
|
-
data,
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
}
|
|
850
|
+
* values() {
|
|
851
|
+
for (const [, value] of this) {
|
|
852
|
+
yield value;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
634
855
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
}
|
|
640
|
-
get proxy() {
|
|
641
|
-
return this.client.proxy(this.base);
|
|
642
|
-
}
|
|
643
|
-
getById(id) {
|
|
644
|
-
return this.proxy(id).get();
|
|
645
|
-
}
|
|
646
|
-
getAll() {
|
|
647
|
-
return this.proxy.all.get();
|
|
648
|
-
}
|
|
649
|
-
/**
|
|
650
|
-
* 带分页的查询
|
|
651
|
-
* @param page
|
|
652
|
-
* @param perPage
|
|
653
|
-
*/
|
|
654
|
-
getAllPaginated(page, perPage) {
|
|
655
|
-
return this.proxy.get({
|
|
656
|
-
params: { page, size: perPage },
|
|
657
|
-
});
|
|
658
|
-
}
|
|
659
|
-
}
|
|
856
|
+
* [Symbol.iterator]() {
|
|
857
|
+
for (const item of this.cache) {
|
|
858
|
+
yield item;
|
|
859
|
+
}
|
|
660
860
|
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
}
|
|
669
|
-
}
|
|
861
|
+
for (const item of this.oldCache) {
|
|
862
|
+
const [key] = item;
|
|
863
|
+
if (!this.cache.has(key)) {
|
|
864
|
+
yield item;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
}
|
|
670
868
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
get proxy() {
|
|
679
|
-
return this.client.proxy(this.base);
|
|
680
|
-
}
|
|
681
|
-
/**
|
|
682
|
-
* 最新日记
|
|
683
|
-
*/
|
|
684
|
-
getLatest() {
|
|
685
|
-
return this.proxy.latest.get();
|
|
686
|
-
}
|
|
687
|
-
/**
|
|
688
|
-
* 获取一篇日记
|
|
689
|
-
* @param id id | nid
|
|
690
|
-
* @param password 访问密码
|
|
691
|
-
*/
|
|
692
|
-
getNoteById(id, password) {
|
|
693
|
-
if (typeof id === 'number') {
|
|
694
|
-
return this.proxy.nid(id.toString()).get({
|
|
695
|
-
params: { password },
|
|
696
|
-
});
|
|
697
|
-
}
|
|
698
|
-
else {
|
|
699
|
-
return this.proxy(id).get({ params: { password } });
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
/**
|
|
703
|
-
* 日记列表分页
|
|
704
|
-
*/
|
|
705
|
-
getList(page = 1, perPage = 10, options = {}) {
|
|
706
|
-
const { select, sortBy, sortOrder, year } = options;
|
|
707
|
-
return this.proxy.get({
|
|
708
|
-
params: {
|
|
709
|
-
page,
|
|
710
|
-
size: perPage,
|
|
711
|
-
select: select === null || select === void 0 ? void 0 : select.join(' '),
|
|
712
|
-
sortBy,
|
|
713
|
-
sortOrder,
|
|
714
|
-
year,
|
|
715
|
-
},
|
|
716
|
-
});
|
|
717
|
-
}
|
|
718
|
-
/**
|
|
719
|
-
* 获取当前日记的上下各 n / 2 篇日记
|
|
720
|
-
*/
|
|
721
|
-
getMiddleList(id, size = 5) {
|
|
722
|
-
return this.proxy.list(id).get({
|
|
723
|
-
params: { size },
|
|
724
|
-
});
|
|
725
|
-
}
|
|
726
|
-
/**
|
|
727
|
-
* 喜欢这篇日记
|
|
728
|
-
*/
|
|
729
|
-
likeIt(id) {
|
|
730
|
-
return this.proxy.like(id).get();
|
|
731
|
-
}
|
|
732
|
-
}
|
|
869
|
+
get size() {
|
|
870
|
+
let oldCacheSize = 0;
|
|
871
|
+
for (const key of this.oldCache.keys()) {
|
|
872
|
+
if (!this.cache.has(key)) {
|
|
873
|
+
oldCacheSize++;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
733
876
|
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
this.client = client;
|
|
737
|
-
this.base = 'pages';
|
|
738
|
-
this.name = 'page';
|
|
739
|
-
autoBind(this);
|
|
740
|
-
}
|
|
741
|
-
get proxy() {
|
|
742
|
-
return this.client.proxy(this.base);
|
|
743
|
-
}
|
|
744
|
-
/**
|
|
745
|
-
* 页面列表
|
|
746
|
-
*/
|
|
747
|
-
getList(page = 1, perPage = 10, options = {}) {
|
|
748
|
-
const { select, sortBy, sortOrder } = options;
|
|
749
|
-
return this.proxy.get({
|
|
750
|
-
params: {
|
|
751
|
-
page,
|
|
752
|
-
size: perPage,
|
|
753
|
-
select: select === null || select === void 0 ? void 0 : select.join(' '),
|
|
754
|
-
sortBy,
|
|
755
|
-
sortOrder,
|
|
756
|
-
},
|
|
757
|
-
});
|
|
758
|
-
}
|
|
759
|
-
/**
|
|
760
|
-
* 页面详情
|
|
761
|
-
*/
|
|
762
|
-
getById(id) {
|
|
763
|
-
return this.proxy(id).get();
|
|
764
|
-
}
|
|
765
|
-
/**
|
|
766
|
-
* 根据路径获取页面
|
|
767
|
-
* @param slug 路径
|
|
768
|
-
* @returns
|
|
769
|
-
*/
|
|
770
|
-
getBySlug(slug) {
|
|
771
|
-
return this.proxy.slug(slug).get({});
|
|
772
|
-
}
|
|
877
|
+
return Math.min(this._size + oldCacheSize, this.maxSize);
|
|
878
|
+
}
|
|
773
879
|
}
|
|
774
880
|
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
881
|
+
var quickLru = QuickLRU;
|
|
882
|
+
|
|
883
|
+
const mapObj = mapObj$1.exports;
|
|
884
|
+
const camelCase = camelcase.exports;
|
|
885
|
+
const QuickLru = quickLru;
|
|
886
|
+
|
|
887
|
+
const has = (array, key) => array.some(x => {
|
|
888
|
+
if (typeof x === 'string') {
|
|
889
|
+
return x === key;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
x.lastIndex = 0;
|
|
893
|
+
return x.test(key);
|
|
894
|
+
});
|
|
895
|
+
|
|
896
|
+
const cache = new QuickLru({maxSize: 100000});
|
|
897
|
+
|
|
898
|
+
// Reproduces behavior from `map-obj`
|
|
899
|
+
const isObject = value =>
|
|
900
|
+
typeof value === 'object' &&
|
|
901
|
+
value !== null &&
|
|
902
|
+
!(value instanceof RegExp) &&
|
|
903
|
+
!(value instanceof Error) &&
|
|
904
|
+
!(value instanceof Date);
|
|
905
|
+
|
|
906
|
+
const camelCaseConvert = (input, options) => {
|
|
907
|
+
if (!isObject(input)) {
|
|
908
|
+
return input;
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
options = {
|
|
912
|
+
deep: false,
|
|
913
|
+
pascalCase: false,
|
|
914
|
+
...options
|
|
915
|
+
};
|
|
916
|
+
|
|
917
|
+
const {exclude, pascalCase, stopPaths, deep} = options;
|
|
918
|
+
|
|
919
|
+
const stopPathsSet = new Set(stopPaths);
|
|
920
|
+
|
|
921
|
+
const makeMapper = parentPath => (key, value) => {
|
|
922
|
+
if (deep && isObject(value)) {
|
|
923
|
+
const path = parentPath === undefined ? key : `${parentPath}.${key}`;
|
|
924
|
+
|
|
925
|
+
if (!stopPathsSet.has(path)) {
|
|
926
|
+
value = mapObj(value, makeMapper(path));
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
if (!(exclude && has(exclude, key))) {
|
|
931
|
+
const cacheKey = pascalCase ? `${key}_` : key;
|
|
932
|
+
|
|
933
|
+
if (cache.has(cacheKey)) {
|
|
934
|
+
key = cache.get(cacheKey);
|
|
935
|
+
} else {
|
|
936
|
+
const returnValue = camelCase(key, {pascalCase});
|
|
825
937
|
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
this.client = client;
|
|
830
|
-
this.base = 'projects';
|
|
831
|
-
this.name = 'project';
|
|
832
|
-
autoBind(this);
|
|
833
|
-
}
|
|
834
|
-
}
|
|
938
|
+
if (key.length < 100) { // Prevent abuse
|
|
939
|
+
cache.set(cacheKey, returnValue);
|
|
940
|
+
}
|
|
835
941
|
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
this.base = 'recently';
|
|
840
|
-
this.name = 'recently';
|
|
841
|
-
autoBind(this);
|
|
842
|
-
}
|
|
843
|
-
get proxy() {
|
|
844
|
-
return this.client.proxy(this.base);
|
|
845
|
-
}
|
|
846
|
-
/**
|
|
847
|
-
* 获取最新一条
|
|
848
|
-
*/
|
|
849
|
-
getLatestOne() {
|
|
850
|
-
return this.proxy.latest.get();
|
|
851
|
-
}
|
|
852
|
-
getAll() {
|
|
853
|
-
return this.proxy.all.get();
|
|
854
|
-
}
|
|
855
|
-
getList(before, after, size) {
|
|
856
|
-
if (!before && !after) {
|
|
857
|
-
throw new Error('you can only choose `before` or `after`');
|
|
858
|
-
}
|
|
859
|
-
return this.proxy.get({
|
|
860
|
-
params: {
|
|
861
|
-
before,
|
|
862
|
-
after,
|
|
863
|
-
size,
|
|
864
|
-
},
|
|
865
|
-
});
|
|
866
|
-
}
|
|
867
|
-
}
|
|
942
|
+
key = returnValue;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
868
945
|
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
super(client);
|
|
872
|
-
this.client = client;
|
|
873
|
-
this.base = 'says';
|
|
874
|
-
this.name = 'say';
|
|
875
|
-
autoBind(this);
|
|
876
|
-
}
|
|
877
|
-
get proxy() {
|
|
878
|
-
return this.client.proxy(this.base);
|
|
879
|
-
}
|
|
880
|
-
/**
|
|
881
|
-
* 获取随机一条
|
|
882
|
-
*/
|
|
883
|
-
getRandom() {
|
|
884
|
-
return this.proxy.random.get();
|
|
885
|
-
}
|
|
886
|
-
}
|
|
946
|
+
return [key, value];
|
|
947
|
+
};
|
|
887
948
|
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
this.client = client;
|
|
891
|
-
this.base = 'search';
|
|
892
|
-
this.name = 'search';
|
|
893
|
-
autoBind(this);
|
|
894
|
-
}
|
|
895
|
-
get proxy() {
|
|
896
|
-
return this.client.proxy(this.base);
|
|
897
|
-
}
|
|
898
|
-
search(type, keyword, options = {}) {
|
|
899
|
-
return this.proxy(type).get({
|
|
900
|
-
params: Object.assign({ keyword }, options),
|
|
901
|
-
});
|
|
902
|
-
}
|
|
903
|
-
/**
|
|
904
|
-
* 从 algolya 搜索
|
|
905
|
-
* https://www.algolia.com/doc/api-reference/api-methods/search/
|
|
906
|
-
* @param keyword
|
|
907
|
-
* @param options
|
|
908
|
-
* @returns
|
|
909
|
-
*/
|
|
910
|
-
searchByAlgolia(keyword, options) {
|
|
911
|
-
return this.proxy('algolia').get({ params: Object.assign({ keyword }, options) });
|
|
912
|
-
}
|
|
913
|
-
}
|
|
949
|
+
return mapObj(input, makeMapper(undefined));
|
|
950
|
+
};
|
|
914
951
|
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
this.name = 'snippet';
|
|
920
|
-
autoBind(this);
|
|
921
|
-
}
|
|
922
|
-
get proxy() {
|
|
923
|
-
return this.client.proxy(this.base);
|
|
924
|
-
}
|
|
925
|
-
getById(id) {
|
|
926
|
-
return this.proxy(id).get();
|
|
927
|
-
}
|
|
928
|
-
getByReferenceAndName(reference, name) {
|
|
929
|
-
return this.proxy(reference)(name).get();
|
|
930
|
-
}
|
|
931
|
-
}
|
|
952
|
+
var camelcaseKeys = (input, options) => {
|
|
953
|
+
if (Array.isArray(input)) {
|
|
954
|
+
return Object.keys(input).map(key => camelCaseConvert(input[key], options));
|
|
955
|
+
}
|
|
932
956
|
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
username,
|
|
950
|
-
password,
|
|
957
|
+
return camelCaseConvert(input, options);
|
|
958
|
+
};
|
|
959
|
+
|
|
960
|
+
function attachRequestMethod(target) {
|
|
961
|
+
Object.defineProperty(target, '$$get', {
|
|
962
|
+
value: function (url, options) {
|
|
963
|
+
// HINT: method get only accept search params;
|
|
964
|
+
const { params = {} } = options;
|
|
965
|
+
const qs = handleSearchParams(params);
|
|
966
|
+
return target.instance.get(url + `${qs ? `${'?' + qs}` : ''}`);
|
|
967
|
+
},
|
|
968
|
+
});
|
|
969
|
+
['put', 'post', 'patch', 'delete'].forEach((method) => {
|
|
970
|
+
Object.defineProperty(target, '$$' + method, {
|
|
971
|
+
value: function (path, options) {
|
|
972
|
+
return target.instance[method](path, options);
|
|
951
973
|
},
|
|
952
974
|
});
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
// FIXME: only support string value
|
|
978
|
+
function handleSearchParams(obj) {
|
|
979
|
+
if (!obj && typeof obj !== 'object') {
|
|
980
|
+
throw new TypeError('params must be object.');
|
|
953
981
|
}
|
|
954
|
-
|
|
955
|
-
return
|
|
956
|
-
params: {
|
|
957
|
-
token,
|
|
958
|
-
},
|
|
959
|
-
});
|
|
982
|
+
if (obj instanceof URLSearchParams) {
|
|
983
|
+
return obj.toString();
|
|
960
984
|
}
|
|
985
|
+
const search = new URLSearchParams();
|
|
986
|
+
Object.entries(obj).forEach(([k, v]) => {
|
|
987
|
+
if (typeof v === 'undefined' ||
|
|
988
|
+
Object.prototype.toString.call(v) === '[object Null]') {
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
search.set(k, v);
|
|
992
|
+
});
|
|
993
|
+
return search.toString();
|
|
961
994
|
}
|
|
962
995
|
|
|
963
|
-
const allControllers = [
|
|
964
|
-
AggregateController,
|
|
965
|
-
CategoryController,
|
|
966
|
-
CommentController,
|
|
967
|
-
LinkController,
|
|
968
|
-
NoteController,
|
|
969
|
-
PageController,
|
|
970
|
-
PostController,
|
|
971
|
-
ProjectController,
|
|
972
|
-
RecentlyController,
|
|
973
|
-
SayController,
|
|
974
|
-
SearchController,
|
|
975
|
-
SnippetController,
|
|
976
|
-
UserController,
|
|
977
|
-
];
|
|
978
|
-
const allContollerNames = [
|
|
979
|
-
'aggregate',
|
|
980
|
-
'category',
|
|
981
|
-
'comment',
|
|
982
|
-
'link',
|
|
983
|
-
'note',
|
|
984
|
-
'page',
|
|
985
|
-
'post',
|
|
986
|
-
'project',
|
|
987
|
-
'recently',
|
|
988
|
-
'say',
|
|
989
|
-
'search',
|
|
990
|
-
'snippet',
|
|
991
|
-
'user',
|
|
992
|
-
];
|
|
993
|
-
|
|
994
996
|
class HTTPControllerDefine {
|
|
995
997
|
get master() {
|
|
996
998
|
return this.user;
|
|
@@ -1004,11 +1006,10 @@ class HTTPControllerDefine {
|
|
|
1004
1006
|
}
|
|
1005
1007
|
|
|
1006
1008
|
class HTTPClient extends HTTPControllerDefine {
|
|
1007
|
-
|
|
1008
|
-
constructor(_endpoint, _instance) {
|
|
1009
|
+
constructor(_endpoint, _adaptor) {
|
|
1009
1010
|
super();
|
|
1010
1011
|
this._endpoint = _endpoint;
|
|
1011
|
-
this.
|
|
1012
|
+
this._adaptor = _adaptor;
|
|
1012
1013
|
this._endpoint = _endpoint
|
|
1013
1014
|
.replace(/\/*$/, '')
|
|
1014
1015
|
.replace('localhost', '127.0.0.1');
|
|
@@ -1049,7 +1050,7 @@ class HTTPClient extends HTTPControllerDefine {
|
|
|
1049
1050
|
return this._endpoint;
|
|
1050
1051
|
}
|
|
1051
1052
|
get instance() {
|
|
1052
|
-
return this.
|
|
1053
|
+
return this._adaptor;
|
|
1053
1054
|
}
|
|
1054
1055
|
request(options) {
|
|
1055
1056
|
return this['$$' + String(options.method || 'get').toLowerCase()](options.url, options);
|