88
99import java .net .URL ;
1010import java .time .LocalDateTime ;
11+ import java .util .Set ;
1112import java .util .UUID ;
1213
1314@ Service
1415@ RequiredArgsConstructor
1516public class FileManager {
1617 private final VideoService videoService ;
1718 private final S3Service s3Service ;
19+ private final Set <String > validResolutions = Set .of ("480p" , "720p" , "1080p" );
1820
1921 public PresignedUrlResponse getUploadUrl (String filename ) {
2022 String contentType = validateAndGetContentType (filename );
@@ -53,8 +55,11 @@ private String validateAndGetContentType(String filename) {
5355 }
5456 }
5557
56- public PresignedUrlResponse getDownloadUrl (String objectKey ) {
58+ public PresignedUrlResponse getDownloadUrl (String uuid , String resolution ) {
5759 Integer expires = 60 ;
60+ validateResolution (resolution );
61+ videoService .isExistByUuid (uuid );
62+ String objectKey = "transcoded/videos/" + uuid + "/" + resolution + "/manifest.mpd" ;
5863 URL url = s3Service .generateDownloadUrl (objectKey , expires );
5964 LocalDateTime expiresAt = LocalDateTime .now ().plusMinutes (expires );
6065 return new PresignedUrlResponse (url , expiresAt );
@@ -68,4 +73,10 @@ public void updateVideoStatus(String videoId, String status) {
6873 videoService .createVideo (videoId , status , "/" , 0 );
6974 }
7075 }
76+
77+ public void validateResolution (String resolution ) {
78+ if (!validResolutions .contains (resolution )) {
79+ throw new ServiceException ("400" , "지원하지 않는 해상도입니다: " + resolution );
80+ }
81+ }
7182}
0 commit comments