Skip to content

Commit

Permalink
Merge pull request #6 from Klaiment/Fix/poster
Browse files Browse the repository at this point in the history
Fix to make cover image not required. and optimization of my personal…
  • Loading branch information
Klaiment authored Oct 12, 2023
2 parents cfba440 + 3b8604b commit 2426fef
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
36 changes: 23 additions & 13 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
22 changes: 12 additions & 10 deletions client/pages/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ const Upload = ({ token, userId }) => {
"image/png": [".png"],
},
maxFiles: 1,
maxSize: 5242880, //5Mo
});
function isPngImage(data) {
const pngHeader = "data:image/png;base64,";
Expand All @@ -285,9 +286,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 @@ -304,7 +303,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 @@ -434,18 +433,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 2426fef

Please sign in to comment.