@@ -185,6 +185,7 @@ export const TorrentFields = ({
185185
186186const Upload = ( { token, userId } ) => {
187187 const [ torrentFile , setTorrentFile ] = useState ( ) ;
188+ const [ posterFile , setPosterFile ] = useState ( ) ;
188189 const [ dropError , setDropError ] = useState ( "" ) ;
189190 const [ groupSuggestions , setGroupSuggestions ] = useState ( [ ] ) ;
190191
@@ -234,19 +235,51 @@ const Upload = ({ token, userId }) => {
234235 setDropError ( e . message ) ;
235236 }
236237 } , [ ] ) ;
238+ const onPosterDrop = useCallback ( ( acceptedFiles ) => {
239+ try {
240+ const [ file ] = acceptedFiles ;
241+ if ( file ) {
242+ const reader = new FileReader ( ) ;
243+ reader . onload = async ( ) => {
244+ console . log ( `[DEBUG] Poster upload complete: ${ reader . result . slice ( 0 , 64 ) } ...` ) ;
245+ const [ , posterB64 ] = reader . result . split ( "base64," ) ;
246+ setPosterFile ( { name : file . name , b64 : posterB64 } ) ;
247+ } ;
248+ reader . onerror = ( ) => {
249+ console . log ( `[DEBUG] Poster upload error: ${ reader . error } ` ) ;
250+ // Gérer les erreurs, si nécessaire
251+ } ;
252+ reader . readAsDataURL ( file ) ;
253+ }
254+ } catch ( e ) {
255+ console . error ( e ) ;
256+ // Gérer les erreurs, si nécessaire
257+ }
258+ } , [ ] ) ;
259+
237260
238261 const { getRootProps, getInputProps, isDragActive } = useDropzone ( {
239262 onDrop,
240263 accept : { "application/x-bittorrent" : [ ".torrent" ] } ,
241264 maxFiles : 1 ,
242265 } ) ;
266+ const { getRootProps : getPosterRootProps , getInputProps : getPosterInputProps , isDragActive : isPosterDragActive } = useDropzone ( {
267+ onDrop : onPosterDrop ,
268+ accept : {
269+ "image/jpeg" : [ ".jpg" , ".jpeg" ] ,
270+ "image/png" : [ ".png" ] ,
271+ } ,
272+ maxFiles : 1 ,
273+ } ) ;
274+
243275
244276 const handleUpload = async ( e ) => {
245277 e . preventDefault ( ) ;
246278 setLoading ( true ) ;
247279 const form = new FormData ( e . target ) ;
248280
249281 try {
282+ form . append ( "poster" , posterFile . b64 ) ; // Ajoutez la valeur de l'image de l'affiche à la requête
250283 if ( ! torrentFile ) throw new Error ( "No .torrent file added" ) ;
251284
252285 const uploadRes = await fetch ( `${ SQ_API_URL } /torrent/upload` , {
@@ -265,6 +298,7 @@ const Upload = ({ token, userId }) => {
265298 tags : form . get ( "tags" ) ,
266299 groupWith,
267300 mediaInfo : form . get ( "mediaInfo" ) ,
301+ poster : posterFile . b64 ,
268302 } ) ,
269303 } ) ;
270304
@@ -381,6 +415,27 @@ const Upload = ({ token, userId }) => {
381415 </ Text >
382416 ) }
383417 </ Box >
418+ < Box mb = { 4 } >
419+ < WrapLabel label = { getLocaleString ( "uploadPosterImage" ) } as = "div" >
420+ < FileUpload { ...getPosterRootProps ( ) } >
421+ < input { ...getPosterInputProps ( ) } />
422+ { posterFile ? (
423+ < Text icon = { Check } iconColor = "success" iconSize = { 24 } ml = { 2 } >
424+ { posterFile . name }
425+ </ Text >
426+ ) : isPosterDragActive ? (
427+ < Text color = "grey" >
428+ { getLocaleString ( "uploadDropImageHere" ) }
429+ </ Text >
430+ ) : (
431+ < Text color = "grey" >
432+ { getLocaleString ( "uploadDragDropClickSelect" ) }
433+ </ Text >
434+ ) }
435+ </ FileUpload >
436+ </ WrapLabel >
437+ </ Box >
438+
384439 < TorrentFields
385440 categories = { SQ_TORRENT_CATEGORIES }
386441 handleGroupSearch = { handleGroupSearch }
0 commit comments