File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 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 ( / \. ( j p g | j p e g ) $ / i, '.webp' ) ;
31+ } ;
You can’t perform that action at this time.
0 commit comments