From 3b8604b1ce739d9dd622291fc02c539ba7fd95b8 Mon Sep 17 00:00:00 2001 From: Klaiment Date: Thu, 12 Oct 2023 19:24:59 +0200 Subject: [PATCH] Fix to make cover image not required. and optimization of my personal code following the comments made on the Pull request --- api/src/controllers/torrent.js | 1 - client/pages/torrent/[infoHash].js | 37 +++++++++++++++++++----------- client/pages/upload.js | 22 ++++++++++-------- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/api/src/controllers/torrent.js b/api/src/controllers/torrent.js index b308361..e82bdc2 100644 --- a/api/src/controllers/torrent.js +++ b/api/src/controllers/torrent.js @@ -508,7 +508,6 @@ export const getTorrentsPage = async ({ created: 1, freeleech: 1, tags: 1, - poster: 1, confidenceScore: 1, }, }, diff --git a/client/pages/torrent/[infoHash].js b/client/pages/torrent/[infoHash].js index 7301724..d4d7ac6 100644 --- a/client/pages/torrent/[infoHash].js +++ b/client/pages/torrent/[infoHash].js @@ -523,10 +523,12 @@ const Torrent = ({ token, torrent = {}, userId, userRole, uid, userStats }) => { userStats.ratio < Number(SQ_MINIMUM_RATIO)) || (Number(SQ_MAXIMUM_HIT_N_RUNS) !== -1 && userStats.hitnruns > Number(SQ_MAXIMUM_HIT_N_RUNS)); + function isPngImage(data) { const pngHeader = "data:image/png;base64,"; return data.startsWith(pngHeader); } + return ( <> @@ -664,19 +666,27 @@ const Torrent = ({ token, torrent = {}, userId, userRole, uid, userStats }) => { : [getLocaleString("torrNo")], }} /> - - - {getLocaleString("PosterImage")} - - Poster - + {torrent.poster && ( + + + {getLocaleString("posterImage")} + + Poster + + )} + { )} - {console.log(torrent)} { "image/png": [".png"], }, maxFiles: 1, + maxSize: 5242880, //5Mo }); function isPngImage(data) { const pngHeader = "data:image/png;base64,"; @@ -287,9 +288,7 @@ const Upload = ({ token, userId }) => { const form = new FormData(e.target); try { - form.append("poster", posterFile.b64); // Ajoutez la valeur de l'image de l'affiche à la requête if (!torrentFile) throw new Error("No .torrent file added"); - const uploadRes = await fetch(`${SQ_API_URL}/torrent/upload`, { method: "POST", headers: { @@ -306,7 +305,7 @@ const Upload = ({ token, userId }) => { tags: form.get("tags"), groupWith, mediaInfo: form.get("mediaInfo"), - poster: posterFile.b64, + poster: posterFile ? posterFile.b64 : null, }), }); @@ -436,18 +435,21 @@ const Upload = ({ token, userId }) => { width={"auto"} height={200} /> - ) : isPosterDragActive ? ( - - {getLocaleString("uploadDropImageHere")} - ) : ( - - {getLocaleString("uploadDragDropClickSelectPoster")} - + isPosterDragActive ? ( + + {getLocaleString("uploadDropImageHere")} + + ) : ( + + {getLocaleString("uploadDragDropClickSelectPoster")} + + ) )} +