-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 이벤트 배너 이미지 형식을 WebP로 전환하여 이미지 성능 개선 #198
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dd310e6
feat: 이미지 webp 패킷 변환 구현
Yejiin21 923f027
refact: 로컬 수정 반영 확인을 위해 https 로컬 설정 주석
Yejiin21 286e15d
feat: S3에 저장된 기존 이미지 .webp 마이그레이션 파일 구현
Yejiin21 8b59c9c
fix: 퍼널 상태 충돌 해결
Yejiin21 a76a14d
fix: 이벤트 생성 시 텍스트 에디터 입력 안되는 에러 해결
Yejiin21 8c72c59
fix: 데이터 전송할때 전화번호 하이픈 포함해서 보내도록 수정
Yejiin21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| export const convertImageToWebP = (file: File): Promise<File> => { | ||
| return new Promise((resolve, reject) => { | ||
| const img = new Image(); | ||
| const reader = new FileReader(); | ||
|
|
||
| reader.onload = () => { | ||
| if (typeof reader.result === 'string') { | ||
| img.src = reader.result; | ||
| } | ||
| }; | ||
|
|
||
| img.onload = () => { | ||
| const canvas = document.createElement('canvas'); | ||
| canvas.width = img.width; | ||
| canvas.height = img.height; | ||
|
|
||
| const ctx = canvas.getContext('2d'); | ||
| if (!ctx) return reject(new Error('Canvas context error')); | ||
|
|
||
| ctx.drawImage(img, 0, 0); | ||
|
|
||
| canvas.toBlob(blob => { | ||
| if (!blob) return reject(new Error('WebP 변환 실패')); | ||
| const webpFile = new File([blob], file.name.replace(/\.\w+$/, '.webp'), { | ||
| type: 'image/webp', | ||
| }); | ||
| resolve(webpFile); | ||
| }, 'image/webp'); | ||
| }; | ||
|
|
||
| img.onerror = reject; | ||
| reader.onerror = reject; | ||
|
|
||
| reader.readAsDataURL(file); | ||
| }); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { uploadFile } from '../../features/event/hooks/usePresignedUrlHook'; | ||
| import { convertImageToWebP } from './convertImageToWebP'; | ||
|
|
||
| const oldJpgUrls: string[] = [ | ||
| // ... 여기에 변환할 이미지 URL들 | ||
| ]; | ||
|
|
||
| export const runImageMigration = async () => { | ||
| for (const jpgUrl of oldJpgUrls) { | ||
| try { | ||
| const response = await fetch(jpgUrl); | ||
| const blob = await response.blob(); | ||
|
|
||
| const file = new File([blob], extractFileName(jpgUrl), { type: blob.type }); | ||
|
|
||
| const webpFile = await convertImageToWebP(file); | ||
| const webpUrl = await uploadFile(webpFile); | ||
|
|
||
| console.log(`✅ ${jpgUrl} → ${webpUrl}`); | ||
| } catch (error) { | ||
| console.error(`❌ 변환 실패: ${jpgUrl}`, error); | ||
| } | ||
| } | ||
|
|
||
| console.log('✅ 전체 마이그레이션 완료'); | ||
| }; | ||
|
|
||
| const extractFileName = (url: string) => { | ||
| const baseName = url.split('/').pop()?.split('?')[0] ?? 'unknown.jpg'; | ||
| return baseName.replace(/\.(jpg|jpeg)$/i, '.webp'); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🛠️ Refactor suggestion
마이그레이션 로직 개선 제안
기본 구조는 좋지만 다음 개선사항들을 고려해보세요:
export const runImageMigration = async () => { + const BATCH_SIZE = 5; // 동시 처리할 이미지 수 제한 + + for (let i = 0; i < oldJpgUrls.length; i += BATCH_SIZE) { + const batch = oldJpgUrls.slice(i, i + BATCH_SIZE); + const promises = batch.map(async (jpgUrl) => { - for (const jpgUrl of oldJpgUrls) { try { - const response = await fetch(jpgUrl); + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), 30000); // 30초 타임아웃 + + const response = await fetch(jpgUrl, { + signal: controller.signal + }); + clearTimeout(timeoutId); + const blob = await response.blob(); // ... 나머지 로직 } catch (error) { console.error(`❌ 변환 실패: ${jpgUrl}`, error); } + }); + + await Promise.allSettled(promises); + + // 배치 간 딜레이 + if (i + BATCH_SIZE < oldJpgUrls.length) { + await new Promise(resolve => setTimeout(resolve, 1000)); + } }📝 Committable suggestion
🤖 Prompt for AI Agents