Skip to content

Commit 286e15d

Browse files
committed
feat: S3에 저장된 기존 이미지 .webp 마이그레이션 파일 구현
1 parent 923f027 commit 286e15d

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/shared/lib/migrateJpgToWebp.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { uploadFile } from '../../features/event/hooks/usePresignedUrlHook';
2+
import { convertImageToWebP } from './convertImageToWebP';
3+
4+
const oldJpgUrls: string[] = [
5+
// ... 여기에 변환할 이미지 URL들
6+
];
7+
8+
export const runImageMigration = async () => {
9+
for (const jpgUrl of oldJpgUrls) {
10+
try {
11+
const response = await fetch(jpgUrl);
12+
const blob = await response.blob();
13+
14+
const file = new File([blob], extractFileName(jpgUrl), { type: blob.type });
15+
16+
const webpFile = await convertImageToWebP(file);
17+
const webpUrl = await uploadFile(webpFile);
18+
19+
console.log(`✅ ${jpgUrl}${webpUrl}`);
20+
} catch (error) {
21+
console.error(`❌ 변환 실패: ${jpgUrl}`, error);
22+
}
23+
}
24+
25+
console.log('✅ 전체 마이그레이션 완료');
26+
};
27+
28+
const extractFileName = (url: string) => {
29+
const baseName = url.split('/').pop()?.split('?')[0] ?? 'unknown.jpg';
30+
return baseName.replace(/\.(jpg|jpeg)$/i, '.webp');
31+
};

0 commit comments

Comments
 (0)