@waline/client 2.13.0 → 2.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +339 -0
- package/dist/api.cjs +1 -1
- package/dist/api.cjs.map +1 -1
- package/dist/api.d.cts +302 -69
- package/dist/api.d.mts +302 -69
- package/dist/api.d.ts +302 -69
- 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 +2 -2
- package/dist/comment.d.mts +2 -2
- package/dist/comment.d.ts +2 -2
- package/dist/comment.js +68 -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 +21 -11
- 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 +121 -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 +25 -19
- package/dist/shim.d.mts +25 -19
- 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 +25 -19
- package/dist/waline.d.mts +25 -19
- package/dist/waline.d.ts +25 -19
- package/dist/waline.js +6787 -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 +52 -22
- package/src/api/comment.ts +158 -55
- package/src/api/commentCount.ts +24 -21
- package/src/api/login.ts +49 -6
- package/src/api/pageview.ts +26 -13
- package/src/api/recentComment.ts +23 -10
- package/src/api/user.ts +24 -18
- package/src/api/utils.ts +33 -10
- package/src/comment.ts +1 -1
- package/src/compact/convert.ts +1 -1
- package/src/components/ArticleReaction.vue +12 -3
- package/src/components/CommentBox.vue +37 -29
- package/src/components/ImageWall.vue +14 -14
- package/src/components/Waline.vue +59 -49
- package/src/config/default.ts +23 -24
- package/src/pageview.ts +3 -3
- package/src/styles/index.scss +3 -3
- package/src/styles/{nomalize.scss → normalize.scss} +0 -0
- package/src/styles/panel.scss +1 -1
- package/src/styles/user-list.scss +158 -0
- package/src/typings/base.ts +5 -1
- package/src/typings/comment.ts +1 -5
- package/src/typings/waline.ts +13 -2
- package/src/utils/config.ts +2 -0
- package/src/utils/date.ts +3 -3
- package/src/utils/emoji.ts +1 -1
- package/src/widgets/recentComments.ts +2 -2
- package/src/widgets/userList.ts +8 -10
- package/src/styles/userlist.scss +0 -116
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@waline/client",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.0",
|
|
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,71 @@
|
|
|
1
|
-
import { JSON_HEADERS
|
|
1
|
+
import { JSON_HEADERS } 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
|
-
)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
serverURL: string;
|
|
34
|
-
lang: string;
|
|
45
|
+
).then((resp) => <Promise<GetArticleCounterResponse>>resp.json());
|
|
46
|
+
|
|
47
|
+
export interface UpdateArticleCounterOptions extends BaseAPIOptions {
|
|
48
|
+
/**
|
|
49
|
+
* 待更新计数器的 path
|
|
50
|
+
*
|
|
51
|
+
* Path of counter to be updated
|
|
52
|
+
*/
|
|
35
53
|
path: string;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 待更新计数器的类型
|
|
57
|
+
*
|
|
58
|
+
* Counter type to be updated
|
|
59
|
+
*/
|
|
36
60
|
type: string;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 更新操作
|
|
64
|
+
*
|
|
65
|
+
* Update operation
|
|
66
|
+
*
|
|
67
|
+
* @default 'inc'
|
|
68
|
+
*/
|
|
37
69
|
action?: 'inc' | 'desc';
|
|
38
70
|
}
|
|
39
71
|
|
|
@@ -48,6 +80,4 @@ export const updateArticleCounter = ({
|
|
|
48
80
|
method: 'POST',
|
|
49
81
|
headers: JSON_HEADERS,
|
|
50
82
|
body: JSON.stringify({ path, type, action }),
|
|
51
|
-
})
|
|
52
|
-
.then((resp) => resp.json() as Promise<number>)
|
|
53
|
-
.then((data) => errorCheck(data, 'article count'));
|
|
83
|
+
}).then((resp) => <Promise<number>>resp.json());
|
package/src/api/comment.ts
CHANGED
|
@@ -1,24 +1,89 @@
|
|
|
1
1
|
import { JSON_HEADERS, errorCheck } from './utils';
|
|
2
|
+
import type { BaseAPIOptions, ErrorStatusResponse } from './utils';
|
|
2
3
|
import type { WalineComment, WalineCommentData } from '../typings';
|
|
3
4
|
|
|
4
|
-
export interface
|
|
5
|
-
|
|
5
|
+
export interface GetCommentOptions extends BaseAPIOptions {
|
|
6
|
+
/**
|
|
7
|
+
* 待获取评论列表的 path
|
|
8
|
+
*
|
|
9
|
+
* Path of comment list
|
|
10
|
+
*/
|
|
6
11
|
path: string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 评论分页数
|
|
15
|
+
*
|
|
16
|
+
* Comment pagination 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 extends ErrorStatusResponse {
|
|
50
|
+
/**
|
|
51
|
+
* 评论数量
|
|
52
|
+
*
|
|
53
|
+
* Comment number
|
|
54
|
+
*/
|
|
16
55
|
count: number;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 评论分页数
|
|
59
|
+
*
|
|
60
|
+
* Comment pagination number
|
|
61
|
+
*/
|
|
62
|
+
page: number;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 每页评论个数
|
|
66
|
+
*
|
|
67
|
+
* Comment number per page
|
|
68
|
+
*/
|
|
69
|
+
pageSize: number;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 评论数据
|
|
73
|
+
*
|
|
74
|
+
* Comment Data
|
|
75
|
+
*/
|
|
17
76
|
data: WalineComment[];
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 页面总数
|
|
80
|
+
*
|
|
81
|
+
* Page number
|
|
82
|
+
*/
|
|
18
83
|
totalPages: number;
|
|
19
84
|
}
|
|
20
85
|
|
|
21
|
-
export const
|
|
86
|
+
export const getComment = ({
|
|
22
87
|
serverURL,
|
|
23
88
|
lang,
|
|
24
89
|
path,
|
|
@@ -27,7 +92,7 @@ export const fetchComment = ({
|
|
|
27
92
|
sortBy,
|
|
28
93
|
signal,
|
|
29
94
|
token,
|
|
30
|
-
}:
|
|
95
|
+
}: GetCommentOptions): Promise<GetCommentResponse> => {
|
|
31
96
|
const headers: Record<string, string> = {};
|
|
32
97
|
|
|
33
98
|
if (token) headers.Authorization = `Bearer ${token}`;
|
|
@@ -38,28 +103,41 @@ export const fetchComment = ({
|
|
|
38
103
|
)}&pageSize=${pageSize}&page=${page}&lang=${lang}&sortBy=${sortBy}`,
|
|
39
104
|
{ signal, headers }
|
|
40
105
|
)
|
|
41
|
-
.then((resp) => resp.json()
|
|
42
|
-
.then((data) => errorCheck(data, 'comment data'));
|
|
106
|
+
.then((resp) => <Promise<GetCommentResponse>>resp.json())
|
|
107
|
+
.then((data) => errorCheck(data, 'Get comment data'));
|
|
43
108
|
};
|
|
44
109
|
|
|
45
|
-
export interface
|
|
46
|
-
|
|
47
|
-
|
|
110
|
+
export interface AddCommentOptions extends BaseAPIOptions {
|
|
111
|
+
/**
|
|
112
|
+
* 用户令牌
|
|
113
|
+
*
|
|
114
|
+
* User token
|
|
115
|
+
*/
|
|
48
116
|
token?: string;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 用户待提交的评论数据
|
|
120
|
+
*
|
|
121
|
+
* Comment data being submitted by user
|
|
122
|
+
*/
|
|
49
123
|
comment: WalineCommentData;
|
|
50
124
|
}
|
|
51
125
|
|
|
52
|
-
export interface
|
|
126
|
+
export interface AddCommentResponse extends ErrorStatusResponse {
|
|
127
|
+
/**
|
|
128
|
+
* 渲染好的评论数据
|
|
129
|
+
*
|
|
130
|
+
* Comment data rendered
|
|
131
|
+
*/
|
|
53
132
|
data?: WalineComment;
|
|
54
|
-
errmsg?: string;
|
|
55
133
|
}
|
|
56
134
|
|
|
57
|
-
export const
|
|
135
|
+
export const addComment = ({
|
|
58
136
|
serverURL,
|
|
59
137
|
lang,
|
|
60
138
|
token,
|
|
61
139
|
comment,
|
|
62
|
-
}:
|
|
140
|
+
}: AddCommentOptions): Promise<AddCommentResponse> => {
|
|
63
141
|
const headers: Record<string, string> = {
|
|
64
142
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
65
143
|
'Content-Type': 'application/json',
|
|
@@ -67,67 +145,90 @@ export const postComment = ({
|
|
|
67
145
|
|
|
68
146
|
if (token) headers.Authorization = `Bearer ${token}`;
|
|
69
147
|
|
|
70
|
-
if (comment.eid) {
|
|
71
|
-
return fetch(`${serverURL}/comment/${comment.eid}?lang=${lang}`, {
|
|
72
|
-
method: 'PUT',
|
|
73
|
-
headers,
|
|
74
|
-
body: JSON.stringify(comment),
|
|
75
|
-
}).then((resp) => resp.json() as Promise<PostCommentResponse>);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
148
|
return fetch(`${serverURL}/comment?lang=${lang}`, {
|
|
79
149
|
method: 'POST',
|
|
80
150
|
headers,
|
|
81
151
|
body: JSON.stringify(comment),
|
|
82
|
-
}).then((resp) => resp.json()
|
|
152
|
+
}).then((resp) => <Promise<AddCommentResponse>>resp.json());
|
|
83
153
|
};
|
|
84
154
|
|
|
85
|
-
export interface DeleteCommentOptions {
|
|
86
|
-
serverURL: string;
|
|
87
|
-
lang: string;
|
|
155
|
+
export interface DeleteCommentOptions extends BaseAPIOptions {
|
|
88
156
|
token: string;
|
|
89
157
|
objectId: string | number;
|
|
90
158
|
}
|
|
91
159
|
|
|
160
|
+
export interface DeleteCommentResponse extends ErrorStatusResponse {
|
|
161
|
+
data: '';
|
|
162
|
+
}
|
|
163
|
+
|
|
92
164
|
export const deleteComment = ({
|
|
93
165
|
serverURL,
|
|
94
166
|
lang,
|
|
95
167
|
token,
|
|
96
168
|
objectId,
|
|
97
|
-
}: DeleteCommentOptions): Promise<
|
|
169
|
+
}: DeleteCommentOptions): Promise<DeleteCommentResponse> =>
|
|
98
170
|
fetch(`${serverURL}/comment/${objectId}?lang=${lang}`, {
|
|
99
171
|
method: 'DELETE',
|
|
100
172
|
headers: {
|
|
101
173
|
Authorization: `Bearer ${token}`,
|
|
102
174
|
},
|
|
103
|
-
})
|
|
175
|
+
})
|
|
176
|
+
.then((resp) => <Promise<DeleteCommentResponse>>resp.json())
|
|
177
|
+
.then((resp) => errorCheck(resp, 'Delete comment'));
|
|
178
|
+
|
|
179
|
+
export interface UpdateCommentOptions extends BaseAPIOptions {
|
|
180
|
+
/**
|
|
181
|
+
* 用户令牌
|
|
182
|
+
*
|
|
183
|
+
* User token
|
|
184
|
+
*/
|
|
185
|
+
token: string;
|
|
104
186
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
187
|
+
/**
|
|
188
|
+
* 评论的 ID
|
|
189
|
+
*
|
|
190
|
+
* Comment ID
|
|
191
|
+
*/
|
|
108
192
|
objectId: number | string;
|
|
109
|
-
like: boolean;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export const likeComment = ({
|
|
113
|
-
serverURL,
|
|
114
|
-
lang,
|
|
115
|
-
objectId,
|
|
116
|
-
like,
|
|
117
|
-
}: LikeCommentOptions): Promise<void> =>
|
|
118
|
-
fetch(`${serverURL}/comment/${objectId}?lang=${lang}`, {
|
|
119
|
-
method: 'PUT',
|
|
120
|
-
headers: JSON_HEADERS,
|
|
121
|
-
body: JSON.stringify({ like }),
|
|
122
|
-
}).then((resp) => resp.json() as Promise<void>);
|
|
123
193
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
194
|
+
/**
|
|
195
|
+
* 评论数据
|
|
196
|
+
*
|
|
197
|
+
* Comment data
|
|
198
|
+
*/
|
|
199
|
+
comment?: WalineCommentData;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* 点赞还是取消点赞
|
|
203
|
+
*
|
|
204
|
+
* Like or dislike
|
|
205
|
+
*/
|
|
206
|
+
like?: boolean;
|
|
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;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export interface UpdateCommentResponse extends ErrorStatusResponse {
|
|
226
|
+
/**
|
|
227
|
+
* 更新后的评论数据
|
|
228
|
+
*
|
|
229
|
+
* Comment data rendered
|
|
230
|
+
*/
|
|
231
|
+
data: WalineComment;
|
|
131
232
|
}
|
|
132
233
|
|
|
133
234
|
export const updateComment = ({
|
|
@@ -136,7 +237,7 @@ export const updateComment = ({
|
|
|
136
237
|
token,
|
|
137
238
|
objectId,
|
|
138
239
|
...data
|
|
139
|
-
}: UpdateCommentOptions): Promise<
|
|
240
|
+
}: UpdateCommentOptions): Promise<UpdateCommentResponse> =>
|
|
140
241
|
fetch(`${serverURL}/comment/${objectId}?lang=${lang}`, {
|
|
141
242
|
method: 'PUT',
|
|
142
243
|
headers: {
|
|
@@ -144,4 +245,6 @@ export const updateComment = ({
|
|
|
144
245
|
Authorization: `Bearer ${token}`,
|
|
145
246
|
},
|
|
146
247
|
body: JSON.stringify(data),
|
|
147
|
-
})
|
|
248
|
+
})
|
|
249
|
+
.then((resp) => <Promise<UpdateCommentResponse>>resp.json())
|
|
250
|
+
.then((resp) => errorCheck(resp, 'Update comment'));
|
package/src/api/commentCount.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { BaseAPIOptions } from './utils';
|
|
2
2
|
|
|
3
|
-
export interface
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export interface GetCommentCountOptions extends BaseAPIOptions {
|
|
4
|
+
/**
|
|
5
|
+
* 待获取评论数的 path
|
|
6
|
+
*
|
|
7
|
+
* Path of pages to be fetched
|
|
8
|
+
*/
|
|
6
9
|
paths: string[];
|
|
7
|
-
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 取消请求的信号
|
|
13
|
+
*
|
|
14
|
+
* AbortSignal to cancel request
|
|
15
|
+
*/
|
|
16
|
+
signal?: AbortSignal;
|
|
8
17
|
}
|
|
9
18
|
|
|
10
19
|
export const fetchCommentCount = ({
|
|
@@ -12,19 +21,13 @@ export const fetchCommentCount = ({
|
|
|
12
21
|
lang,
|
|
13
22
|
paths,
|
|
14
23
|
signal,
|
|
15
|
-
}:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
)
|
|
25
|
-
.then((resp) => resp.json() as Promise<number | number[]>)
|
|
26
|
-
.then((data) => errorCheck(data, 'comment count'))
|
|
27
|
-
// TODO: Improve this API
|
|
28
|
-
.then((counts) => (Array.isArray(counts) ? counts : [counts]))
|
|
29
|
-
);
|
|
30
|
-
};
|
|
24
|
+
}: GetCommentCountOptions): Promise<number[]> =>
|
|
25
|
+
fetch(
|
|
26
|
+
`${serverURL}/comment?type=count&url=${encodeURIComponent(
|
|
27
|
+
paths.join(',')
|
|
28
|
+
)}&lang=${lang}`,
|
|
29
|
+
{ signal }
|
|
30
|
+
)
|
|
31
|
+
.then((resp) => <Promise<number | number[]>>resp.json())
|
|
32
|
+
// TODO: Improve this API
|
|
33
|
+
.then((counts) => (Array.isArray(counts) ? counts : [counts]));
|
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 getPageview = ({
|
|
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,17 +35,20 @@ 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
|
-
export const
|
|
47
|
+
export const updatePageview = (
|
|
36
48
|
options: UpdatePageviewOptions
|
|
37
49
|
): Promise<number> =>
|
|
38
50
|
updateArticleCounter({
|
|
39
51
|
...options,
|
|
40
52
|
type: 'time',
|
|
53
|
+
action: 'inc',
|
|
41
54
|
});
|