Skip to content

Commit 5a936ef

Browse files
authored
Merge pull request #84 from TU-NEBULA/fix/SCRUM-211
SCRUM 211 : tistory 파비콘 통일 및 S3 파일 url 에러 해결
2 parents c2ba24c + 0b7c0e0 commit 5a936ef

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

src/main/java/com/team_nebula/nebula/domain/favicon/service/FaviconServiceImpl.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.team_nebula.nebula.global.image.FaviconDownloader;
66
import com.team_nebula.nebula.global.image.S3Service;
77
import lombok.RequiredArgsConstructor;
8+
import org.springframework.beans.factory.annotation.Value;
89
import org.springframework.stereotype.Service;
910
import org.springframework.transaction.annotation.Transactional;
1011

@@ -18,22 +19,30 @@ public class FaviconServiceImpl implements FaviconService {
1819
private final FaviconRepository faviconRepository;
1920
private final S3Service s3Service;
2021

22+
@Value("${favicon.tistory-default}")
23+
private String tistoryDefaultFavicon;
24+
2125
@Override
2226
public Favicon getOrCreateFavicon(String siteUrl) {
23-
// 1. 도메인 추출
27+
// 도메인 추출
2428
String domain = extractDomain(siteUrl);
2529

26-
// 2. 기존 Favicon이 있는지 확인
30+
// tistoy일 경우 체크
31+
if (domain.equals("tistory.com") || domain.endsWith(".tistory.com")) {
32+
domain = tistoryDefaultFavicon;
33+
}
34+
35+
// 기존 Favicon이 있는지 확인
2736
Optional<Favicon> existingFavicon = faviconRepository.findById(domain);
2837
if (existingFavicon.isPresent()) {
2938
return existingFavicon.get();
3039
}
3140

32-
// 3. 파비콘 다운로드 후 S3 업로드
41+
// 파비콘 다운로드 후 S3 업로드
3342
File faviconFile = downloadFavicon(domain);
3443
String faviconUrl = s3Service.saveFavicon(faviconFile, domain);
3544

36-
// 4. 새로운 Favicon 노드 저장 후 반환
45+
// 새로운 Favicon 노드 저장 후 반환
3746
Favicon newFavicon = new Favicon(domain, faviconUrl);
3847
return faviconRepository.save(newFavicon);
3948
}

src/main/java/com/team_nebula/nebula/domain/star/service/StarCommandServiceImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public CreateStarResponseDTO createFirstStar(Long userId, MultipartFile htmlFile
5454
UserNode userNode = userNodeRepository.findById(userId)
5555
.orElseThrow(() -> new GeneralException(ErrorStatus._USER_NOT_FOUND));
5656

57-
String htmlFileKey = s3Service.saveHtmlFile(htmlFile, title);
57+
String sanitizedTitle = s3Service.sanitizeTitleForS3(title);
58+
String htmlFileKey = s3Service.saveHtmlFile(htmlFile, sanitizedTitle);
5859

5960
Star star = Star.builder()
6061
.title(title)

src/main/java/com/team_nebula/nebula/global/image/S3Service.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,23 @@ public void deleteHtmlFileInS3(String fileKey){
132132
throw new GeneralException(ErrorStatus._S3_HTML_FILE_DELETE_FAIL);
133133
}
134134
}
135+
136+
public String sanitizeTitleForS3(String title) {
137+
if (title == null) return "";
138+
139+
// 1. 공백을 하나로 정규화
140+
title = title.replaceAll("\\s+", " ");
141+
142+
// 2. 한글, 영문, 숫자, '-', '_', '.', '~', 공백만 허용 (이모티콘, 특수문자, 대괄호 등 제거)
143+
title = title.replaceAll("[^가-힣a-zA-Z0-9\\-_.~ ]", "");
144+
145+
// 3. 공백을 하이픈으로 변환
146+
title = title.replace(" ", "-");
147+
148+
// 4. 소문자로 변환
149+
title = title.toLowerCase();
150+
151+
return title;
152+
}
135153
}
136154

0 commit comments

Comments
 (0)