| 1 | /** |
| 2 | * 平台交互统一类型定义 |
| 3 | */ |
| 4 | |
| 5 | import type { PLUGIN_SUPPORTED_PLATFORMS } from '../types/baseTypes' |
| 6 | import type { PlatType } from '@/app/config/platConfig' |
| 7 | |
| 8 | // ============================================================================ |
| 9 | // 通用参数类型 |
| 10 | // ============================================================================ |
| 11 | |
| 12 | /** |
| 13 | * 评论参数 |
| 14 | */ |
| 15 | export interface CommentParams { |
| 16 | /** 作品ID */ |
| 17 | workId: string |
| 18 | /** 评论内容 */ |
| 19 | content: string |
| 20 | /** 回复的评论ID(可选,二级评论时使用) */ |
| 21 | replyToCommentId?: string |
| 22 | } |
| 23 | |
| 24 | // ============================================================================ |
| 25 | // 通用结果类型 |
| 26 | // ============================================================================ |
| 27 | |
| 28 | /** |
| 29 | * 基础结果 |
| 30 | */ |
| 31 | export interface BaseResult { |
| 32 | /** 是否成功 */ |
| 33 | success: boolean |
| 34 | /** 错误/提示信息 */ |
| 35 | message?: string |
| 36 | /** 截图 base64 data URI (png) */ |
| 37 | screenshot?: string |
| 38 | /** 是否需要人工处理(如短信验证码) */ |
| 39 | needHumanAssist?: boolean |
| 40 | /** 需要人工处理的原因 */ |
| 41 | verificationReason?: string |
| 42 | /** 原始响应数据 */ |
| 43 | rawData?: any |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * 点赞结果 |
| 48 | */ |
| 49 | export interface LikeResult extends BaseResult {} |
| 50 | |
| 51 | /** |
| 52 | * 评论结果 |
| 53 | */ |
| 54 | export interface CommentResult extends BaseResult { |
| 55 | /** 评论ID */ |
| 56 | commentId?: string |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * 收藏结果 |
| 61 | */ |
| 62 | export interface FavoriteResult extends BaseResult {} |
| 63 | |
| 64 | /** |
| 65 | * 私信参数 |
| 66 | */ |
| 67 | export interface DirectMessageParams { |
| 68 | /** 作品ID(二选一) */ |
| 69 | workId?: string |
| 70 | /** 作者链接(二选一) */ |
| 71 | authorUrl?: string |
| 72 | /** 私信内容 */ |
| 73 | content: string |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * 私信结果 |
| 78 | */ |
| 79 | export interface DirectMessageResult extends BaseResult {} |
| 80 | |
| 81 | // ============================================================================ |
| 82 | // 首页列表类型 |
| 83 | // ============================================================================ |
| 84 | |
| 85 | /** |
| 86 | * 话题信息 |
| 87 | */ |
| 88 | export interface TopicInfo { |
| 89 | /** 话题名称 */ |
| 90 | name: string |
| 91 | /** 话题跳转链接 */ |
| 92 | url: string |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * 首页作品列表项 |
| 97 | * 注:list不包含收藏数和话题,这些在详情中获取 |
| 98 | */ |
| 99 | export interface HomeFeedItem { |
| 100 | /** 作品ID */ |
| 101 | workId: string |
| 102 | /** 缩略图URL */ |
| 103 | thumbnail: string |
| 104 | /** 缩略图宽度 */ |
| 105 | thumbnailWidth?: number |
| 106 | /** 缩略图高度 */ |
| 107 | thumbnailHeight?: number |
| 108 | /** 作品标题 */ |
| 109 | title: string |
| 110 | /** 作者头像 */ |
| 111 | authorAvatar: string |
| 112 | /** 作者名称 */ |
| 113 | authorName: string |
| 114 | /** 作者ID */ |
| 115 | authorId: string |
| 116 | /** 作者主页链接 */ |
| 117 | authorUrl: string |
| 118 | /** 点赞数(字符串,可能含"万") */ |
| 119 | likeCount: string |
| 120 | /** 是否已关注作者 */ |
| 121 | isFollowed: boolean |
| 122 | /** 是否已点赞 */ |
| 123 | isLiked: boolean |
| 124 | /** 是否为视频 */ |
| 125 | isVideo: boolean |
| 126 | /** 视频时长(秒),非视频为 undefined */ |
| 127 | videoDuration?: number |
| 128 | /** 平台原始数据 */ |
| 129 | origin: any |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * 作品详情 |
| 134 | */ |
| 135 | export interface WorkDetail { |
| 136 | /** 作品ID */ |
| 137 | workId: string |
| 138 | /** 作品类型:视频/图文 */ |
| 139 | type: 'video' | 'normal' |
| 140 | /** 作品标题 */ |
| 141 | title: string |
| 142 | /** 作品描述/正文 */ |
| 143 | description: string |
| 144 | /** 封面图URL */ |
| 145 | coverUrl: string |
| 146 | /** 图片列表(图文类型) */ |
| 147 | imageList: Array<{ |
| 148 | url: string |
| 149 | width?: number |
| 150 | height?: number |
| 151 | }> |
| 152 | /** 视频信息(视频类型) */ |
| 153 | video?: { |
| 154 | /** 视频URL */ |
| 155 | url: string |
| 156 | /** 时长(秒) */ |
| 157 | duration?: number |
| 158 | /** 宽度 */ |
| 159 | width?: number |
| 160 | /** 高度 */ |
| 161 | height?: number |
| 162 | } |
| 163 | /** 作者信息 */ |
| 164 | author: { |
| 165 | id: string |
| 166 | name: string |
| 167 | avatar: string |
| 168 | url: string |
| 169 | } |
| 170 | /** 互动数据 */ |
| 171 | interactInfo: { |
| 172 | /** 点赞数 */ |
| 173 | likeCount: string |
| 174 | /** 收藏数 */ |
| 175 | collectCount: string |
| 176 | /** 评论数 */ |
| 177 | commentCount: string |
| 178 | /** 分享数 */ |
| 179 | shareCount: string |
| 180 | /** 是否已点赞 */ |
| 181 | isLiked: boolean |
| 182 | /** 是否已收藏 */ |
| 183 | isCollected: boolean |
| 184 | /** 是否已关注作者 */ |
| 185 | isFollowed: boolean |
| 186 | } |
| 187 | /** 话题列表 */ |
| 188 | topics: TopicInfo[] |
| 189 | /** 发布时间(时间戳) */ |
| 190 | publishTime?: number |
| 191 | /** IP位置 */ |
| 192 | ipLocation?: string |
| 193 | /** 平台原始数据 */ |
| 194 | origin: any |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * 获取作品详情请求参数 |
| 199 | */ |
| 200 | export interface GetWorkDetailParams { |
| 201 | /** 作品ID */ |
| 202 | workId: string |
| 203 | /** 安全token(小红书需要) */ |
| 204 | xsecToken?: string |
| 205 | /** 来源(小红书需要) */ |
| 206 | xsecSource?: string |
| 207 | /** 列表项原始数据(抖音需要,直接从 HomeFeedItem.origin 获取详情) */ |
| 208 | origin?: any |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * 获取作品详情返回结果 |
| 213 | */ |
| 214 | export interface GetWorkDetailResult extends BaseResult { |
| 215 | /** 作品详情 */ |
| 216 | detail?: WorkDetail |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * 首页列表请求参数 |
| 221 | */ |
| 222 | export interface HomeFeedListParams { |
| 223 | /** 页码,从1开始 */ |
| 224 | page: number |
| 225 | /** 每页数量 */ |
| 226 | size: number |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * 首页列表返回结果 |
| 231 | */ |
| 232 | export interface HomeFeedListResult extends BaseResult { |
| 233 | /** 作品列表 */ |
| 234 | items: HomeFeedItem[] |
| 235 | /** 是否有更多数据 */ |
| 236 | hasMore: boolean |
| 237 | /** 总数(可选,部分平台不提供) */ |
| 238 | total?: number |
| 239 | } |
| 240 | |
| 241 | // ============================================================================ |
| 242 | // 平台接口定义 |
| 243 | // ============================================================================ |
| 244 | |
| 245 | /** |
| 246 | * 平台交互接口 |
| 247 | * 所有平台都需要实现此接口 |
| 248 | */ |
| 249 | export interface IPlatformInteraction { |
| 250 | /** 平台类型 */ |
| 251 | readonly platformType: PlatType |
| 252 | |
| 253 | /** |
| 254 | * 点赞/取消点赞作品 |
| 255 | * @param workId 作品ID |
| 256 | * @param isLike true 点赞,false 取消点赞 |
| 257 | */ |
| 258 | likeWork: (workId: string, isLike: boolean) => Promise<LikeResult> |
| 259 | |
| 260 | /** |
| 261 | * 评论作品 |
| 262 | * @param params 评论参数 |
| 263 | */ |
| 264 | commentWork: (params: CommentParams) => Promise<CommentResult> |
| 265 | |
| 266 | /** |
| 267 | * 收藏/取消收藏作品 |
| 268 | * @param workId 作品ID |
| 269 | * @param isFavorite true 收藏,false 取消收藏 |
| 270 | */ |
| 271 | favoriteWork: (workId: string, isFavorite: boolean) => Promise<FavoriteResult> |
| 272 | |
| 273 | /** |
| 274 | * 发送私信(可选方法,不是所有平台都支持) |
| 275 | * @param params 私信参数 |
| 276 | */ |
| 277 | sendDirectMessage?: (params: DirectMessageParams) => Promise<DirectMessageResult> |
| 278 | |
| 279 | /** |
| 280 | * 获取首页作品列表 |
| 281 | * @param params 分页参数 |
| 282 | */ |
| 283 | getHomeFeedList: (params: HomeFeedListParams) => Promise<HomeFeedListResult> |
| 284 | |
| 285 | /** |
| 286 | * 获取作品详情 |
| 287 | * @param params 作品详情请求参数 |
| 288 | */ |
| 289 | getWorkDetail: (params: GetWorkDetailParams) => Promise<GetWorkDetailResult> |
| 290 | |
| 291 | /** |
| 292 | * 获取评论列表 |
| 293 | * @param params 评论列表请求参数 |
| 294 | */ |
| 295 | getCommentList: (params: CommentListParams) => Promise<CommentListResult> |
| 296 | |
| 297 | /** |
| 298 | * 获取子评论列表(查看更多回复) |
| 299 | * @param params 子评论列表请求参数 |
| 300 | */ |
| 301 | getSubCommentList: (params: SubCommentListParams) => Promise<CommentListResult> |
| 302 | } |
| 303 | |
| 304 | // ============================================================================ |
| 305 | // 支持的平台类型 |
| 306 | // ============================================================================ |
| 307 | |
| 308 | /** |
| 309 | * 支持交互功能的平台类型 |
| 310 | */ |
| 311 | export type SupportedPlatformType = (typeof PLUGIN_SUPPORTED_PLATFORMS)[number] |
| 312 | |
| 313 | // ============================================================================ |
| 314 | // 评论列表相关类型 |
| 315 | // ============================================================================ |
| 316 | |
| 317 | /** |
| 318 | * 评论用户信息 |
| 319 | */ |
| 320 | export interface CommentUser { |
| 321 | /** 用户ID */ |
| 322 | id: string |
| 323 | /** 用户昵称 */ |
| 324 | nickname: string |
| 325 | /** 用户头像 */ |
| 326 | avatar: string |
| 327 | /** 安全token(小红书需要) */ |
| 328 | xsecToken?: string |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * 统一评论项 |
| 333 | */ |
| 334 | export interface CommentItem { |
| 335 | /** 评论ID */ |
| 336 | id: string |
| 337 | /** 评论内容 */ |
| 338 | content: string |
| 339 | /** 创建时间(毫秒级时间戳) */ |
| 340 | createTime: number |
| 341 | /** 点赞数 */ |
| 342 | likeCount: number |
| 343 | /** 用户信息 */ |
| 344 | user: CommentUser |
| 345 | /** IP属地 */ |
| 346 | ipLocation?: string |
| 347 | /** 是否为作者 */ |
| 348 | isAuthor: boolean |
| 349 | /** 是否已点赞 */ |
| 350 | isLiked: boolean |
| 351 | /** 子评论/回复数量 */ |
| 352 | replyCount: number |
| 353 | /** 子评论列表(首次加载时可能包含部分回复) */ |
| 354 | replies: CommentItem[] |
| 355 | /** 子评论分页游标 */ |
| 356 | replyCursor?: string |
| 357 | /** 是否有更多子评论 */ |
| 358 | hasMoreReplies: boolean |
| 359 | /** 回复目标(二级评论时存在) */ |
| 360 | replyTo?: { |
| 361 | /** 被回复的评论ID */ |
| 362 | id: string |
| 363 | /** 被回复的用户信息 */ |
| 364 | user: CommentUser |
| 365 | } |
| 366 | /** 原始数据 */ |
| 367 | origin: unknown |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * 评论列表请求参数 |
| 372 | */ |
| 373 | export interface CommentListParams { |
| 374 | /** 作品ID */ |
| 375 | workId: string |
| 376 | /** 分页游标(首次请求不传或传空) */ |
| 377 | cursor?: string |
| 378 | /** 每页数量 */ |
| 379 | count?: number |
| 380 | /** 安全token(小红书需要) */ |
| 381 | xsecToken?: string |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * 子评论列表请求参数 |
| 386 | */ |
| 387 | export interface SubCommentListParams extends CommentListParams { |
| 388 | /** 根评论ID */ |
| 389 | rootCommentId: string |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * 评论列表返回结果 |
| 394 | */ |
| 395 | export interface CommentListResult extends BaseResult { |
| 396 | /** 评论列表 */ |
| 397 | comments: CommentItem[] |
| 398 | /** 下一页游标 */ |
| 399 | cursor: string |
| 400 | /** 是否有更多数据 */ |
| 401 | hasMore: boolean |
| 402 | /** 评论总数(可选,部分平台不提供) */ |
| 403 | total?: number |
| 404 | } |
| 405 |