@@ -39,64 +39,6 @@ function ImageUploader({ onImageSelect, initialImageUrl, className = '' }: Image
3939 setPreviewUrl ( objectUrl ) ;
4040 } , [ ] ) ;
4141
42- const handleFileChange = useCallback (
43- async ( event : ChangeEvent < HTMLInputElement > ) => {
44- const file = event . target . files ?. [ 0 ] ;
45- if ( ! file ) return ;
46-
47- if ( file . type . startsWith ( 'video/' ) ) {
48- try {
49- const video = document . createElement ( 'video' ) ;
50- const videoObjectUrl = URL . createObjectURL ( file ) ;
51- video . src = videoObjectUrl ;
52- video . crossOrigin = 'anonymous' ;
53- video . muted = true ;
54-
55- await new Promise < void > ( ( resolve , reject ) => {
56- video . onloadeddata = ( ) => {
57- video . currentTime = Math . min ( 1 , video . duration / 2 ) ;
58- } ;
59- video . onseeked = ( ) => resolve ( ) ;
60- video . onerror = ( ) => reject ( new Error ( 'Failed to load video' ) ) ;
61- } ) ;
62-
63- const canvas = document . createElement ( 'canvas' ) ;
64- canvas . width = video . videoWidth ;
65- canvas . height = video . videoHeight ;
66- const ctx = canvas . getContext ( '2d' ) ;
67- if ( ctx ) {
68- ctx . drawImage ( video , 0 , 0 , canvas . width , canvas . height ) ;
69- canvas . toBlob (
70- ( blob ) => {
71- if ( blob ) {
72- const objectUrl = URL . createObjectURL ( blob ) ;
73- setObjectPreviewUrl ( objectUrl ) ;
74- const optimizedFile = new File ( [ blob ] , file . name . replace ( / \. [ ^ / . ] + $ / , '.jpg' ) , {
75- type : 'image/jpeg' ,
76- } ) ;
77- onImageSelect ( optimizedFile ) ;
78- }
79- } ,
80- 'image/jpeg' ,
81- 0.85 ,
82- ) ;
83- }
84- URL . revokeObjectURL ( videoObjectUrl ) ;
85- } catch ( error ) {
86- console . error ( 'Video optimization failed:' , error ) ;
87- }
88- } else if ( file . type . startsWith ( 'image/' ) ) {
89- const objectUrl = URL . createObjectURL ( file ) ;
90- setObjectPreviewUrl ( objectUrl ) ;
91- onImageSelect ( file ) ;
92- }
93-
94- if ( fileInputRef . current ) {
95- fileInputRef . current . value = '' ;
96- }
97- } ,
98- [ onImageSelect , setObjectPreviewUrl ] ,
99- ) ;
10042 const handleFileChange = useCallback (
10143 async ( event : ChangeEvent < HTMLInputElement > ) => {
10244 const file = event . target . files ?. [ 0 ] ;
0 commit comments