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