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

시험 지문에 마크다운 에디터로 이미지 추가를 할 수 있다. #46

Merged
merged 14 commits into from
Feb 2, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.fluffy.exam.domain.ExamImage;
import com.fluffy.exam.domain.ExamImageRepository;
import com.fluffy.exam.domain.ExamRepository;
import com.fluffy.global.exception.BadRequestException;
import com.fluffy.global.exception.ForbiddenException;
import com.fluffy.global.web.Accessor;
import com.fluffy.storage.application.StorageClient;
Expand All @@ -31,7 +32,7 @@ public String uploadImage(Long examId, MultipartFile image, Accessor accessor) {
UUID imageId = UUID.randomUUID();

Long fileSize = image.getSize();
String filePath = generateUploadPath(imageId, accessor.id(), image.getOriginalFilename());
String filePath = generateUploadPath(imageId, accessor.id(), image);

ExamImage examImage = new ExamImage(imageId, accessor.id(), examId, filePath, fileSize);
examImageRepository.save(examImage);
Expand All @@ -53,7 +54,13 @@ private void validateExamAuthor(Long examId, Accessor accessor) {
}
}

private String generateUploadPath(UUID imageId, Long memberId, String originalFilename) {
private String generateUploadPath(UUID imageId, Long memberId, MultipartFile image) {
String originalFilename = image.getOriginalFilename();

if (image.isEmpty() || originalFilename == null) {
throw new BadRequestException("이미지 파일이 비어있습니다.");
}

int lastDotIndex = originalFilename.lastIndexOf(".");
String extension = originalFilename.substring(lastDotIndex + 1);

Expand Down
2 changes: 2 additions & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@hello-pangea/dnd": "^17.0.0",
"@nextui-org/react": "^2.4.8",
"@tanstack/react-query": "^5.59.16",
"@uiw/react-md-editor": "^4.0.5",
"axios": "^1.7.7",
"date-fns": "^4.1.0",
"framer-motion": "^11.13.1",
Expand All @@ -25,6 +26,7 @@
"react-hot-toast": "^2.4.1",
"react-icons": "^5.4.0",
"react-router": "^7.0.2",
"rehype-sanitize": "^6.0.0",
"zustand": "^5.0.0"
},
"devDependencies": {
Expand Down
Loading