From 1e6d3633d3d5c8e0f3a5c240f6717446b47ff273 Mon Sep 17 00:00:00 2001 From: cfdxkk Date: Sat, 23 Dec 2023 14:32:08 +0800 Subject: [PATCH 1/8] =?UTF-8?q?:sparkles:=20=E5=A2=9E=E5=8A=A0=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E8=AF=84=E8=AE=BA=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/Comment/VideoCommentController.ts | 49 +++++ .../Comment/VideoCommentControllerDto.d.ts | 185 ++++++++++++++++++ composables/api/Danmaku/DanmakuController.ts | 2 +- .../api/Danmaku/DanmakuControllerDto.d.ts | 3 + 4 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 composables/api/Comment/VideoCommentController.ts create mode 100644 composables/api/Comment/VideoCommentControllerDto.d.ts diff --git a/composables/api/Comment/VideoCommentController.ts b/composables/api/Comment/VideoCommentController.ts new file mode 100644 index 00000000..f8de0055 --- /dev/null +++ b/composables/api/Comment/VideoCommentController.ts @@ -0,0 +1,49 @@ +import { post } from "../Common"; +import getCorrectUri from "../Common/getCorrectUri"; +import type { EmitVideoCommentDownvoteRequestDto, EmitVideoCommentDownvoteResponseDto, EmitVideoCommentRequestDto, EmitVideoCommentResponseDto, EmitVideoCommentUpvoteRequestDto, EmitVideoCommentUpvoteResponseDto, GetVideoCommentByKvidRequestDto, GetVideoCommentByKvidResponseDto } from "./VideoCommentControllerDto"; + +const BACK_END_URL = getCorrectUri(); +const USER_API_URI = `${BACK_END_URL}/video/comment`; + +/** + * 用户发送视频评论 + * @param emitVideoCommentRequest 用户发送的视频评论的请求载荷 + * @returns 用户发送视频评论的结果 + */ +export const emitVideoComment = async (emitVideoCommentRequest: EmitVideoCommentRequestDto): Promise => { + // TODO use { credentials: "include" } to allow save/read cookies from cross-origin domains. Maybe we should remove it before deployment to production env. + return await post(`${USER_API_URI}/emit`, emitVideoCommentRequest, { credentials: "include" }) as EmitVideoCommentResponseDto; +}; + +/** + * 根据 kvid 获取视频评论列表 + * @param getVideoCommentByKvidRequest 请求视频评论列表的查询参数 + * @returns 视频的视频评论列表 + */ +export const getVideoCommentByKvid = async (getVideoCommentByKvidRequest: GetVideoCommentByKvidRequestDto): Promise => { + const { data: result } = await useFetch(`${USER_API_URI}?videoId=${getVideoCommentByKvidRequest.videoId}`); + if (result.value) + return result.value; + else + return { success: false, message: "获取首页视频失败", videoCommentCount: 0, videoCommentList: [] }; +}; + +/** + * 用户为视频评论点赞 + * @param emitVideoCommentUpvoteRequest 用户为视频评论点赞的请求载荷 + * @returns 用户为视频评论点赞的结果 + */ +export const emitVideoCommentUpvote = async (emitVideoCommentUpvoteRequest: EmitVideoCommentUpvoteRequestDto): Promise => { + // TODO use { credentials: "include" } to allow save/read cookies from cross-origin domains. Maybe we should remove it before deployment to production env. + return await post(`${USER_API_URI}/upvote`, emitVideoCommentUpvoteRequest, { credentials: "include" }) as EmitVideoCommentUpvoteResponseDto; +}; + +/** + * 用户为视频评论点踩 + * @param emitVideoCommentDownvoteRequest 用户为视频评论点踩的请求载荷 + * @returns 用户为视频评论点踩的结果 + */ +export const emitVideoCommentDownvote = async (emitVideoCommentDownvoteRequest: EmitVideoCommentDownvoteRequestDto): Promise => { + // TODO use { credentials: "include" } to allow save/read cookies from cross-origin domains. Maybe we should remove it before deployment to production env. + return await post(`${USER_API_URI}/downvote`, emitVideoCommentDownvoteRequest, { credentials: "include" }) as EmitVideoCommentDownvoteResponseDto; +}; diff --git a/composables/api/Comment/VideoCommentControllerDto.d.ts b/composables/api/Comment/VideoCommentControllerDto.d.ts new file mode 100644 index 00000000..45edab04 --- /dev/null +++ b/composables/api/Comment/VideoCommentControllerDto.d.ts @@ -0,0 +1,185 @@ +/** + * 基础视频评论数据 + */ +type BasicVideoCommentDto = { + /** KVID 视频 ID */ + videoId: number; + /** 评论正文 */ + text: string; +}; + +/** + * 发送视频评论的请求数据 + */ +export type EmitVideoCommentRequestDto = BasicVideoCommentDto; + +/** + * 发送视频评论的响应的数据 + */ +export type EmitVideoCommentResponseDto = { + /** 是否请求成功 */ + success: boolean; + /** 附加的文本消息 */ + message?: string; + /** 发送成功的话,返回发送时的评论的数据 */ + videoComment?: EmitVideoCommentRequestDto; +}; + +/** + * 获取某个用户在对某个视频的评论的点赞情况的参数 + */ +export type GetVideoCommentUpvotePropsDto = { + /** KVID 视频 ID */ + videoId: number; + /** 视频评论点赞者的用户的 UID */ + uid: number; +}; + +/** + * 获取某个用户在对某个视频的评论的点赞情况的结果 + */ +export type GetVideoCommentUpvoteResultDto = { + /** 是否请求成功 */ + success: boolean; + /** 附加的文本消息 */ + message?: string; + /** 某个用户在对某个视频的评论的点赞情况 */ + videoCommentUpvoteResult: { + /** KVID 视频 ID */ + videoId: number; + /** 评论的ID */ + commentId: string; + /** 评论点赞者的用户的 UID */ + uid: number; + /** 系统专用字段-最后编辑时间 */ + editDateTime: number; + }[]; +}; + +/** + * 获取某个用户在对某个视频的评论的点踩情况的参数 + */ +export type GetVideoCommentDownvotePropsDto = { + /** KVID 视频 ID */ + videoId: number; + /** 视频评论点踩者的用户的 UID */ + uid: number; +}; + +/** + * 获取某个用户在对某个视频的评论的点踩情况的结果 + */ +export type GetVideoCommentDownvoteResultDto = { + /** 是否请求成功 */ + success: boolean; + /** 附加的文本消息 */ + message?: string; + /** 某个用户在对某个视频的评论的点踩情况 */ + videoCommentDownvoteResult: { + /** KVID 视频 ID */ + videoId: number; + /** 评论的ID */ + commentId: string; + /** 评论点踩者的用户的 UID */ + uid: number; + /** 系统专用字段-最后编辑时间 */ + editDateTime: number; + }[]; +}; + +/** + * 根据 KVID 获取视频评论的请求的参数 + */ +export type GetVideoCommentByKvidRequestDto = { + /** KVID 视频 ID */ + videoId: number; +}; + +type VideoCommentIdDto = { + /** 评论的路由 */ /** 如:1.2.3(视频的第一个评论的第二个回复的第三个回复) */ + commentRoute: string; + /** 评论 ID */ + upvoteCount: string; + /** 评论楼层数 */ + commentIndex: number; +}; + +export type GetVideoCommentByKvidResponseDto = { + /** 是否请求成功 */ + success: boolean; + /** 附加的文本消息 */ + message?: string; + /** 视频评论总数量 */ + videoCommentCount: number; + /** 视频评论 */ + videoCommentList: { + /** MongoDB 生成的唯一 ID */ + _id: string; + /** 评论的路由 */ /** 如:1.2.3(视频的第一个评论的第二个回复的第三个回复) */ + commentRoute: string; + /** KVID 视频 ID */ + videoId: number; + /** 评论发送者的用户的 UID */ + uid: number; + /** 发送评论的时间 */ + emitTime: number; + /** 评论正文 */ + text: string; + /** 是否已点赞 */ + isUpvote: boolean; + /** 是否已点踩 */ + isDownvote: boolean; + /** 评论点赞数 */ + upvoteCount: number; + /** 评论点踩数 */ + downvoteCount: number; + /** 评论楼层数 */ + commentIndex: number; + /** 子评论 */ + subComments: VideoCommentIdDto[]; + /** 该评论的下一级子评论数量 */ + subCommentsCount: number; + /** 系统专用字段-最后编辑时间 */ + editDateTime: number; + }[]; +}; + +/** + * 为视频点赞的请求的请求参数 + */ +export type EmitVideoCommentUpvoteRequestDto = { + /** 评论的唯一 ID */ + id: string; + /** KVID 视频 ID */ + videoId: number; +}; + +/** +* 为视频点赞的请求的响应结果 +*/ +export type EmitVideoCommentUpvoteResponseDto = { + /** 是否请求成功 */ + success: boolean; + /** 附加的文本消息 */ + message?: string; +}; + +/** + * 为视频点踩的请求的请求参数 + */ +export type EmitVideoCommentDownvoteRequestDto = { + /** 评论的唯一 ID */ + id: string; + /** KVID 视频 ID */ + videoId: number; +}; + +/** +* 为视频点踩的请求的响应结果 +*/ +export type EmitVideoCommentDownvoteResponseDto = { + /** 是否请求成功 */ + success: boolean; + /** 附加的文本消息 */ + message?: string; +}; diff --git a/composables/api/Danmaku/DanmakuController.ts b/composables/api/Danmaku/DanmakuController.ts index d916dcc3..6ef5b0ba 100644 --- a/composables/api/Danmaku/DanmakuController.ts +++ b/composables/api/Danmaku/DanmakuController.ts @@ -21,5 +21,5 @@ export const emitDanmaku = async (emitDanmakuRequest: EmitDanmakuRequestDto): Pr * @returns 视频的弹幕列表 */ export const getDanmakuByKvid = async (getDanmakuByKvidRequest: GetDanmakuByKvidRequestDto): Promise => { - return await get(`${USER_API_URI}/?videoId=${getDanmakuByKvidRequest.videoId}`) as GetDanmakuByKvidResponseDto; + return await get(`${USER_API_URI}?videoId=${getDanmakuByKvidRequest.videoId}`) as GetDanmakuByKvidResponseDto; }; diff --git a/composables/api/Danmaku/DanmakuControllerDto.d.ts b/composables/api/Danmaku/DanmakuControllerDto.d.ts index bff38ec3..1ddf972a 100644 --- a/composables/api/Danmaku/DanmakuControllerDto.d.ts +++ b/composables/api/Danmaku/DanmakuControllerDto.d.ts @@ -1,3 +1,6 @@ +/** + * 基础弹幕数据 + */ type BasicDanmakuDto = { /** 非空 - KVID 视频 ID */ videoId: number; From 284cb6e5f192a656b4b35f01b40621dbe8f869ca Mon Sep 17 00:00:00 2001 From: cfdxkk Date: Sun, 24 Dec 2023 17:03:37 +0800 Subject: [PATCH 2/8] =?UTF-8?q?:sparkles:=20=E8=A7=86=E9=A2=91=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=EF=BC=8C=E8=A7=86=E9=A2=91=E8=AF=84=E8=AE=BA=E7=82=B9?= =?UTF-8?q?=E8=B5=9E/=E8=B8=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CreationComments/CreationComments.vue | 32 ++++++++++--------- .../CreationComments/CreationCommentsItem.vue | 30 +++++++++++++---- composables/api.ts | 3 +- .../api/Comment/VideoCommentController.ts | 9 ++---- .../Comment/VideoCommentControllerDto.d.ts | 21 ++++++++++++ pages/video/kv[kvid].vue | 11 +++++-- types/backend.d.ts | 2 ++ 7 files changed, 77 insertions(+), 31 deletions(-) diff --git a/components/Creation/CreationComments/CreationComments.vue b/components/Creation/CreationComments/CreationComments.vue index 90db64c9..4cd59f33 100755 --- a/components/Creation/CreationComments/CreationComments.vue +++ b/components/Creation/CreationComments/CreationComments.vue @@ -5,17 +5,17 @@