Skip to content

Commit

Permalink
Fix to make cover image not required. and optimization of my personal…
Browse files Browse the repository at this point in the history
… code following the comments made on the Pull request
  • Loading branch information
Klaiment committed Oct 12, 2023
1 parent 375db33 commit 3b8604b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
1 change: 0 additions & 1 deletion api/src/controllers/torrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,6 @@ export const getTorrentsPage = async ({
created: 1,
freeleech: 1,
tags: 1,
poster: 1,
confidenceScore: 1,
},
},
Expand Down
37 changes: 23 additions & 14 deletions client/pages/torrent/[infoHash].js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<SEO title={torrent.name} />
Expand Down Expand Up @@ -664,19 +666,27 @@ const Torrent = ({ token, torrent = {}, userId, userRole, uid, userStats }) => {
: [getLocaleString("torrNo")],
}}
/>
<Infobox mb={5}>
<Text fontWeight={600} fontSize={1} textTransform="uppercase" mb={3}>
{getLocaleString("PosterImage")}
</Text>
<img
src={`data:image/${
isPngImage(torrent.poster) ? "png" : "jpeg"
};base64,${torrent.poster}`}
alt="Poster"
width="auto"
height={200}
/>
</Infobox>
{torrent.poster && (
<Infobox mb={5}>
<Text
fontWeight={600}
fontSize={1}
_css={{ textTransform: "uppercase" }}
mb={3}
>
{getLocaleString("posterImage")}
</Text>
<img
src={`data:image/${
isPngImage(torrent.poster) ? "png" : "jpeg"
};base64,${torrent.poster}`}
alt="Poster"
width="auto"
height={200}
/>
</Infobox>
)}


<Infobox mb={5}>
<Text
Expand Down Expand Up @@ -708,7 +718,6 @@ const Torrent = ({ token, torrent = {}, userId, userRole, uid, userStats }) => {
</Box>
</Infobox>
)}
{console.log(torrent)}
<Infobox mb={5}>
<Text
fontWeight={600}
Expand Down
22 changes: 12 additions & 10 deletions client/pages/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ const Upload = ({ token, userId }) => {
"image/png": [".png"],
},
maxFiles: 1,
maxSize: 5242880, //5Mo
});
function isPngImage(data) {
const pngHeader = "data:image/png;base64,";
Expand All @@ -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: {
Expand All @@ -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,
}),
});

Expand Down Expand Up @@ -436,18 +435,21 @@ const Upload = ({ token, userId }) => {
width={"auto"}
height={200}
/>
) : isPosterDragActive ? (
<Text color="grey">
{getLocaleString("uploadDropImageHere")}
</Text>
) : (
<Text color="grey">
{getLocaleString("uploadDragDropClickSelectPoster")}
</Text>
isPosterDragActive ? (
<Text color="grey">
{getLocaleString("uploadDropImageHere")}
</Text>
) : (
<Text color="grey">
{getLocaleString("uploadDragDropClickSelectPoster")}
</Text>
)
)}
</FileUpload>
</WrapLabel>
</Box>

<TorrentFields
categories={SQ_TORRENT_CATEGORIES}
handleGroupSearch={handleGroupSearch}
Expand Down

0 comments on commit 3b8604b

Please sign in to comment.