Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to make cover image not required. and optimization of my personal… #6

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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