@waline/client 2.15.8 → 3.0.0-alpha.2
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/dist/comment.cjs +1 -1
- package/dist/comment.cjs.map +1 -1
- package/dist/comment.d.cts +2 -1
- package/dist/comment.d.mts +2 -1
- package/dist/comment.d.ts +2 -1
- package/dist/comment.js +1 -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 +8 -1
- package/dist/component.mjs.map +1 -1
- package/dist/pageview.cjs +1 -1
- package/dist/pageview.cjs.map +1 -1
- package/dist/pageview.d.cts +2 -1
- package/dist/pageview.d.mts +2 -1
- package/dist/pageview.d.ts +2 -1
- package/dist/pageview.js +1 -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 +8 -1
- package/dist/shim.cjs.map +1 -1
- package/dist/shim.d.cts +7 -82
- package/dist/shim.d.mts +7 -82
- package/dist/shim.mjs +8 -1
- package/dist/shim.mjs.map +1 -1
- package/dist/waline.cjs +53 -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 +7 -82
- package/dist/waline.d.mts +7 -82
- package/dist/waline.d.ts +7 -82
- package/dist/waline.js +53 -1
- package/dist/waline.js.map +1 -1
- package/dist/waline.mjs +53 -1
- package/dist/waline.mjs.map +1 -1
- package/package.json +20 -53
- package/dist/api.cjs +0 -2
- package/dist/api.cjs.map +0 -1
- package/dist/api.d.cts +0 -445
- package/dist/api.d.mts +0 -445
- package/dist/api.d.ts +0 -445
- package/dist/api.mjs +0 -2
- package/dist/api.mjs.map +0 -1
- package/dist/legacy.umd.d.ts +0 -628
- package/dist/legacy.umd.js +0 -2
- package/dist/legacy.umd.js.map +0 -1
- package/src/api/articleCounter.ts +0 -82
- package/src/api/comment.ts +0 -258
- package/src/api/commentCount.ts +0 -33
- package/src/api/index.ts +0 -7
- package/src/api/login.ts +0 -96
- package/src/api/pageview.ts +0 -54
- package/src/api/recentComment.ts +0 -42
- package/src/api/user.ts +0 -44
- package/src/api/utils.ts +0 -46
- package/src/comment.ts +0 -69
- package/src/compact/convert.ts +0 -80
- package/src/compact/dropped.ts +0 -35
- package/src/compact/index.ts +0 -4
- package/src/compact/logger.ts +0 -5
- package/src/compact/v1.ts +0 -103
- package/src/compact/valine.ts +0 -132
- package/src/components/ArticleReaction.vue +0 -159
- package/src/components/CommentBox.vue +0 -807
- package/src/components/CommentCard.vue +0 -271
- package/src/components/Icons.ts +0 -181
- package/src/components/ImageWall.vue +0 -169
- package/src/components/WalineComment.vue +0 -353
- package/src/composables/index.ts +0 -6
- package/src/composables/inputs.ts +0 -17
- package/src/composables/like.ts +0 -13
- package/src/composables/reaction.ts +0 -15
- package/src/composables/recaptchaV3.ts +0 -19
- package/src/composables/turnstile.ts +0 -50
- package/src/composables/userInfo.ts +0 -16
- package/src/config/default.ts +0 -93
- package/src/config/highlighter.ts +0 -74
- package/src/config/i18n/en.ts +0 -53
- package/src/config/i18n/generate.ts +0 -58
- package/src/config/i18n/index.ts +0 -30
- package/src/config/i18n/jp.ts +0 -53
- package/src/config/i18n/pt-BR.ts +0 -53
- package/src/config/i18n/ru.ts +0 -53
- package/src/config/i18n/vi-VN.ts +0 -53
- package/src/config/i18n/zh-CN.ts +0 -53
- package/src/config/i18n/zh-TW.ts +0 -53
- package/src/config/index.ts +0 -3
- package/src/entries/api.ts +0 -1
- package/src/entries/comment.ts +0 -2
- package/src/entries/components.ts +0 -2
- package/src/entries/full.ts +0 -7
- package/src/entries/init.ts +0 -4
- package/src/entries/legacy.ts +0 -31
- package/src/entries/pageview.ts +0 -2
- package/src/init.ts +0 -112
- package/src/pageview.ts +0 -116
- package/src/shims-vue.d.ts +0 -6
- package/src/styles/base.scss +0 -67
- package/src/styles/card.scss +0 -258
- package/src/styles/config.scss +0 -52
- package/src/styles/emoji.scss +0 -137
- package/src/styles/gif.scss +0 -73
- package/src/styles/helpers/_svg.scss +0 -51
- package/src/styles/highlight.scss +0 -138
- package/src/styles/index.scss +0 -12
- package/src/styles/layout.scss +0 -105
- package/src/styles/meta.scss +0 -82
- package/src/styles/normalize.scss +0 -117
- package/src/styles/panel.scss +0 -286
- package/src/styles/reaction.scss +0 -103
- package/src/styles/recent.scss +0 -3
- package/src/styles/user-list.scss +0 -159
- package/src/typings/base.ts +0 -123
- package/src/typings/comment.ts +0 -94
- package/src/typings/index.ts +0 -5
- package/src/typings/locale.ts +0 -73
- package/src/typings/options.ts +0 -44
- package/src/typings/waline.ts +0 -251
- package/src/utils/config.ts +0 -122
- package/src/utils/darkmode.ts +0 -11
- package/src/utils/date.ts +0 -71
- package/src/utils/email.ts +0 -8
- package/src/utils/emoji.ts +0 -73
- package/src/utils/error.ts +0 -3
- package/src/utils/getRoot.ts +0 -8
- package/src/utils/image.ts +0 -10
- package/src/utils/index.ts +0 -13
- package/src/utils/markdown.ts +0 -41
- package/src/utils/markedMathExtension.ts +0 -54
- package/src/utils/path.ts +0 -15
- package/src/utils/query.ts +0 -2
- package/src/utils/userAgent.ts +0 -31
- package/src/utils/wordCount.ts +0 -31
- package/src/version.ts +0 -3
- package/src/widgets/index.ts +0 -2
- package/src/widgets/recentComments.ts +0 -93
- package/src/widgets/userList.ts +0 -136
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { type BaseAPIOptions, JSON_HEADERS } from './utils.js';
|
|
2
|
-
|
|
3
|
-
export interface GetArticleCounterOptions extends BaseAPIOptions {
|
|
4
|
-
/**
|
|
5
|
-
* 待获取计数器的 path
|
|
6
|
-
*
|
|
7
|
-
* Path of counters
|
|
8
|
-
*/
|
|
9
|
-
paths: string[];
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* 待获取计数器的类型
|
|
13
|
-
*
|
|
14
|
-
* Counter type to be fetched
|
|
15
|
-
*/
|
|
16
|
-
type: string[];
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 取消请求的信号
|
|
20
|
-
*
|
|
21
|
-
* AbortSignal to cancel request
|
|
22
|
-
*/
|
|
23
|
-
signal?: AbortSignal;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export type GetArticleCounterResponse =
|
|
27
|
-
| Record<string, number>[]
|
|
28
|
-
| Record<string, number>
|
|
29
|
-
| number[]
|
|
30
|
-
| number;
|
|
31
|
-
|
|
32
|
-
export const getArticleCounter = ({
|
|
33
|
-
serverURL,
|
|
34
|
-
lang,
|
|
35
|
-
paths,
|
|
36
|
-
type,
|
|
37
|
-
signal,
|
|
38
|
-
}: GetArticleCounterOptions): Promise<GetArticleCounterResponse> =>
|
|
39
|
-
fetch(
|
|
40
|
-
`${serverURL}/article?path=${encodeURIComponent(
|
|
41
|
-
paths.join(','),
|
|
42
|
-
)}&type=${encodeURIComponent(type.join(','))}&lang=${lang}`,
|
|
43
|
-
{ signal },
|
|
44
|
-
).then((resp) => <Promise<GetArticleCounterResponse>>resp.json());
|
|
45
|
-
|
|
46
|
-
export interface UpdateArticleCounterOptions extends BaseAPIOptions {
|
|
47
|
-
/**
|
|
48
|
-
* 待更新计数器的 path
|
|
49
|
-
*
|
|
50
|
-
* Path of counter to be updated
|
|
51
|
-
*/
|
|
52
|
-
path: string;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 待更新计数器的类型
|
|
56
|
-
*
|
|
57
|
-
* Counter type to be updated
|
|
58
|
-
*/
|
|
59
|
-
type: string;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* 更新操作
|
|
63
|
-
*
|
|
64
|
-
* Update operation
|
|
65
|
-
*
|
|
66
|
-
* @default 'inc'
|
|
67
|
-
*/
|
|
68
|
-
action?: 'inc' | 'desc';
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export const updateArticleCounter = ({
|
|
72
|
-
serverURL,
|
|
73
|
-
lang,
|
|
74
|
-
path,
|
|
75
|
-
type,
|
|
76
|
-
action,
|
|
77
|
-
}: UpdateArticleCounterOptions): Promise<number> =>
|
|
78
|
-
fetch(`${serverURL}/article?lang=${lang}`, {
|
|
79
|
-
method: 'POST',
|
|
80
|
-
headers: JSON_HEADERS,
|
|
81
|
-
body: JSON.stringify({ path, type, action }),
|
|
82
|
-
}).then((resp) => <Promise<number>>resp.json());
|
package/src/api/comment.ts
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type BaseAPIOptions,
|
|
3
|
-
type ErrorStatusResponse,
|
|
4
|
-
JSON_HEADERS,
|
|
5
|
-
errorCheck,
|
|
6
|
-
} from './utils.js';
|
|
7
|
-
import {
|
|
8
|
-
type WalineComment,
|
|
9
|
-
type WalineCommentData,
|
|
10
|
-
} from '../typings/index.js';
|
|
11
|
-
|
|
12
|
-
export interface GetCommentOptions extends BaseAPIOptions {
|
|
13
|
-
/**
|
|
14
|
-
* 待获取评论列表的 path
|
|
15
|
-
*
|
|
16
|
-
* Path of comment list
|
|
17
|
-
*/
|
|
18
|
-
path: string;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 评论分页数
|
|
22
|
-
*
|
|
23
|
-
* Comment pagination number
|
|
24
|
-
*/
|
|
25
|
-
page: number;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 每页评论个数
|
|
29
|
-
*
|
|
30
|
-
* Comment number per page
|
|
31
|
-
*/
|
|
32
|
-
pageSize: number;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 排序方式
|
|
36
|
-
*
|
|
37
|
-
* Sort method
|
|
38
|
-
*/
|
|
39
|
-
sortBy: string;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 用户令牌
|
|
43
|
-
*
|
|
44
|
-
* User token
|
|
45
|
-
*/
|
|
46
|
-
token?: string;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 取消请求的信号
|
|
50
|
-
*
|
|
51
|
-
* AbortSignal to cancel request
|
|
52
|
-
*/
|
|
53
|
-
signal?: AbortSignal;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface GetCommentResponse extends ErrorStatusResponse {
|
|
57
|
-
/**
|
|
58
|
-
* 评论数量
|
|
59
|
-
*
|
|
60
|
-
* Comment number
|
|
61
|
-
*/
|
|
62
|
-
count: number;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* 评论分页数
|
|
66
|
-
*
|
|
67
|
-
* Comment pagination number
|
|
68
|
-
*/
|
|
69
|
-
page: number;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* 每页评论个数
|
|
73
|
-
*
|
|
74
|
-
* Comment number per page
|
|
75
|
-
*/
|
|
76
|
-
pageSize: number;
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* 评论数据
|
|
80
|
-
*
|
|
81
|
-
* Comment Data
|
|
82
|
-
*/
|
|
83
|
-
data: WalineComment[];
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* 页面总数
|
|
87
|
-
*
|
|
88
|
-
* Page number
|
|
89
|
-
*/
|
|
90
|
-
totalPages: number;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export const getComment = ({
|
|
94
|
-
serverURL,
|
|
95
|
-
lang,
|
|
96
|
-
path,
|
|
97
|
-
page,
|
|
98
|
-
pageSize,
|
|
99
|
-
sortBy,
|
|
100
|
-
signal,
|
|
101
|
-
token,
|
|
102
|
-
}: GetCommentOptions): Promise<GetCommentResponse> => {
|
|
103
|
-
const headers: Record<string, string> = {};
|
|
104
|
-
|
|
105
|
-
if (token) headers.Authorization = `Bearer ${token}`;
|
|
106
|
-
|
|
107
|
-
return fetch(
|
|
108
|
-
`${serverURL}/comment?path=${encodeURIComponent(
|
|
109
|
-
path,
|
|
110
|
-
)}&pageSize=${pageSize}&page=${page}&lang=${lang}&sortBy=${sortBy}`,
|
|
111
|
-
{ signal, headers },
|
|
112
|
-
)
|
|
113
|
-
.then((resp) => <Promise<GetCommentResponse>>resp.json())
|
|
114
|
-
.then((data) => errorCheck(data, 'Get comment data'));
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export interface AddCommentOptions extends BaseAPIOptions {
|
|
118
|
-
/**
|
|
119
|
-
* 用户令牌
|
|
120
|
-
*
|
|
121
|
-
* User token
|
|
122
|
-
*/
|
|
123
|
-
token?: string;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* 用户待提交的评论数据
|
|
127
|
-
*
|
|
128
|
-
* Comment data being submitted by user
|
|
129
|
-
*/
|
|
130
|
-
comment: WalineCommentData;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export interface AddCommentResponse extends ErrorStatusResponse {
|
|
134
|
-
/**
|
|
135
|
-
* 渲染好的评论数据
|
|
136
|
-
*
|
|
137
|
-
* Comment data rendered
|
|
138
|
-
*/
|
|
139
|
-
data?: WalineComment;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export const addComment = ({
|
|
143
|
-
serverURL,
|
|
144
|
-
lang,
|
|
145
|
-
token,
|
|
146
|
-
comment,
|
|
147
|
-
}: AddCommentOptions): Promise<AddCommentResponse> => {
|
|
148
|
-
const headers: Record<string, string> = {
|
|
149
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
150
|
-
'Content-Type': 'application/json',
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
if (token) headers.Authorization = `Bearer ${token}`;
|
|
154
|
-
|
|
155
|
-
return fetch(`${serverURL}/comment?lang=${lang}`, {
|
|
156
|
-
method: 'POST',
|
|
157
|
-
headers,
|
|
158
|
-
body: JSON.stringify(comment),
|
|
159
|
-
}).then((resp) => <Promise<AddCommentResponse>>resp.json());
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
export interface DeleteCommentOptions extends BaseAPIOptions {
|
|
163
|
-
token: string;
|
|
164
|
-
objectId: string | number;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export interface DeleteCommentResponse extends ErrorStatusResponse {
|
|
168
|
-
data: '';
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export const deleteComment = ({
|
|
172
|
-
serverURL,
|
|
173
|
-
lang,
|
|
174
|
-
token,
|
|
175
|
-
objectId,
|
|
176
|
-
}: DeleteCommentOptions): Promise<DeleteCommentResponse> =>
|
|
177
|
-
fetch(`${serverURL}/comment/${objectId}?lang=${lang}`, {
|
|
178
|
-
method: 'DELETE',
|
|
179
|
-
headers: {
|
|
180
|
-
Authorization: `Bearer ${token}`,
|
|
181
|
-
},
|
|
182
|
-
})
|
|
183
|
-
.then((resp) => <Promise<DeleteCommentResponse>>resp.json())
|
|
184
|
-
.then((resp) => errorCheck(resp, 'Delete comment'));
|
|
185
|
-
|
|
186
|
-
interface UpdateWalineCommentData extends Partial<WalineCommentData> {
|
|
187
|
-
/**
|
|
188
|
-
* 点赞还是取消点赞
|
|
189
|
-
*
|
|
190
|
-
* Like or dislike
|
|
191
|
-
*/
|
|
192
|
-
like?: boolean;
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* 评论的状态
|
|
196
|
-
*
|
|
197
|
-
* Comment status
|
|
198
|
-
*/
|
|
199
|
-
status?: 'approved' | 'waiting' | 'spam';
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* 评论指定状态
|
|
203
|
-
*
|
|
204
|
-
* Comment sticky status
|
|
205
|
-
*
|
|
206
|
-
* @description 0 means not sticky and 1 means sticky
|
|
207
|
-
*/
|
|
208
|
-
sticky?: 0 | 1;
|
|
209
|
-
}
|
|
210
|
-
export interface UpdateCommentOptions extends BaseAPIOptions {
|
|
211
|
-
/**
|
|
212
|
-
* 用户令牌
|
|
213
|
-
*
|
|
214
|
-
* User token
|
|
215
|
-
*/
|
|
216
|
-
token: string;
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* 评论的 ID
|
|
220
|
-
*
|
|
221
|
-
* Comment ID
|
|
222
|
-
*/
|
|
223
|
-
objectId: number | string;
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* 评论数据
|
|
227
|
-
*
|
|
228
|
-
* Comment data
|
|
229
|
-
*/
|
|
230
|
-
comment?: UpdateWalineCommentData;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export interface UpdateCommentResponse extends ErrorStatusResponse {
|
|
234
|
-
/**
|
|
235
|
-
* 更新后的评论数据
|
|
236
|
-
*
|
|
237
|
-
* Comment data rendered
|
|
238
|
-
*/
|
|
239
|
-
data: WalineComment;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
export const updateComment = ({
|
|
243
|
-
serverURL,
|
|
244
|
-
lang,
|
|
245
|
-
token,
|
|
246
|
-
objectId,
|
|
247
|
-
comment,
|
|
248
|
-
}: UpdateCommentOptions): Promise<UpdateCommentResponse> =>
|
|
249
|
-
fetch(`${serverURL}/comment/${objectId}?lang=${lang}`, {
|
|
250
|
-
method: 'PUT',
|
|
251
|
-
headers: {
|
|
252
|
-
...JSON_HEADERS,
|
|
253
|
-
Authorization: `Bearer ${token}`,
|
|
254
|
-
},
|
|
255
|
-
body: JSON.stringify(comment),
|
|
256
|
-
})
|
|
257
|
-
.then((resp) => <Promise<UpdateCommentResponse>>resp.json())
|
|
258
|
-
.then((resp) => errorCheck(resp, 'Update comment'));
|
package/src/api/commentCount.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { type BaseAPIOptions } from './utils.js';
|
|
2
|
-
|
|
3
|
-
export interface GetCommentCountOptions extends BaseAPIOptions {
|
|
4
|
-
/**
|
|
5
|
-
* 待获取评论数的 path
|
|
6
|
-
*
|
|
7
|
-
* Path of pages to be fetched
|
|
8
|
-
*/
|
|
9
|
-
paths: string[];
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* 取消请求的信号
|
|
13
|
-
*
|
|
14
|
-
* AbortSignal to cancel request
|
|
15
|
-
*/
|
|
16
|
-
signal?: AbortSignal;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const fetchCommentCount = ({
|
|
20
|
-
serverURL,
|
|
21
|
-
lang,
|
|
22
|
-
paths,
|
|
23
|
-
signal,
|
|
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/index.ts
DELETED
package/src/api/login.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
2
|
-
import { type BaseAPIOptions } from './utils.js';
|
|
3
|
-
|
|
4
|
-
export interface UserInfo {
|
|
5
|
-
/**
|
|
6
|
-
* 显示姓名
|
|
7
|
-
*
|
|
8
|
-
* User name displayed
|
|
9
|
-
*/
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
11
|
-
display_name: string;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 用户电子邮件地址
|
|
15
|
-
*
|
|
16
|
-
* User email
|
|
17
|
-
*/
|
|
18
|
-
email: string;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 用户网站地址
|
|
22
|
-
*
|
|
23
|
-
* User website
|
|
24
|
-
*/
|
|
25
|
-
url: string;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 用户令牌
|
|
29
|
-
*
|
|
30
|
-
* User token
|
|
31
|
-
*/
|
|
32
|
-
token: string;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 用户头像
|
|
36
|
-
*
|
|
37
|
-
* User avatar
|
|
38
|
-
*/
|
|
39
|
-
avatar: string;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 用户邮箱 MD5
|
|
43
|
-
*
|
|
44
|
-
* MD5 of User email
|
|
45
|
-
*/
|
|
46
|
-
mailMd5: string;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 用户对象 ID
|
|
50
|
-
*
|
|
51
|
-
* User object ID
|
|
52
|
-
*/
|
|
53
|
-
objectId: string | number;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* 用户身份
|
|
57
|
-
*
|
|
58
|
-
* User role
|
|
59
|
-
*/
|
|
60
|
-
type: 'administrator' | 'guest';
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export const login = ({
|
|
64
|
-
lang,
|
|
65
|
-
serverURL,
|
|
66
|
-
}: BaseAPIOptions): Promise<UserInfo & { remember: boolean }> => {
|
|
67
|
-
const width = 450;
|
|
68
|
-
const height = 450;
|
|
69
|
-
const left = (window.innerWidth - width) / 2;
|
|
70
|
-
const top = (window.innerHeight - height) / 2;
|
|
71
|
-
|
|
72
|
-
const handler = window.open(
|
|
73
|
-
`${serverURL}/ui/login?lng=${encodeURIComponent(lang)}`,
|
|
74
|
-
'_blank',
|
|
75
|
-
`width=${width},height=${height},left=${left},top=${top},scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no`,
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
handler?.postMessage({ type: 'TOKEN', data: null }, '*');
|
|
79
|
-
|
|
80
|
-
return new Promise((resolve) => {
|
|
81
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
82
|
-
const receiver = ({ data }: any): void => {
|
|
83
|
-
if (!data || typeof data !== 'object' || data.type !== 'userInfo') return;
|
|
84
|
-
|
|
85
|
-
if (data.data.token) {
|
|
86
|
-
handler?.close();
|
|
87
|
-
|
|
88
|
-
window.removeEventListener('message', receiver);
|
|
89
|
-
|
|
90
|
-
resolve(data.data as UserInfo & { remember: boolean });
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
window.addEventListener('message', receiver);
|
|
95
|
-
});
|
|
96
|
-
};
|
package/src/api/pageview.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { getArticleCounter, updateArticleCounter } from './articleCounter.js';
|
|
2
|
-
import { type BaseAPIOptions } from './utils.js';
|
|
3
|
-
|
|
4
|
-
interface GetPageviewOptions extends BaseAPIOptions {
|
|
5
|
-
/**
|
|
6
|
-
* 待获取页面的 path
|
|
7
|
-
*
|
|
8
|
-
* Path of pages
|
|
9
|
-
*/
|
|
10
|
-
paths: string[];
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 取消请求的信号
|
|
14
|
-
*
|
|
15
|
-
* AbortSignal to cancel request
|
|
16
|
-
*/
|
|
17
|
-
signal?: AbortSignal;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const getPageview = ({
|
|
21
|
-
serverURL,
|
|
22
|
-
lang,
|
|
23
|
-
paths,
|
|
24
|
-
signal,
|
|
25
|
-
}: GetPageviewOptions): Promise<number[]> =>
|
|
26
|
-
getArticleCounter({
|
|
27
|
-
serverURL,
|
|
28
|
-
lang,
|
|
29
|
-
paths,
|
|
30
|
-
type: ['time'],
|
|
31
|
-
signal,
|
|
32
|
-
})
|
|
33
|
-
// TODO: Improve this API
|
|
34
|
-
.then((counts) => (Array.isArray(counts) ? counts : [counts])) as Promise<
|
|
35
|
-
number[]
|
|
36
|
-
>;
|
|
37
|
-
|
|
38
|
-
export interface UpdatePageviewOptions extends BaseAPIOptions {
|
|
39
|
-
/**
|
|
40
|
-
* 待更新页面的 path
|
|
41
|
-
*
|
|
42
|
-
* Path of pages
|
|
43
|
-
*/
|
|
44
|
-
path: string;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const updatePageview = (
|
|
48
|
-
options: UpdatePageviewOptions,
|
|
49
|
-
): Promise<number> =>
|
|
50
|
-
updateArticleCounter({
|
|
51
|
-
...options,
|
|
52
|
-
type: 'time',
|
|
53
|
-
action: 'inc',
|
|
54
|
-
});
|
package/src/api/recentComment.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { type BaseAPIOptions } from './utils.js';
|
|
2
|
-
import { type WalineComment } from '../typings/index.js';
|
|
3
|
-
|
|
4
|
-
export interface GetRecentCommentOptions extends BaseAPIOptions {
|
|
5
|
-
/**
|
|
6
|
-
* 获取评论的数量
|
|
7
|
-
*
|
|
8
|
-
* Comment number to be fetched
|
|
9
|
-
*/
|
|
10
|
-
count: number;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 取消请求的信号
|
|
14
|
-
*
|
|
15
|
-
* AbortSignal to cancel request
|
|
16
|
-
*/
|
|
17
|
-
signal?: AbortSignal;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 用户令牌
|
|
21
|
-
*
|
|
22
|
-
* User token
|
|
23
|
-
*/
|
|
24
|
-
token?: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const getRecentComment = ({
|
|
28
|
-
serverURL,
|
|
29
|
-
lang,
|
|
30
|
-
count,
|
|
31
|
-
signal,
|
|
32
|
-
token,
|
|
33
|
-
}: GetRecentCommentOptions): Promise<WalineComment[]> => {
|
|
34
|
-
const headers: Record<string, string> = {};
|
|
35
|
-
|
|
36
|
-
if (token) headers.Authorization = `Bearer ${token}`;
|
|
37
|
-
|
|
38
|
-
return fetch(`${serverURL}/comment?type=recent&count=${count}&lang=${lang}`, {
|
|
39
|
-
signal,
|
|
40
|
-
headers,
|
|
41
|
-
}).then((resp) => <Promise<WalineComment[]>>resp.json());
|
|
42
|
-
};
|
package/src/api/user.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type BaseAPIOptions,
|
|
3
|
-
errorCheck,
|
|
4
|
-
ErrorStatusResponse,
|
|
5
|
-
} from './utils.js';
|
|
6
|
-
import { type WalineComment } from '../typings/index.js';
|
|
7
|
-
|
|
8
|
-
export interface GetUserListOptions extends BaseAPIOptions {
|
|
9
|
-
/**
|
|
10
|
-
* 每页个数
|
|
11
|
-
*
|
|
12
|
-
* Number per page
|
|
13
|
-
*/
|
|
14
|
-
pageSize: number;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* 取消请求的信号
|
|
18
|
-
*
|
|
19
|
-
* AbortSignal to cancel request
|
|
20
|
-
*/
|
|
21
|
-
signal?: AbortSignal;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface WalineUser
|
|
25
|
-
extends Pick<WalineComment, 'nick' | 'link' | 'avatar' | 'label' | 'level'> {
|
|
26
|
-
count: number;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface GetUserListResponse extends ErrorStatusResponse {
|
|
30
|
-
data: WalineUser[];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const getUserList = ({
|
|
34
|
-
serverURL,
|
|
35
|
-
signal,
|
|
36
|
-
pageSize,
|
|
37
|
-
lang,
|
|
38
|
-
}: GetUserListOptions): Promise<WalineUser[]> =>
|
|
39
|
-
fetch(`${serverURL}/user?pageSize=${pageSize}&lang=${lang}`, {
|
|
40
|
-
signal,
|
|
41
|
-
})
|
|
42
|
-
.then((resp) => <Promise<GetUserListResponse>>resp.json())
|
|
43
|
-
.then((resp) => errorCheck(resp, 'user list'))
|
|
44
|
-
.then((resp) => resp.data);
|
package/src/api/utils.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export interface BaseAPIOptions {
|
|
2
|
-
/**
|
|
3
|
-
* Waline 服务端地址
|
|
4
|
-
*
|
|
5
|
-
* Waline serverURL
|
|
6
|
-
*/
|
|
7
|
-
serverURL: string;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 错误信息所使用的语言
|
|
11
|
-
*
|
|
12
|
-
* Language used in error text
|
|
13
|
-
*/
|
|
14
|
-
lang: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface ErrorStatusResponse {
|
|
18
|
-
/**
|
|
19
|
-
* 错误代码
|
|
20
|
-
*
|
|
21
|
-
* Error number
|
|
22
|
-
*/
|
|
23
|
-
errno: number;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 错误消息
|
|
27
|
-
*
|
|
28
|
-
* Error msg
|
|
29
|
-
*/
|
|
30
|
-
errmsg: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const JSON_HEADERS: Record<string, string> = {
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
35
|
-
'Content-Type': 'application/json',
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const errorCheck = <T extends ErrorStatusResponse>(
|
|
39
|
-
data: T,
|
|
40
|
-
name = '',
|
|
41
|
-
): T => {
|
|
42
|
-
if (typeof data === 'object' && data.errno)
|
|
43
|
-
throw new TypeError(`${name} failed with ${data.errno}: ${data.errmsg}`);
|
|
44
|
-
|
|
45
|
-
return data;
|
|
46
|
-
};
|