Skip to content
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
11 changes: 11 additions & 0 deletions src/main/java/com/adoonge/seedzip/seed/service/SeedService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.adoonge.seedzip.tag.domain.type.DefaultTagType;
import com.adoonge.seedzip.tag.repository.TagRepository;
import com.adoonge.seedzip.tag.repository.UsedDefaultTagRepository;
import com.amazonaws.services.dynamodbv2.xspec.S;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
Expand Down Expand Up @@ -164,6 +165,16 @@ public SeedResponse.SeedInfoSimple uploadSeed(SeedRequest seedRequest, Member me

@Transactional
public void uploadFiles(Long seedId, List<MultipartFile> files) {
for(MultipartFile file : files){
String contentType = file.getContentType();
if (contentType == null ||
!(contentType.equalsIgnoreCase("image/png") ||
contentType.equalsIgnoreCase("image/jpg") ||
contentType.equalsIgnoreCase("image/jpeg"))) {
throw SeedzipException.from(ErrorCode.SEED_TYPE_NOT_SUPPORTED);
}
}

Seed seed = seedRepository.findById(seedId).orElseThrow(
() -> SeedzipException.from(ErrorCode.SEED_NOT_FOUND)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.adoonge.seedzip.simplification.service;

import static com.adoonge.seedzip.global.exception.ErrorCode.*;

import com.adoonge.seedzip.global.service.S3Service;
import com.adoonge.seedzip.global.exception.ErrorCode;
import com.adoonge.seedzip.global.exception.SeedzipException;
Expand Down Expand Up @@ -77,7 +79,21 @@ public SimplificationInfoResponse requestImageAnalysis(MultipartFile file) {
} catch (IOException e) {
throw SeedzipException.from(ErrorCode.INTERNAL_SEVER_ERROR);
}
String imageUrl = "data:image/jpeg;base64," + base64Image;

// MIME 타입 확인
String contentType = file.getContentType();
if (contentType == null) {
throw SeedzipException.from(SEED_TYPE_NOT_SUPPORTED);
}

// jpg/jpeg/png만 허용
if (!(contentType.equalsIgnoreCase("image/jpeg") ||
contentType.equalsIgnoreCase("image/jpg") ||
contentType.equalsIgnoreCase("image/png"))) {
throw SeedzipException.from(SEED_TYPE_NOT_SUPPORTED);}

String imageUrl = "data:" + contentType + ";base64," + base64Image;

ChatGPTRequest request = ChatGPTRequest.createImageRequest(apiModel, 500, imageUrl);
ChatGPTResponse chatGPTResponse = template.postForObject(apiUrl, request, ChatGPTResponse.class);

Expand Down