Skip to content

Commit b224e4c

Browse files
author
Oleg Omelchenko
committed
incorrect work with non latin letters in torrent file or folder name
tdjsnelling#39
1 parent 515a2a0 commit b224e4c

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"bittorrent-tracker": "9.19.0",
2020
"body-parser": "^1.19.0",
2121
"chalk": "^4.1.1",
22+
"content-disposition": "^0.5.4",
2223
"cookie-parser": "^1.4.6",
2324
"cors": "^2.8.5",
2425
"dotenv": "^10.0.0",

api/src/controllers/torrent.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import User from "../schema/user";
88
import Comment from "../schema/comment";
99
import Group from "../schema/group";
1010
import { createGroup, addToGroup, removeFromGroup } from "./group";
11+
import contentDisposition from "content-disposition";
1112

1213
const urlReservedCharRegex = /[&$+,/:;=?@#<>\[\]{}|\\\^%]/g;
1314

@@ -254,13 +255,16 @@ export const downloadTorrent = async (req, res, next) => {
254255
delete parsed["announce-list"];
255256
parsed.info.private = 1;
256257

258+
const fileName = `${parsed.info.name.toString()} - ${
259+
process.env.SQ_SITE_NAME
260+
}.torrent`;
261+
257262
res.setHeader("Content-Type", "application/x-bittorrent");
258263
res.setHeader(
259264
"Content-Disposition",
260-
`attachment;filename=${parsed.info.name.toString()} - ${
261-
process.env.SQ_SITE_NAME
262-
}.torrent`
265+
`attachment;filename=${contentDisposition(fileName)}`
263266
);
267+
264268
res.write(bencode.encode(parsed));
265269
res.end();
266270
} catch (e) {

0 commit comments

Comments
 (0)