Skip to content

Commit 4ec621f

Browse files
committed
upload do not error on wrong announce / not private, just set them on backend
1 parent 0645138 commit 4ec621f

2 files changed

Lines changed: 6 additions & 21 deletions

File tree

api/src/controllers/torrent.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,6 @@ export const uploadTorrent = async (req, res, next) => {
3333
const torrent = Buffer.from(req.body.torrent, "base64");
3434
const parsed = bencode.decode(torrent);
3535

36-
if (parsed.info.private !== 1) {
37-
res.status(400).send("Torrent must be set to private");
38-
return;
39-
}
40-
41-
if (!parsed.announce || parsed["announce-list"]) {
42-
res.status(400).send("One and only one announce URL must be set");
43-
return;
44-
}
45-
4636
if (process.env.SQ_TORRENT_CATEGORIES.length && !req.body.type) {
4737
res.status(400).send("Torrent must have a category");
4838
return;
@@ -67,14 +57,6 @@ export const uploadTorrent = async (req, res, next) => {
6757

6858
const user = await User.findOne({ _id: req.userId }).lean();
6959

70-
if (
71-
parsed.announce.toString() !==
72-
`${process.env.SQ_BASE_URL}/sq/${user.uid}/announce`
73-
) {
74-
res.status(400).send("Announce URL is invalid");
75-
return;
76-
}
77-
7860
const infoHash = crypto
7961
.createHash("sha1")
8062
.update(bencode.encode(parsed.info))
@@ -87,6 +69,10 @@ export const uploadTorrent = async (req, res, next) => {
8769
return;
8870
}
8971

72+
parsed.info.private = 1;
73+
parsed.announce = `${process.env.SQ_BASE_URL}/sq/${user.uid}/announce`;
74+
delete parsed["announce-list"];
75+
9076
let files;
9177
if (parsed.info.files) {
9278
files = parsed.info.files.map((file) => ({

client/pages/upload.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,14 @@ const Upload = ({ token, userId }) => {
269269
</Text>
270270
<Box mb={5}>
271271
<Text icon={LinkIcon} iconColor="primary">
272-
Announce URL must be set to{" "}
272+
Announce URL:{" "}
273273
<Text
274274
as="strong"
275275
fontFamily="mono"
276276
_css={{ userSelect: "all", wordBreak: "break-all" }}
277277
>
278278
{SQ_BASE_URL}/sq/{userId}/announce
279-
</Text>{" "}
280-
or upload will be rejected
279+
</Text>
281280
</Text>
282281
</Box>
283282
<form onSubmit={handleUpload}>

0 commit comments

Comments
 (0)