Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

업로드 한 비디오 API 응답 데이터 수정 #212

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions server/src/user/dto/uploaded-video-response.dto.ts

This file was deleted.

2 changes: 1 addition & 1 deletion server/src/user/dto/user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class UserDto {
* 프로필 이미지 확장자
* @example 'webp'
*/
profileImageExtension?: string;
profileImageExtension?: string | null = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

대박 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

대박티비 📺


/**
* 유저 닉네임
Expand Down
6 changes: 3 additions & 3 deletions server/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import { TokenExpiredException } from 'src/exceptions/token-expired.exception';
import { ApiSuccessResponse } from 'src/decorators/api-succes-response';
import { UserNotFoundException } from 'src/exceptions/user-not-found.exception';
import { ProfileUploadRequiredException } from 'src/exceptions/profile-upload-required-exception';
import { VideoListResponseDto } from 'src/video/dto/video-list-response.dto';
import { UserService } from './user.service';
import { ProfileDto } from './dto/profile.dto';
import { UploadedVideoResponseDto } from './dto/uploaded-video-response.dto';
import { UserUploadedVideoQueryDto } from './dto/uploaded-video-request.dto';
import { UserRatedVideoQueryDto } from './dto/rated-video-request.dto';
import { RatedVideoResponseDto } from './dto/rated-video-response.dto';
Expand Down Expand Up @@ -56,12 +56,12 @@ export class UserController {
* 특정 유저가 업로드 한 비디오 정보 반환
*/
@Get(':userId/videos/uploaded')
@ApiSuccessResponse(200, '비디오 반환 성공', UploadedVideoResponseDto)
@ApiSuccessResponse(200, '비디오 반환 성공', VideoListResponseDto)
@ApiFailResponse('조회 실패', [UserNotFoundException])
getUploadedVideos(
@Param('userId') userId: string,
@Query() query: UserUploadedVideoQueryDto,
): Promise<UploadedVideoResponseDto> {
) {
return this.userService.getUploadedVideos(
userId,
query.limit,
Expand Down
25 changes: 11 additions & 14 deletions server/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import { Video } from 'src/video/schemas/video.schema';
import { UserNotFoundException } from 'src/exceptions/user-not-found.exception';
import * as _ from 'lodash';
import { deleteObject } from 'src/ncpAPI/deleteObject';
import { getBucketImage } from 'src/ncpAPI/getBucketImage';
import { VideoService } from 'src/video/video.service';
import { createPresignedUrl } from 'src/ncpAPI/presignedURL';
import { ProfileUploadRequiredException } from 'src/exceptions/profile-upload-required-exception';
import { checkUpload } from 'src/ncpAPI/listObjects';
import { UploadedVideoResponseDto } from './dto/uploaded-video-response.dto';
import { User } from './schemas/user.schema';
import { ProfileDto } from './dto/profile.dto';
import { RatedVideoResponseDto } from './dto/rated-video-response.dto';
Expand Down Expand Up @@ -93,11 +91,7 @@ export class UserService {
};
}

async getUploadedVideos(
uuid: string,
limit: number,
lastId: string,
): Promise<UploadedVideoResponseDto> {
async getUploadedVideos(uuid: string, limit: number, lastId: string) {
const uploaderData = await this.UserModel.findOne({ uuid }, { actions: 0 });
const { uploader, uploaderId } = await this.getUploaderInfo(
uuid,
Expand All @@ -118,8 +112,8 @@ export class UserService {
.sort({ _id: -1 })
.limit(limit);

const videos = await this.getVideoInfos(videoData);
return { videos, uploader };
const videos = await this.getVideoInfos(videoData, uploader);
return { videos };
}

async getUploaderInfo(uuid: string, uploaderData) {
Expand All @@ -142,7 +136,7 @@ export class UserService {
return { uploader, uploaderId };
}

async getVideoInfos(videoData: Array<any>) {
async getVideoInfos(videoData: Array<any>, uploader: object) {
const videos = await Promise.all(
videoData.map(async (video) => {
const { thumbnailExtension, raterCount, totalRating, ...videoInfo } =
Expand All @@ -151,12 +145,15 @@ export class UserService {
? (totalRating / raterCount).toFixed(1)
: null;
const manifest = `${process.env.MANIFEST_URL_PREFIX}${videoInfo._id}_,${process.env.ENCODING_SUFFIXES}${process.env.ABR_MANIFEST_URL_SUFFIX}`;
const thumbnailImage = await getBucketImage(
const thumbnailImageUrl = await createPresignedUrl(
process.env.THUMBNAIL_BUCKET,
thumbnailExtension,
videoInfo._id,
`${videoInfo._id}.${thumbnailExtension}`,
'GET',
);
return { ...videoInfo, manifest, rating, thumbnailImage };
return {
video: { ...videoInfo, manifest, rating, thumbnailImageUrl },
uploader,
};
}),
);
return videos;
Expand Down