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..3e039b5 100644 --- a/api/src/controllers/torrent.js +++ b/api/src/controllers/torrent.js @@ -3,6 +3,7 @@ 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"; @@ -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) {