-
Notifications
You must be signed in to change notification settings - Fork 2
prod: fix 전반적인 오류 수정 #299
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
prod: fix 전반적인 오류 수정 #299
Changes from all commits
2c99aaa
d0157b1
05927d7
25ae7f0
c0576ab
5264184
5d270db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -31,13 +31,23 @@ | |||||
| @RequiredArgsConstructor | ||||||
| public class S3Service { | ||||||
|
|
||||||
| private static final int MAX_FILENAME_LENGTH = 150; | ||||||
| private static final int MAX_S3_KEY_LENGTH = 255; | ||||||
|
|
||||||
| private final S3Client s3Client; | ||||||
| private final S3Presigner s3Presigner; | ||||||
| private final S3Properties s3Properties; | ||||||
|
|
||||||
| public FileUploadResponse uploadFile(MultipartFile file, Folder folder) { | ||||||
| String sanitizedName = sanitizeFileName(file.getOriginalFilename()); | ||||||
| String s3Key = folder.getPath() + "/" + UUID.randomUUID() + "_" + sanitizedName; | ||||||
| String randomPrefix = UUID.randomUUID().toString(); | ||||||
| String s3Key = folder.getPath() + "/" + randomPrefix + "_" + sanitizedName; | ||||||
|
|
||||||
| if (s3Key.length() > MAX_S3_KEY_LENGTH) { | ||||||
| int excess = s3Key.length() - MAX_S3_KEY_LENGTH; | ||||||
| sanitizedName = sanitizedName.substring(0, sanitizedName.length() - excess); | ||||||
| s3Key = folder.getPath() + "/" + randomPrefix + "_" + sanitizedName; | ||||||
| } | ||||||
|
|
||||||
| try { | ||||||
| s3Client.putObject( | ||||||
|
|
@@ -108,12 +118,23 @@ public String getPreSignedUrl(String s3Key) { | |||||
| } | ||||||
|
|
||||||
| private String sanitizeFileName(String originalFilename) { | ||||||
| try { | ||||||
| return URLEncoder.encode(originalFilename, StandardCharsets.UTF_8) | ||||||
| .replaceAll("\\+", "%20"); | ||||||
| } catch (Exception e) { | ||||||
| throw new RuntimeException("파일 이름 인코딩 실패", e); | ||||||
|
|
||||||
| String encoded = URLEncoder.encode(originalFilename, StandardCharsets.UTF_8) | ||||||
| .replaceAll("\\+", "%20"); | ||||||
|
|
||||||
| // 파일명만 잘라내기 (확장자 유지) | ||||||
| String extension = ""; | ||||||
| int dotIndex = encoded.lastIndexOf('.'); | ||||||
| if (dotIndex != -1) { | ||||||
| extension = encoded.substring(dotIndex); | ||||||
| encoded = encoded.substring(0, dotIndex); | ||||||
| } | ||||||
|
|
||||||
| if (encoded.length() > MAX_FILENAME_LENGTH) { | ||||||
| encoded = encoded.substring(0, MAX_FILENAME_LENGTH); | ||||||
| } | ||||||
|
|
||||||
| return encoded; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| private String shortenKey(String key) { | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| import org.springframework.http.HttpHeaders; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
|
|
@@ -42,15 +43,22 @@ public ResponseEntity<ApiResponseWrapper<LoginResponse>> login( | |
| )); | ||
| } | ||
|
|
||
| @GetMapping("/check-cookie") | ||
| public ResponseEntity<Void> checkToken() { | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
|
|
||
| ; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| private HttpHeaders applyTokenHeader(Token token) { | ||
| HttpHeaders headers = new HttpHeaders(); | ||
|
|
||
| headers.add(HttpHeaders.SET_COOKIE, CookieBuilderUtil.createDevelopCookieString( | ||
| headers.add(HttpHeaders.SET_COOKIE, CookieBuilderUtil.createLocalCookieString( | ||
| CookieBuilderUtil.ACCESS_TOKEN_COOKIE_NAME, | ||
| token.accessToken(), | ||
| token.accessTokenExpireTime() | ||
| )); | ||
| headers.add(HttpHeaders.SET_COOKIE, CookieBuilderUtil.createDevelopCookieString( | ||
| headers.add(HttpHeaders.SET_COOKIE, CookieBuilderUtil.createLocalCookieString( | ||
| CookieBuilderUtil.REFRESH_TOKEN_COOKIE_NAME, | ||
| token.refreshToken(), | ||
| token.refreshTokenExpireTime() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is significant code duplication between this new block for handling
AuthConstants.COOKIE_ACCESSand the existing token validation logic that follows (lines 101-114). Both blocks resolve tokens, get the access token, and callsetAuthenticationwithin atry-catchblock.This duplication makes the code harder to maintain. For example:
tokenResolver.resolveTokens(request)is called twice.CustomRuntimeExceptionwhile the subsequent block wraps it. The logging levels and messages also differ.Consider refactoring to a single token validation flow that handles both cases to improve readability and maintainability.