From b224e4c8697d052671b1e3b2d346306d56c9e68b Mon Sep 17 00:00:00 2001 From: Oleg Omelchenko Date: Sat, 19 Aug 2023 21:10:03 +0300 Subject: [PATCH 1/2] incorrect work with non latin letters in torrent file or folder name https://github.com/tdjsnelling/sqtracker/issues/39 --- api/package.json | 1 + api/src/controllers/torrent.js | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/api/package.json b/api/package.json index c7e9d68..7c51868 100644 --- a/api/package.json +++ b/api/package.json @@ -19,6 +19,7 @@ "bittorrent-tracker": "9.19.0", "body-parser": "^1.19.0", "chalk": "^4.1.1", + "content-disposition": "^0.5.4", "cookie-parser": "^1.4.6", "cors": "^2.8.5", "dotenv": "^10.0.0", diff --git a/api/src/controllers/torrent.js b/api/src/controllers/torrent.js index a636df1..111311e 100644 --- a/api/src/controllers/torrent.js +++ b/api/src/controllers/torrent.js @@ -8,6 +8,7 @@ import User from "../schema/user"; import Comment from "../schema/comment"; import Group from "../schema/group"; import { createGroup, addToGroup, removeFromGroup } from "./group"; +import contentDisposition from "content-disposition"; const urlReservedCharRegex = /[&$+,/:;=?@#<>\[\]{}|\\\^%]/g; @@ -254,13 +255,16 @@ export const downloadTorrent = async (req, res, next) => { delete parsed["announce-list"]; parsed.info.private = 1; + const fileName = `${parsed.info.name.toString()} - ${ + process.env.SQ_SITE_NAME + }.torrent`; + res.setHeader("Content-Type", "application/x-bittorrent"); res.setHeader( "Content-Disposition", - `attachment;filename=${parsed.info.name.toString()} - ${ - process.env.SQ_SITE_NAME - }.torrent` + `attachment;filename=${contentDisposition(fileName)}` ); + res.write(bencode.encode(parsed)); res.end(); } catch (e) { From a072d94a7ce10d63ee0792a85cb7ab14e8bb63d0 Mon Sep 17 00:00:00 2001 From: Oleg Omelchenko Date: Mon, 21 Aug 2023 23:28:20 +0300 Subject: [PATCH 2/2] incorrect work with non latin letters in torrent file or folder name https://github.com/tdjsnelling/sqtracker/issues/39 --- api/src/controllers/torrent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/controllers/torrent.js b/api/src/controllers/torrent.js index 111311e..3e039b5 100644 --- a/api/src/controllers/torrent.js +++ b/api/src/controllers/torrent.js @@ -3,12 +3,12 @@ import crypto from "crypto"; import mongoose from "mongoose"; import { createNGrams, nGrams } from "mongoose-fuzzy-searching/helpers"; import slugify from "slugify"; +import contentDisposition from "content-disposition"; import Torrent from "../schema/torrent"; import User from "../schema/user"; import Comment from "../schema/comment"; import Group from "../schema/group"; import { createGroup, addToGroup, removeFromGroup } from "./group"; -import contentDisposition from "content-disposition"; const urlReservedCharRegex = /[&$+,/:;=?@#<>\[\]{}|\\\^%]/g;