Skip to content

Commit 84249d1

Browse files
committed
refactor: types
1 parent 382b831 commit 84249d1

4 files changed

Lines changed: 327 additions & 355 deletions

File tree

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useRef, useState } from 'react'
22
import Highlighter from 'react-highlight-words'
33
import { fetchComments } from './api'
4-
import { Reply } from './reply'
4+
import { Reply } from './types/reply'
55
import { extractVideoId, formatDateTime } from './utils'
66

77
import './App.css'

src/api.ts

Lines changed: 2 additions & 324 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Reply } from './reply'
1+
import { CommentDetailsResponse, CommentSort, CommentType } from './types/api'
2+
import { Reply } from './types/reply'
23

34
const replies: Reply[] = []
45

@@ -44,326 +45,3 @@ export async function fetchComments(videoId: string) {
4445

4546
return replies
4647
}
47-
48-
interface Page {
49-
/**
50-
* 当前页码
51-
*/
52-
num: number
53-
/**
54-
* 每页项数
55-
*/
56-
size: number
57-
/**
58-
* 根评论条数
59-
*/
60-
count: number
61-
/**
62-
* 总计评论条数
63-
*/
64-
acount: number
65-
}
66-
67-
interface Config {
68-
/**
69-
* 是否显示管理置顶
70-
*/
71-
showadmin: number
72-
/**
73-
* (?)
74-
*/
75-
showentry: number
76-
/**
77-
* 是否显示楼层号
78-
*/
79-
showfloor: number
80-
/**
81-
* 是否显示话题
82-
*/
83-
showtopic: number
84-
/**
85-
* 是否显示“UP 觉得很赞”标志
86-
*/
87-
show_up_flag: boolean
88-
/**
89-
* 是否只读评论区
90-
*/
91-
read_only: boolean
92-
/**
93-
* 是否显示删除记录
94-
*/
95-
show_del_log: boolean
96-
}
97-
98-
interface Hot {
99-
// Define properties for each hot comment item
100-
}
101-
102-
interface Top {
103-
// Define properties for the top comment item
104-
}
105-
106-
interface Notice {
107-
/**
108-
* 公告正文
109-
*/
110-
content: string
111-
/**
112-
* 公告 id
113-
*/
114-
id: number
115-
/**
116-
* 公告页面链接 url
117-
*/
118-
link: string
119-
/**
120-
* 公告标题
121-
*/
122-
title: string
123-
}
124-
125-
interface Folder {
126-
/**
127-
* 评论区是否存在折叠评论
128-
*/
129-
has_folded: boolean
130-
/**
131-
* 是否折叠?
132-
*/
133-
is_folded: boolean
134-
/**
135-
* 相关规则页面 url
136-
*/
137-
rule: string
138-
}
139-
140-
interface Control {
141-
/**
142-
* 是否禁止新增评论
143-
* 用户涉及合约争议,锁定该用户所有稿件、动态的评论区,不允许新增评论,root_input_text和child_input_text值为“当前评论区不可新增评论”
144-
*/
145-
input_disable: boolean
146-
/**
147-
* 评论框文字
148-
*/
149-
root_input_text: string
150-
/**
151-
* 评论框文字
152-
*/
153-
child_input_text: string
154-
/**
155-
* 空评论区文字
156-
*/
157-
bg_text: string
158-
/**
159-
* 评论是否筛选后可见
160-
* false:无需筛选
161-
* true:需要筛选
162-
*/
163-
web_selection: boolean
164-
/**
165-
* 答题页面链接文字
166-
*/
167-
answer_guide_text: string
168-
/**
169-
* 答题页面图标 url
170-
*/
171-
answer_guide_icon_url: string
172-
/**
173-
* 答题页面 ios url
174-
*/
175-
answer_guide_ios_url: string
176-
/**
177-
* 答题页面安卓 url
178-
*/
179-
answer_guide_android_url: string
180-
}
181-
182-
interface CommentSection {
183-
/**
184-
* 页信息
185-
*/
186-
page: Page
187-
/**
188-
* 评论区显示控制
189-
*/
190-
config: Config
191-
/**
192-
* 评论列表
193-
*/
194-
replies: Reply[] | null
195-
/**
196-
* 热评列表
197-
*/
198-
hots: Hot[] | null
199-
/**
200-
* 置顶评论
201-
*/
202-
upper: {
203-
/**
204-
* UP 主 mid
205-
*/
206-
mid: number
207-
/**
208-
* 置顶条目
209-
*/
210-
top: Top | null
211-
}
212-
/**
213-
* (?)
214-
*/
215-
top: null
216-
/**
217-
* 评论区公告信息
218-
*/
219-
notice: Notice | null
220-
/**
221-
* 投票评论?
222-
*/
223-
vote: number | null
224-
/**
225-
* (?)
226-
*/
227-
blacklist: number
228-
/**
229-
* (?)
230-
*/
231-
assist: number
232-
/**
233-
* 评论区类型id
234-
*/
235-
mode: number
236-
/**
237-
* 评论区支持的类型id
238-
*/
239-
support_mode: number[]
240-
/**
241-
* 折叠相关信息
242-
*/
243-
folder: Folder
244-
/**
245-
* (?)
246-
*/
247-
lottery_card: null
248-
/**
249-
* 显示bvid?
250-
*/
251-
show_bvid: boolean
252-
/**
253-
* 评论区输入属性
254-
*/
255-
control: Control
256-
}
257-
258-
interface CommentDetailsResponse {
259-
/**
260-
* 返回值
261-
* 0:成功
262-
* -400:请求错误
263-
* -404:无此项
264-
* 12002:评论区已关闭
265-
* 12009:评论主体的type不合法
266-
*/
267-
code: number
268-
/**
269-
* 错误信息
270-
* 默认为0
271-
*/
272-
message: string
273-
/**
274-
* 1
275-
*/
276-
ttl: number
277-
/**
278-
* 数据本体
279-
* 正确时:obj
280-
* 错误时:null
281-
*/
282-
data: CommentSection | null
283-
}
284-
285-
/**
286-
* Enum representing the different types of comments.
287-
*/
288-
enum CommentType {
289-
VIDEO = 1, // Video稿件
290-
TOPIC = 2, // 话题
291-
ACTIVITY = 4, // 活动
292-
SHORT_VIDEO = 5, // 小视频
293-
BAN_INFO = 6, // 小黑屋封禁信息
294-
NOTICE = 7, // 公告信息
295-
LIVE_ACTIVITY = 8, // 直播活动
296-
ACTIVITY_ARTICLE = 9, // 活动稿件
297-
LIVE_NOTICE = 10, // 直播公告
298-
ALBUM = 11, // 相簿(图片动态)
299-
COLUMN = 12, // 专栏
300-
TICKET = 13, // 票务
301-
AUDIO = 14, // 音频
302-
JURY = 15, // 风纪委员会
303-
REVIEW = 16, // 点评
304-
DYNAMIC = 17, // 动态(纯文字动态&分享)
305-
PLAYLIST = 18, // 播单
306-
MUSIC_PLAYLIST = 19, // 音乐播单
307-
COMIC_1 = 20, // 漫画
308-
COMIC_2 = 21, // 漫画
309-
COMIC_3 = 22, // 漫画
310-
COURSE = 33, // 课程
311-
}
312-
313-
enum CommentSort {
314-
/**
315-
* 按时间
316-
*/
317-
TIME = 0,
318-
/**
319-
* 按点赞数
320-
*/
321-
LIKES = 1,
322-
/**
323-
* 按回复数
324-
*/
325-
REPLIES = 2,
326-
}
327-
328-
interface CommentRequestParams {
329-
/**
330-
* APP 登录 Token
331-
* APP 方式必要
332-
*/
333-
access_key?: string
334-
/**
335-
* 评论区类型代码
336-
* 类型代码见表
337-
*/
338-
type: CommentType
339-
/**
340-
* 目标评论区 id
341-
*/
342-
oid: number
343-
/**
344-
* 排序方式
345-
* 默认为0
346-
* 0:按时间
347-
* 1:按点赞数
348-
* 2:按回复数
349-
*/
350-
sort?: CommentSort
351-
/**
352-
* 是否不显示热评
353-
* 默认为0
354-
* 1:不显示
355-
* 0:显示
356-
*/
357-
nohot?: number
358-
/**
359-
* 每页项数
360-
* 默认为20
361-
* 定义域:1-49
362-
*/
363-
ps?: number
364-
/**
365-
* 页码
366-
* 默认为1
367-
*/
368-
pn?: number
369-
}

0 commit comments

Comments
 (0)