@waline/client 2.12.0 → 2.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +339 -0
- package/dist/api.cjs +1 -1
- package/dist/api.cjs.map +1 -1
- package/dist/api.d.cts +271 -53
- package/dist/api.d.mts +271 -53
- package/dist/api.d.ts +271 -53
- package/dist/api.mjs +1 -1
- package/dist/api.mjs.map +1 -1
- package/dist/comment.cjs +1 -1
- package/dist/comment.cjs.map +1 -1
- package/dist/comment.d.cts +1 -1
- package/dist/comment.d.mts +1 -1
- package/dist/comment.d.ts +1 -1
- package/dist/comment.js +73 -1
- package/dist/comment.js.map +1 -1
- package/dist/comment.mjs +1 -1
- package/dist/comment.mjs.map +1 -1
- package/dist/component.mjs +1 -1
- package/dist/component.mjs.map +1 -1
- package/dist/legacy.umd.d.ts +8 -8
- package/dist/legacy.umd.js +1 -1
- package/dist/legacy.umd.js.map +1 -1
- package/dist/pageview.cjs +1 -1
- package/dist/pageview.cjs.map +1 -1
- package/dist/pageview.d.cts +1 -1
- package/dist/pageview.d.mts +1 -1
- package/dist/pageview.d.ts +1 -1
- package/dist/pageview.js +126 -1
- package/dist/pageview.js.map +1 -1
- package/dist/pageview.mjs +1 -1
- package/dist/pageview.mjs.map +1 -1
- package/dist/shim.cjs +1 -1
- package/dist/shim.cjs.map +1 -1
- package/dist/shim.d.cts +75 -11
- package/dist/shim.d.mts +75 -11
- package/dist/shim.mjs +1 -1
- package/dist/shim.mjs.map +1 -1
- package/dist/waline.cjs +1 -1
- package/dist/waline.cjs.map +1 -1
- package/dist/waline.css +1 -1
- package/dist/waline.css.map +1 -1
- package/dist/waline.d.cts +75 -11
- package/dist/waline.d.mts +75 -11
- package/dist/waline.d.ts +75 -11
- package/dist/waline.js +6795 -1
- package/dist/waline.js.map +1 -1
- package/dist/waline.mjs +1 -1
- package/dist/waline.mjs.map +1 -1
- package/package.json +28 -29
- package/src/api/articleCounter.ts +50 -16
- package/src/api/comment.ts +131 -39
- package/src/api/commentCount.ts +25 -20
- package/src/api/index.ts +1 -0
- package/src/api/login.ts +49 -6
- package/src/api/pageview.ts +25 -12
- package/src/api/recentComment.ts +23 -7
- package/src/api/user.ts +43 -0
- package/src/api/utils.ts +21 -5
- package/src/components/ArticleReaction.vue +12 -3
- package/src/components/CommentBox.vue +26 -21
- package/src/components/ImageWall.vue +14 -14
- package/src/components/Waline.vue +25 -16
- package/src/composables/userInfo.ts +1 -2
- package/src/composables/vote.ts +1 -1
- package/src/config/default.ts +23 -24
- package/src/pageview.ts +2 -2
- package/src/styles/index.scss +2 -1
- package/src/styles/userlist.scss +158 -0
- package/src/utils/emoji.ts +1 -1
- package/src/widgets/index.ts +1 -0
- package/src/widgets/recentComments.ts +2 -2
- package/src/widgets/userList.ts +136 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@waline/client",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.13.1",
|
|
4
4
|
"description": "client for waline comment system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"valine",
|
|
@@ -93,17 +93,6 @@
|
|
|
93
93
|
"dist",
|
|
94
94
|
"src"
|
|
95
95
|
],
|
|
96
|
-
"scripts": {
|
|
97
|
-
"build": "pnpm rollup && pnpm style",
|
|
98
|
-
"clean": "rimraf ./dist",
|
|
99
|
-
"dev": "vite -c config/vite.config.js",
|
|
100
|
-
"lint": "eslint --ext .ts,.vue .",
|
|
101
|
-
"prepublishOnly": "pnpm clean && pnpm build",
|
|
102
|
-
"rollup": "rollup -c ./config/rollup.config.js",
|
|
103
|
-
"style": "pnpm style:main && pnpm style:meta",
|
|
104
|
-
"style:main": "sass ./src/styles/index.scss ./dist/waline.css --style=compressed",
|
|
105
|
-
"style:meta": "sass ./src/styles/meta.scss ./dist/waline-meta.css --style=compressed"
|
|
106
|
-
},
|
|
107
96
|
"browserslist": {
|
|
108
97
|
"production": [
|
|
109
98
|
">0.5%",
|
|
@@ -119,33 +108,43 @@
|
|
|
119
108
|
]
|
|
120
109
|
},
|
|
121
110
|
"dependencies": {
|
|
122
|
-
"@vueuse/core": "^9.
|
|
111
|
+
"@vueuse/core": "^9.5.0",
|
|
123
112
|
"autosize": "^5.0.1",
|
|
124
|
-
"marked": "^4.
|
|
125
|
-
"vue": "^3.2.
|
|
113
|
+
"marked": "^4.2.2",
|
|
114
|
+
"vue": "^3.2.45"
|
|
126
115
|
},
|
|
127
116
|
"devDependencies": {
|
|
128
|
-
"@babel/core": "7.
|
|
129
|
-
"@babel/preset-env": "7.
|
|
117
|
+
"@babel/core": "7.20.2",
|
|
118
|
+
"@babel/preset-env": "7.20.2",
|
|
130
119
|
"@giphy/js-types": "4.2.1",
|
|
131
|
-
"@rollup/plugin-babel": "
|
|
132
|
-
"@rollup/plugin-commonjs": "
|
|
133
|
-
"@rollup/plugin-node-resolve": "
|
|
134
|
-
"@rollup/plugin-replace": "
|
|
120
|
+
"@rollup/plugin-babel": "6.0.2",
|
|
121
|
+
"@rollup/plugin-commonjs": "23.0.2",
|
|
122
|
+
"@rollup/plugin-node-resolve": "15.0.1",
|
|
123
|
+
"@rollup/plugin-replace": "5.0.1",
|
|
124
|
+
"@rollup/plugin-terser": "0.1.0",
|
|
135
125
|
"@types/autosize": "4.0.1",
|
|
136
126
|
"@types/marked": "4.0.7",
|
|
137
|
-
"@types/node": "18.
|
|
138
|
-
"@vitejs/plugin-vue": "3.
|
|
127
|
+
"@types/node": "18.11.9",
|
|
128
|
+
"@vitejs/plugin-vue": "3.2.0",
|
|
139
129
|
"recaptcha-v3": "1.10.0",
|
|
140
130
|
"rimraf": "3.0.2",
|
|
141
|
-
"rollup": "
|
|
142
|
-
"rollup-plugin-dts": "
|
|
143
|
-
"rollup-plugin-terser": "7.0.2",
|
|
131
|
+
"rollup": "3.3.0",
|
|
132
|
+
"rollup-plugin-dts": "5.0.0",
|
|
144
133
|
"rollup-plugin-ts": "3.0.2",
|
|
145
|
-
"typescript": "4.
|
|
146
|
-
"vite": "3.
|
|
134
|
+
"typescript": "4.9.3",
|
|
135
|
+
"vite": "3.2.4"
|
|
147
136
|
},
|
|
148
137
|
"engines": {
|
|
149
138
|
"node": ">=14"
|
|
139
|
+
},
|
|
140
|
+
"scripts": {
|
|
141
|
+
"build": "pnpm rollup && pnpm style",
|
|
142
|
+
"clean": "rimraf ./dist",
|
|
143
|
+
"dev": "vite -c config/vite.config.js",
|
|
144
|
+
"lint": "eslint --ext .ts,.vue .",
|
|
145
|
+
"rollup": "rollup -c ./config/rollup.config.mjs",
|
|
146
|
+
"style": "pnpm style:main && pnpm style:meta",
|
|
147
|
+
"style:main": "sass ./src/styles/index.scss ./dist/waline.css --style=compressed",
|
|
148
|
+
"style:meta": "sass ./src/styles/meta.scss ./dist/waline-meta.css --style=compressed"
|
|
150
149
|
}
|
|
151
|
-
}
|
|
150
|
+
}
|
|
@@ -1,39 +1,73 @@
|
|
|
1
1
|
import { JSON_HEADERS, errorCheck } from './utils';
|
|
2
|
+
import type { BaseAPIOptions } from './utils';
|
|
2
3
|
|
|
3
|
-
export interface
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
export interface GetArticleCounterOptions extends BaseAPIOptions {
|
|
5
|
+
/**
|
|
6
|
+
* 待获取计数器的 path
|
|
7
|
+
*
|
|
8
|
+
* Path of counters
|
|
9
|
+
*/
|
|
6
10
|
paths: string[];
|
|
7
|
-
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 待获取计数器的类型
|
|
14
|
+
*
|
|
15
|
+
* Counter type to be fetched
|
|
16
|
+
*/
|
|
8
17
|
type: string[];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 取消请求的信号
|
|
21
|
+
*
|
|
22
|
+
* AbortSignal to cancel request
|
|
23
|
+
*/
|
|
24
|
+
signal?: AbortSignal;
|
|
9
25
|
}
|
|
10
26
|
|
|
11
|
-
export
|
|
27
|
+
export type GetArticleCounterResponse =
|
|
28
|
+
| Record<string, number>[]
|
|
29
|
+
| Record<string, number>
|
|
30
|
+
| number[]
|
|
31
|
+
| number;
|
|
32
|
+
|
|
33
|
+
export const getArticleCounter = ({
|
|
12
34
|
serverURL,
|
|
13
35
|
lang,
|
|
14
36
|
paths,
|
|
15
37
|
type,
|
|
16
38
|
signal,
|
|
17
|
-
}:
|
|
18
|
-
Record<string, number>[] | Record<string, number> | number[] | number
|
|
19
|
-
> =>
|
|
39
|
+
}: GetArticleCounterOptions): Promise<GetArticleCounterResponse> =>
|
|
20
40
|
fetch(
|
|
21
41
|
`${serverURL}/article?path=${encodeURIComponent(
|
|
22
42
|
paths.join(',')
|
|
23
43
|
)}&type=${encodeURIComponent(type.join(','))}&lang=${lang}`,
|
|
24
44
|
{ signal }
|
|
25
45
|
)
|
|
26
|
-
.then(
|
|
27
|
-
(resp) =>
|
|
28
|
-
resp.json() as Promise<Record<string, number>[] | number[] | number>
|
|
29
|
-
)
|
|
46
|
+
.then((resp) => <Promise<GetArticleCounterResponse>>resp.json())
|
|
30
47
|
.then((data) => errorCheck(data, 'article count'));
|
|
31
48
|
|
|
32
|
-
export interface UpdateArticleCounterOptions {
|
|
33
|
-
|
|
34
|
-
|
|
49
|
+
export interface UpdateArticleCounterOptions extends BaseAPIOptions {
|
|
50
|
+
/**
|
|
51
|
+
* 待更新计数器的 path
|
|
52
|
+
*
|
|
53
|
+
* Path of counter to be updated
|
|
54
|
+
*/
|
|
35
55
|
path: string;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 待更新计数器的类型
|
|
59
|
+
*
|
|
60
|
+
* Counter type to be updated
|
|
61
|
+
*/
|
|
36
62
|
type: string;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 更新操作
|
|
66
|
+
*
|
|
67
|
+
* Update operation
|
|
68
|
+
*
|
|
69
|
+
* @default 'inc'
|
|
70
|
+
*/
|
|
37
71
|
action?: 'inc' | 'desc';
|
|
38
72
|
}
|
|
39
73
|
|
|
@@ -49,5 +83,5 @@ export const updateArticleCounter = ({
|
|
|
49
83
|
headers: JSON_HEADERS,
|
|
50
84
|
body: JSON.stringify({ path, type, action }),
|
|
51
85
|
})
|
|
52
|
-
.then((resp) => resp.json()
|
|
86
|
+
.then((resp) => <Promise<number>>resp.json())
|
|
53
87
|
.then((data) => errorCheck(data, 'article count'));
|
package/src/api/comment.ts
CHANGED
|
@@ -1,24 +1,75 @@
|
|
|
1
1
|
import { JSON_HEADERS, errorCheck } from './utils';
|
|
2
|
+
import type { BaseAPIOptions } from './utils';
|
|
2
3
|
import type { WalineComment, WalineCommentData } from '../typings';
|
|
3
4
|
|
|
4
|
-
export interface
|
|
5
|
-
|
|
5
|
+
export interface GetCommentOptions extends BaseAPIOptions {
|
|
6
|
+
/**
|
|
7
|
+
* 待获取评论列hi奥德路径
|
|
8
|
+
*
|
|
9
|
+
* Path of comment list
|
|
10
|
+
*/
|
|
6
11
|
path: string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 评论分页数
|
|
15
|
+
*
|
|
16
|
+
* Comment panination number
|
|
17
|
+
*/
|
|
7
18
|
page: number;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 评论每页个数
|
|
22
|
+
*
|
|
23
|
+
* Comment number per page
|
|
24
|
+
*/
|
|
8
25
|
pageSize: number;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 排序方式
|
|
29
|
+
*
|
|
30
|
+
* Sort method
|
|
31
|
+
*/
|
|
9
32
|
sortBy: string;
|
|
10
|
-
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 用户令牌
|
|
36
|
+
*
|
|
37
|
+
* User token
|
|
38
|
+
*/
|
|
11
39
|
token?: string;
|
|
12
|
-
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 取消请求的信号
|
|
43
|
+
*
|
|
44
|
+
* AbortSignal to cancel request
|
|
45
|
+
*/
|
|
46
|
+
signal?: AbortSignal;
|
|
13
47
|
}
|
|
14
48
|
|
|
15
|
-
export interface
|
|
49
|
+
export interface GetCommentResponse {
|
|
50
|
+
/**
|
|
51
|
+
* 评论数量
|
|
52
|
+
*
|
|
53
|
+
* Comment number
|
|
54
|
+
*/
|
|
16
55
|
count: number;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 评论数据
|
|
59
|
+
*
|
|
60
|
+
* Comment Data
|
|
61
|
+
*/
|
|
17
62
|
data: WalineComment[];
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 页面总数
|
|
66
|
+
*
|
|
67
|
+
* Page number
|
|
68
|
+
*/
|
|
18
69
|
totalPages: number;
|
|
19
70
|
}
|
|
20
71
|
|
|
21
|
-
export const
|
|
72
|
+
export const getComment = ({
|
|
22
73
|
serverURL,
|
|
23
74
|
lang,
|
|
24
75
|
path,
|
|
@@ -27,7 +78,7 @@ export const fetchComment = ({
|
|
|
27
78
|
sortBy,
|
|
28
79
|
signal,
|
|
29
80
|
token,
|
|
30
|
-
}:
|
|
81
|
+
}: GetCommentOptions): Promise<GetCommentResponse> => {
|
|
31
82
|
const headers: Record<string, string> = {};
|
|
32
83
|
|
|
33
84
|
if (token) headers.Authorization = `Bearer ${token}`;
|
|
@@ -38,28 +89,44 @@ export const fetchComment = ({
|
|
|
38
89
|
)}&pageSize=${pageSize}&page=${page}&lang=${lang}&sortBy=${sortBy}`,
|
|
39
90
|
{ signal, headers }
|
|
40
91
|
)
|
|
41
|
-
.then((resp) => resp.json()
|
|
92
|
+
.then((resp) => <Promise<GetCommentResponse>>resp.json())
|
|
42
93
|
.then((data) => errorCheck(data, 'comment data'));
|
|
43
94
|
};
|
|
44
95
|
|
|
45
|
-
export interface
|
|
46
|
-
|
|
47
|
-
|
|
96
|
+
export interface AddCommentOptions extends BaseAPIOptions {
|
|
97
|
+
/**
|
|
98
|
+
* 用户令牌
|
|
99
|
+
*
|
|
100
|
+
* User token
|
|
101
|
+
*/
|
|
48
102
|
token?: string;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 用户待提交的评论数据
|
|
106
|
+
*
|
|
107
|
+
* Comment data being submitted by user
|
|
108
|
+
*/
|
|
49
109
|
comment: WalineCommentData;
|
|
50
110
|
}
|
|
51
111
|
|
|
52
|
-
export interface
|
|
112
|
+
export interface AddCommentResponse {
|
|
113
|
+
/**
|
|
114
|
+
* 渲染好的评论数据
|
|
115
|
+
*
|
|
116
|
+
* Comment data rendered
|
|
117
|
+
*/
|
|
53
118
|
data?: WalineComment;
|
|
119
|
+
|
|
120
|
+
/** 错误原因 */
|
|
54
121
|
errmsg?: string;
|
|
55
122
|
}
|
|
56
123
|
|
|
57
|
-
export const
|
|
124
|
+
export const addComment = ({
|
|
58
125
|
serverURL,
|
|
59
126
|
lang,
|
|
60
127
|
token,
|
|
61
128
|
comment,
|
|
62
|
-
}:
|
|
129
|
+
}: AddCommentOptions): Promise<AddCommentResponse> => {
|
|
63
130
|
const headers: Record<string, string> = {
|
|
64
131
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
65
132
|
'Content-Type': 'application/json',
|
|
@@ -67,24 +134,17 @@ export const postComment = ({
|
|
|
67
134
|
|
|
68
135
|
if (token) headers.Authorization = `Bearer ${token}`;
|
|
69
136
|
|
|
70
|
-
|
|
71
|
-
|
|
137
|
+
return fetch(
|
|
138
|
+
`${serverURL}/comment${comment.eid ? `/${comment.eid}` : ''}?lang=${lang}`,
|
|
139
|
+
{
|
|
72
140
|
method: 'PUT',
|
|
73
141
|
headers,
|
|
74
142
|
body: JSON.stringify(comment),
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return fetch(`${serverURL}/comment?lang=${lang}`, {
|
|
79
|
-
method: 'POST',
|
|
80
|
-
headers,
|
|
81
|
-
body: JSON.stringify(comment),
|
|
82
|
-
}).then((resp) => resp.json() as Promise<PostCommentResponse>);
|
|
143
|
+
}
|
|
144
|
+
).then((resp) => <Promise<AddCommentResponse>>resp.json());
|
|
83
145
|
};
|
|
84
146
|
|
|
85
|
-
export interface DeleteCommentOptions {
|
|
86
|
-
serverURL: string;
|
|
87
|
-
lang: string;
|
|
147
|
+
export interface DeleteCommentOptions extends BaseAPIOptions {
|
|
88
148
|
token: string;
|
|
89
149
|
objectId: string | number;
|
|
90
150
|
}
|
|
@@ -100,12 +160,21 @@ export const deleteComment = ({
|
|
|
100
160
|
headers: {
|
|
101
161
|
Authorization: `Bearer ${token}`,
|
|
102
162
|
},
|
|
103
|
-
}).then((resp) => resp.json()
|
|
104
|
-
|
|
105
|
-
export interface LikeCommentOptions {
|
|
106
|
-
|
|
107
|
-
|
|
163
|
+
}).then((resp) => <Promise<void>>resp.json());
|
|
164
|
+
|
|
165
|
+
export interface LikeCommentOptions extends BaseAPIOptions {
|
|
166
|
+
/**
|
|
167
|
+
* 评论的 ID
|
|
168
|
+
*
|
|
169
|
+
* Comment ID
|
|
170
|
+
*/
|
|
108
171
|
objectId: number | string;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* 点赞还是取消点赞
|
|
175
|
+
*
|
|
176
|
+
* Like or dislike
|
|
177
|
+
*/
|
|
109
178
|
like: boolean;
|
|
110
179
|
}
|
|
111
180
|
|
|
@@ -119,15 +188,38 @@ export const likeComment = ({
|
|
|
119
188
|
method: 'PUT',
|
|
120
189
|
headers: JSON_HEADERS,
|
|
121
190
|
body: JSON.stringify({ like }),
|
|
122
|
-
}).then((resp) => resp.json()
|
|
123
|
-
|
|
124
|
-
export interface UpdateCommentOptions {
|
|
125
|
-
|
|
126
|
-
|
|
191
|
+
}).then((resp) => <Promise<void>>resp.json());
|
|
192
|
+
|
|
193
|
+
export interface UpdateCommentOptions extends BaseAPIOptions {
|
|
194
|
+
/**
|
|
195
|
+
* 用户令牌
|
|
196
|
+
*
|
|
197
|
+
* User token
|
|
198
|
+
*/
|
|
127
199
|
token: string;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* 评论的 ID
|
|
203
|
+
*
|
|
204
|
+
* Comment ID
|
|
205
|
+
*/
|
|
128
206
|
objectId: number | string;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* 评论的状态
|
|
210
|
+
*
|
|
211
|
+
* Comment status
|
|
212
|
+
*/
|
|
129
213
|
status?: 'approved' | 'waiting' | 'spam';
|
|
130
|
-
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* 评论指定状态
|
|
217
|
+
*
|
|
218
|
+
* Comment sticky status
|
|
219
|
+
*
|
|
220
|
+
* @description 0 means not sticky and 1 means sticky
|
|
221
|
+
*/
|
|
222
|
+
sticky?: 0 | 1;
|
|
131
223
|
}
|
|
132
224
|
|
|
133
225
|
export const updateComment = ({
|
|
@@ -144,4 +236,4 @@ export const updateComment = ({
|
|
|
144
236
|
Authorization: `Bearer ${token}`,
|
|
145
237
|
},
|
|
146
238
|
body: JSON.stringify(data),
|
|
147
|
-
}).then((resp) => resp.json()
|
|
239
|
+
}).then((resp) => <Promise<void>>resp.json());
|
package/src/api/commentCount.ts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { errorCheck } from './utils';
|
|
2
|
+
import type { BaseAPIOptions } from './utils';
|
|
2
3
|
|
|
3
|
-
export interface
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
export interface GetCommentCountOptions extends BaseAPIOptions {
|
|
5
|
+
/**
|
|
6
|
+
* 待获取评论数的 path
|
|
7
|
+
*
|
|
8
|
+
* Path of pages to be fetched
|
|
9
|
+
*/
|
|
6
10
|
paths: string[];
|
|
7
|
-
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 取消请求的信号
|
|
14
|
+
*
|
|
15
|
+
* AbortSignal to cancel request
|
|
16
|
+
*/
|
|
17
|
+
signal?: AbortSignal;
|
|
8
18
|
}
|
|
9
19
|
|
|
10
20
|
export const fetchCommentCount = ({
|
|
@@ -12,19 +22,14 @@ export const fetchCommentCount = ({
|
|
|
12
22
|
lang,
|
|
13
23
|
paths,
|
|
14
24
|
signal,
|
|
15
|
-
}:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.then((data) => errorCheck(data, 'comment count'))
|
|
27
|
-
// TODO: Improve this API
|
|
28
|
-
.then((counts) => (Array.isArray(counts) ? counts : [counts]))
|
|
29
|
-
);
|
|
30
|
-
};
|
|
25
|
+
}: GetCommentCountOptions): Promise<number[]> =>
|
|
26
|
+
fetch(
|
|
27
|
+
`${serverURL}/comment?type=count&url=${encodeURIComponent(
|
|
28
|
+
paths.join(',')
|
|
29
|
+
)}&lang=${lang}`,
|
|
30
|
+
{ signal }
|
|
31
|
+
)
|
|
32
|
+
.then((resp) => <Promise<number | number[]>>resp.json())
|
|
33
|
+
.then((data) => errorCheck(data, 'comment count'))
|
|
34
|
+
// TODO: Improve this API
|
|
35
|
+
.then((counts) => (Array.isArray(counts) ? counts : [counts]));
|
package/src/api/index.ts
CHANGED
package/src/api/login.ts
CHANGED
|
@@ -1,26 +1,69 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
2
|
-
|
|
3
|
-
export interface LoginOptions {
|
|
4
|
-
lang: string;
|
|
5
|
-
serverURL: string;
|
|
6
|
-
}
|
|
2
|
+
import type { BaseAPIOptions } from './utils';
|
|
7
3
|
|
|
8
4
|
export interface UserInfo {
|
|
5
|
+
/**
|
|
6
|
+
* 显示姓名
|
|
7
|
+
*
|
|
8
|
+
* User name displayed
|
|
9
|
+
*/
|
|
9
10
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
10
11
|
display_name: string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 用户电子邮件地址
|
|
15
|
+
*
|
|
16
|
+
* User email
|
|
17
|
+
*/
|
|
11
18
|
email: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 用户网站地址
|
|
22
|
+
*
|
|
23
|
+
* User website
|
|
24
|
+
*/
|
|
12
25
|
url: string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 用户令牌
|
|
29
|
+
*
|
|
30
|
+
* User token
|
|
31
|
+
*/
|
|
13
32
|
token: string;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 用户头像
|
|
36
|
+
*
|
|
37
|
+
* User avatar
|
|
38
|
+
*/
|
|
14
39
|
avatar: string;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 用户邮箱 MD5
|
|
43
|
+
*
|
|
44
|
+
* MD5 of User email
|
|
45
|
+
*/
|
|
15
46
|
mailMd5: string;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 用户对象 ID
|
|
50
|
+
*
|
|
51
|
+
* User object ID
|
|
52
|
+
*/
|
|
16
53
|
objectId: string | number;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 用户身份
|
|
57
|
+
*
|
|
58
|
+
* User role
|
|
59
|
+
*/
|
|
17
60
|
type: 'administrator' | 'guest';
|
|
18
61
|
}
|
|
19
62
|
|
|
20
63
|
export const login = ({
|
|
21
64
|
lang,
|
|
22
65
|
serverURL,
|
|
23
|
-
}:
|
|
66
|
+
}: BaseAPIOptions): Promise<UserInfo & { remember: boolean }> => {
|
|
24
67
|
const width = 450;
|
|
25
68
|
const height = 450;
|
|
26
69
|
const left = (window.innerWidth - width) / 2;
|
package/src/api/pageview.ts
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getArticleCounter, updateArticleCounter } from './articleCounter';
|
|
2
|
+
import type { BaseAPIOptions } from './utils';
|
|
2
3
|
|
|
3
|
-
interface
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
interface GetPageviewOptions extends BaseAPIOptions {
|
|
5
|
+
/**
|
|
6
|
+
* 待获取页面的 path
|
|
7
|
+
*
|
|
8
|
+
* Path of pages
|
|
9
|
+
*/
|
|
6
10
|
paths: string[];
|
|
7
|
-
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 取消请求的信号
|
|
14
|
+
*
|
|
15
|
+
* AbortSignal to cancel request
|
|
16
|
+
*/
|
|
17
|
+
signal?: AbortSignal;
|
|
8
18
|
}
|
|
9
19
|
|
|
10
|
-
export const
|
|
20
|
+
export const getPageviews = ({
|
|
11
21
|
serverURL,
|
|
12
22
|
lang,
|
|
13
23
|
paths,
|
|
14
24
|
signal,
|
|
15
|
-
}:
|
|
16
|
-
|
|
25
|
+
}: GetPageviewOptions): Promise<number[]> =>
|
|
26
|
+
getArticleCounter({
|
|
17
27
|
serverURL,
|
|
18
28
|
lang,
|
|
19
29
|
paths,
|
|
@@ -25,11 +35,13 @@ export const fetchPageviews = ({
|
|
|
25
35
|
number[]
|
|
26
36
|
>;
|
|
27
37
|
|
|
28
|
-
export interface UpdatePageviewOptions {
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
export interface UpdatePageviewOptions extends BaseAPIOptions {
|
|
39
|
+
/**
|
|
40
|
+
* 待更新页面的 path
|
|
41
|
+
*
|
|
42
|
+
* Path of pages
|
|
43
|
+
*/
|
|
31
44
|
path: string;
|
|
32
|
-
action?: 'inc' | 'desc';
|
|
33
45
|
}
|
|
34
46
|
|
|
35
47
|
export const updatePageviews = (
|
|
@@ -38,4 +50,5 @@ export const updatePageviews = (
|
|
|
38
50
|
updateArticleCounter({
|
|
39
51
|
...options,
|
|
40
52
|
type: 'time',
|
|
53
|
+
action: 'inc',
|
|
41
54
|
});
|
package/src/api/recentComment.ts
CHANGED
|
@@ -1,21 +1,37 @@
|
|
|
1
1
|
import { errorCheck } from './utils';
|
|
2
|
+
import type { BaseAPIOptions } from './utils';
|
|
2
3
|
import type { WalineComment } from '../typings';
|
|
3
4
|
|
|
4
|
-
export interface
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
export interface GetRecentCommentOptions extends BaseAPIOptions {
|
|
6
|
+
/**
|
|
7
|
+
* 获取评论的数量
|
|
8
|
+
*
|
|
9
|
+
* Comment numebr to be fetched
|
|
10
|
+
*/
|
|
7
11
|
count: number;
|
|
8
|
-
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 取消请求的信号
|
|
15
|
+
*
|
|
16
|
+
* AbortSignal to cancel request
|
|
17
|
+
*/
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 用户令牌
|
|
22
|
+
*
|
|
23
|
+
* User token
|
|
24
|
+
*/
|
|
9
25
|
token?: string;
|
|
10
26
|
}
|
|
11
27
|
|
|
12
|
-
export const
|
|
28
|
+
export const getRecentComment = ({
|
|
13
29
|
serverURL,
|
|
14
30
|
lang,
|
|
15
31
|
count,
|
|
16
32
|
signal,
|
|
17
33
|
token,
|
|
18
|
-
}:
|
|
34
|
+
}: GetRecentCommentOptions): Promise<WalineComment[]> => {
|
|
19
35
|
const headers: Record<string, string> = {};
|
|
20
36
|
|
|
21
37
|
if (token) headers.Authorization = `Bearer ${token}`;
|
|
@@ -24,6 +40,6 @@ export const fetchRecentComment = ({
|
|
|
24
40
|
signal,
|
|
25
41
|
headers,
|
|
26
42
|
})
|
|
27
|
-
.then((resp) =>
|
|
43
|
+
.then((resp) => <Promise<WalineComment[]>>resp.json())
|
|
28
44
|
.then((data) => errorCheck(data, 'recent comment'));
|
|
29
45
|
};
|