Skip to content

Commit

Permalink
✨ ①视频分区、视频 TAG、查看封面和视频上传者信息功能 ② 其他 QoL 改进
Browse files Browse the repository at this point in the history
  • Loading branch information
cfdxkk committed Dec 17, 2023
1 parent dc8acdc commit fa142e8
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/controller/VideoController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export const updateVideoController = async (ctx: koaCtx, next: koaNext) => {
uploaderId: data.uploaderId,
duration: data.duration,
description: data.description,
videoCategory: data.videoCategory,
copyright: data.copyright,
videoTags: data.videoTags,
}
const uploadVideoResponse = await updateVideoService(uploadVideoRequest)
ctx.body = uploadVideoResponse
Expand Down
49 changes: 46 additions & 3 deletions src/controller/VideoControllerDto.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@ type VideoPartDto = {
/** 视频直链 */
link: string;
}

/**
* 视频 TAG 的数据
*/
type VideoTagDto = {
/** 非空 - 视频的 TAG ID */
tagId: number;
/** 非空 - 视频 TAG 的名称 */
tag: string;
/** TAG 描述 */
description?: string;
}

/**
* 展示视频卡片返回的参数
* 上传视频的请求参数
*/
export type UploadVideoRequestDto = {
/** 每 P 视频的数据 */
Expand All @@ -27,6 +40,12 @@ export type UploadVideoRequestDto = {
duration: number;
/** 视频描述 */
description?: string;
/** 视频分区 */
videoCategory: string;
/** 视频版权 */
copyright: string;
/** 视频 TAG */
videoTags: VideoTagDto[];
}

/**
Expand Down Expand Up @@ -64,7 +83,7 @@ export type ThumbVideoResponseDto = {
/** 封面图链接 */
image?: string;
/** 视频上传的日期,时间戳格式 */
updateDate?: number;
uploadDate?: number;
/** 视频播放量 */
watchedCount?: number;
/** 视频作者 ID */
Expand All @@ -86,6 +105,22 @@ export type GetVideoByKvidRequestDto = {
videoId: number;
}

/**
* 上传视频的用户信息
*/
type UploaderInfoDto = {
/** 用户 ID */
uid: number;
/** 用户名 */
username?: string;
/** 用户头像的链接 */
avatar?: string;
/** 用户背景图片的链接 */
userBannerImage?: string;
/** 用户的个性签名 */
signature?: string;
}

/**
* 视频页面需要的响应
*/
Expand All @@ -105,17 +140,25 @@ export type GetVideoByKvidResponseDto = {
/** 封面图链接 */
image?: string;
/** 视频上传的日期,时间戳格式 */
updateDate?: number;
uploadDate?: number;
/** 视频播放量 */
watchedCount?: number;
/** 视频作者 ID */
uploader?: string;
/** 创作者 UID */
uploaderId?: number;
/** 视频作者信息 */
uploaderInfo?: UploaderInfoDto;
/** 视频时长,单位 ms */
duration?: number;
/** 视频描述 */
description?: string;
/** 视频分区 */
videoCategory: string;
/** 视频版权 */
copyright: string;
/** 视频 TAG */
videoTags: VideoTagDto[];
};
}

Expand Down
32 changes: 26 additions & 6 deletions src/dbPool/schema/VideoSchema.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
/**
* 分P 视频的数据
*/
const videoPartSchema = {
/** 非空 - 唯一 - 分P 视频的顺序 */
const VideoPartSchema = {
/** 非空 - 分P 视频的顺序 */
id: { type: Number, required: true },
/** 非空 - 唯一 - 每 P 视频的标题 */
/** 非空 - 每 P 视频的标题 */
videoPartTitle: { type: String, required: true },
/** 非空 - 唯一 - 每 P 视频的链接 */
/** 非空 - 每 P 视频的链接 */
link: { type: String, required: true },
/** 非空 - 系统专用字段-最后编辑时间 */
editDateTime: { type: Number, required: true },
}

/**
* 视频 TAG 的数据
*/
const VideoTagSchema = {
/** 非空 - 视频的 TAG ID */
tagId: { type: Number, required: true },
/** 非空 - 视频 TAG 的名称 */
tag: { type: String, required: true },
/** TAG 描述 */
description: String,
/** 非空 - 系统专用字段-最后编辑时间 */
editDateTime: { type: Number, required: true },
}

/**
* 视频数据
*/
Expand All @@ -23,11 +37,11 @@ const VideoSchema = {
/** 非空 - 视频标题 */
title: { type: String, required: true },
/** 非空 - 分 P 视频的数据 */
videoPart: { type: [videoPartSchema], required: true },
videoPart: { type: [VideoPartSchema], required: true },
/** 非空 - 封面图链接 */
image: { type: String, required: true },
/** 非空 - 视频上传的日期,时间戳格式 */
updateDate: { type: Number, required: true },
uploadDate: { type: Number, required: true },
/** 非空 - 视频播放量 */
watchedCount: { type: Number, required: true },
/** 非空 - 视频作者 ID */
Expand All @@ -38,6 +52,12 @@ const VideoSchema = {
duration: { type: Number, required: true },
/** 视频描述 */
description: String,
/** 非空 - 视频分区 */
videoCategory: { type: String, required: true },
/** 非空 - 视频版权 */
copyright: { type: String, required: true },
/** 非空 - 视频 TAG */
videoTags: { type: [VideoTagSchema], required: true },
/** 非空 - 系统专用字段-最后编辑时间 */
editDateTime: { type: Number, required: true },
},
Expand Down
26 changes: 21 additions & 5 deletions src/service/VideoService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { insertData2MongoDB, selectDataFromMongoDB } from '../dbPool/DbClusterPo
import { QueryType, SelectType } from '../dbPool/DbClusterPoolTypes.js'
import VideoSchema from '../dbPool/schema/VideoSchema.js'
import { getNextSequenceValueEjectService } from './SequenceValueService.js'
import { getUserInfoByUidService } from './UserService.js'

/**
* 上传视频
Expand All @@ -22,17 +23,21 @@ export const updateVideoService = async (uploadVideoRequest: UploadVideoRequestD
type Video = InferSchemaType<typeof schema>
const nowDate = new Date().getTime()
const videoPart = uploadVideoRequest.videoPart.map(video => ({ ...video, editDateTime: nowDate }))
const videoTags = uploadVideoRequest.videoTags.map(tag => ({ ...tag, editDateTime: nowDate }))
const video: Video = {
videoId,
videoPart,
title: uploadVideoRequest.title,
image: uploadVideoRequest.image,
updateDate: new Date().getTime(),
uploadDate: new Date().getTime(),
watchedCount: 0,
uploader: uploadVideoRequest.uploader,
uploaderId: uploadVideoRequest.uploaderId,
duration: uploadVideoRequest.duration,
description: uploadVideoRequest.description,
videoCategory: uploadVideoRequest.videoCategory,
copyright: uploadVideoRequest.copyright,
videoTags,
editDateTime: nowDate,
}
try {
Expand Down Expand Up @@ -71,7 +76,7 @@ export const getThumbVideoService = async (): Promise<ThumbVideoResponseDto> =>
videoId: 1,
title: 1,
image: 1,
updateDate: 1,
uploadDate: 1,
watchedCount: 1,
uploader: 1,
uploaderId: 1,
Expand Down Expand Up @@ -128,22 +133,33 @@ export const getVideoByKvidService = async (getVideoByKvidRequest: GetVideoByKvi
videoPart: 1,
title: 1,
image: 1,
updateDate: 1,
uploadDate: 1,
watchedCount: 1,
uploader: 1,
uploaderId: 1,
duration: 1,
description: 1,
editDateTime: 1,
videoCategory: 1,
copyright: 1,
videoTags: 1,
}
try {
const result = await selectDataFromMongoDB(where, select, schema, collectionName)
const videoResult = result.result
if (result.success && videoResult) {
const videosCount = result.result?.length
if (videosCount === 1) {
const video = videoResult?.[0]
const video = videoResult?.[0] as GetVideoByKvidResponseDto['video']
if (video) {
const getVideoByUidRequest: GetVideoByUidRequestDto = {
uid: video.uploaderId,
}
const userInfoResult = await getUserInfoByUidService(getVideoByUidRequest) // 通过视频的上传者 ID 获取上传者信息
const userInfo = userInfoResult.result
if (userInfoResult.success) { // 如果获取到的话,就将视频上传者信息附加到请求响应中
video.uploaderInfo = { uid: video.uploaderId, username: userInfo.username, avatar: userInfo.avatar, userBannerImage: userInfo.userBannerImage, signature: userInfo.signature }
}
return {
success: true,
message: '获取首页视频成功',
Expand Down Expand Up @@ -194,7 +210,7 @@ export const getVideoByUidRequestService = async (getVideoByUidRequest: GetVideo
videoPart: 1,
title: 1,
image: 1,
updateDate: 1,
uploadDate: 1,
watchedCount: 1,
uploader: 1,
uploaderId: 1,
Expand Down

0 comments on commit fa142e8

Please sign in to comment.