33import com .semosan .api .common .config .MinioProperties ;
44import com .semosan .api .common .exception .GeneralException ;
55import com .semosan .api .common .status .ErrorStatus ;
6+ import com .semosan .api .domain .image .constant .ImageConstants ;
67import com .semosan .api .domain .image .dto .response .PresignedUrlResponse ;
78import io .minio .GetPresignedObjectUrlArgs ;
89import io .minio .MinioClient ;
1112import org .springframework .stereotype .Service ;
1213
1314import java .util .Map ;
14- import java .util .Set ;
1515import java .util .UUID ;
1616import java .util .concurrent .TimeUnit ;
1717
1818@ Service
1919@ RequiredArgsConstructor
2020public class ImageService {
2121
22- public static final Set <String > ALLOWED_BUCKETS = Set .of ("reviews" , "mountains" , "restaurants" , "posts" , "semofeed" );
23- private static final Set <String > ALLOWED_EXTENSIONS = Set .of (".jpg" , ".jpeg" , ".png" , ".webp" );
24- private static final Map <String , String > CONTENT_TYPE_MAP = Map .of (
25- ".jpg" , "image/jpeg" ,
26- ".jpeg" , "image/jpeg" ,
27- ".png" , "image/png" ,
28- ".webp" , "image/webp"
29- );
30-
3122 private final MinioClient minioClient ;
3223 private final MinioProperties minioProperties ;
3324
@@ -39,7 +30,7 @@ public PresignedUrlResponse generatePresignedUrl(String bucket, String filename)
3930 String key = UUID .randomUUID () + extension ;
4031
4132 try {
42- String contentType = CONTENT_TYPE_MAP .get (extension .toLowerCase ());
33+ String contentType = ImageConstants . CONTENT_TYPE_MAP .get (extension .toLowerCase ());
4334 String uploadUrl = minioClient .getPresignedObjectUrl (
4435 GetPresignedObjectUrlArgs .builder ()
4536 .method (Method .PUT )
@@ -60,13 +51,13 @@ public PresignedUrlResponse generatePresignedUrl(String bucket, String filename)
6051 }
6152
6253 private void validateBucket (String bucket ) {
63- if (bucket == null || !ALLOWED_BUCKETS .contains (bucket )) {
54+ if (bucket == null || !ImageConstants . ALLOWED_BUCKETS .contains (bucket )) {
6455 throw new GeneralException (ErrorStatus .INVALID_IMAGE_BUCKET );
6556 }
6657 }
6758
6859 private void validateExtension (String extension ) {
69- if (extension .isEmpty () || !ALLOWED_EXTENSIONS .contains (extension .toLowerCase ())) {
60+ if (extension .isEmpty () || !ImageConstants . ALLOWED_EXTENSIONS .contains (extension .toLowerCase ())) {
7061 throw new GeneralException (ErrorStatus .INVALID_IMAGE_EXTENSION );
7162 }
7263 }
0 commit comments