diff --git a/modules/backup/server/controllers/backup.server.controller.js b/modules/backup/server/controllers/backup.server.controller.js index cf98eb81..6874b22f 100644 --- a/modules/backup/server/controllers/backup.server.controller.js +++ b/modules/backup/server/controllers/backup.server.controller.js @@ -74,7 +74,7 @@ exports.download = function (req, res) { try { res.set('Content-Type', 'application/octet-stream'); - res.set('Content-Disposition', 'attachment; filename=' + encodeURI(req.params.filename)); + res.set('Content-Disposition', 'attachment; filename*=UTF-8\'\'' + encodeURIComponent(req.params.filename)); res.set('Content-Length', stat.size); fs.createReadStream(filePath).pipe(res); diff --git a/modules/forums/server/controllers/forums.server.controller.js b/modules/forums/server/controllers/forums.server.controller.js index 033faf0d..5ec59cdb 100644 --- a/modules/forums/server/controllers/forums.server.controller.js +++ b/modules/forums/server/controllers/forums.server.controller.js @@ -1025,7 +1025,7 @@ exports.attachDownload = function (req, res) { try { //res.set('Content-Type', 'application/x-bittorrent'); - res.set('Content-Disposition', 'attachment; filename=' + encodeURI(filename)); + res.set('Content-Disposition', 'attachment; filename*=UTF-8\'\'' + encodeURIComponent(filename)); res.set('Content-Length', stat.size); fs.createReadStream(filePath).pipe(res); diff --git a/modules/torrents/client/services/torrent-download.client.service.js b/modules/torrents/client/services/torrent-download.client.service.js index 078f9742..237cddfc 100644 --- a/modules/torrents/client/services/torrent-download.client.service.js +++ b/modules/torrents/client/services/torrent-download.client.service.js @@ -115,7 +115,7 @@ responseType: 'blob' }).then(function successCallback(response) { var contentDisposition = response.headers('Content-Disposition'); - var fileName = decodeURI(contentDisposition.substr(contentDisposition.indexOf('filename=') + 9)); + var fileName = decodeURI(contentDisposition.substr(contentDisposition.indexOf('filename*=UTF-8\'\'') + 17)); FileSaver.saveAs(response.data, fileName); if (successcb) successcb(response.status); diff --git a/modules/torrents/server/controllers/subtitles.server.controller.js b/modules/torrents/server/controllers/subtitles.server.controller.js index f88170e2..146965e0 100644 --- a/modules/torrents/server/controllers/subtitles.server.controller.js +++ b/modules/torrents/server/controllers/subtitles.server.controller.js @@ -192,7 +192,7 @@ exports.download = function (req, res) { try { //res.set('Content-Type', 'application/x-bittorrent'); - res.set('Content-Disposition', 'attachment; filename=' + encodeURI(r.subtitle_filename)); + res.set('Content-Disposition', 'attachment; filename*=UTF-8\'\'' + encodeURIComponent(r.subtitle_filename)); res.set('Content-Length', stat.size); fs.createReadStream(filePath).pipe(res); diff --git a/modules/torrents/server/controllers/torrents.server.controller.js b/modules/torrents/server/controllers/torrents.server.controller.js index e5ce9b31..1265340d 100644 --- a/modules/torrents/server/controllers/torrents.server.controller.js +++ b/modules/torrents/server/controllers/torrents.server.controller.js @@ -422,7 +422,7 @@ exports.announceEdit = function (req, res) { getTorrentFileData(filePath) .then(function () { res.set('Content-Type', 'application/x-bittorrent'); - res.set('Content-Disposition', 'attachment; filename=' + encodeURI(req.file.filename)); + res.set('Content-Disposition', 'attachment; filename*=UTF-8\'\'' + encodeURIComponent(req.file.filename)); res.set('Content-Length', stat.size); res.send(benc.encode(torrent_data)); @@ -503,39 +503,47 @@ exports.download = function (req, res) { var torrent_data = null; var filePath = config.uploads.torrent.file.dest + req.torrent.torrent_filename; - if (req.torrent.torrent_vip && !req.user.isVip) { - return res.status(701).send({ - message: 'SERVER.ONLY_VIP_CAN_DOWNLOAD' - }); - } else if (req.user.status === 'banned') { - return res.status(702).send({ - message: 'SERVER.CAN_NOT_DOWNLOAD_BANNED' - }); - } else if (req.user.status === 'idle') { - return res.status(703).send({ - message: 'SERVER.CAN_NOT_DOWNLOAD_IDLE' - }); - } else { - fs.exists(filePath, function (exists) { - if (exists) { - var stat = fs.statSync(filePath); - getTorrentFileData(filePath) - .then(function () { - res.set('Content-Type', 'application/x-bittorrent'); - res.set('Content-Disposition', 'attachment; filename=' + config.meanTorrentConfig.announce.announcePrefix + encodeURI(req.torrent.torrent_filename)); - res.set('Content-Length', stat.size); + var user = req.user || req.passkeyuser || undefined; - res.send(benc.encode(torrent_data)); - }) - .catch(function (err) { - mtDebug.debugRed(err); - res.status(422).send(err); + if (user) { + if (req.torrent.torrent_vip && !user.isVip) { + return res.status(701).send({ + message: 'SERVER.ONLY_VIP_CAN_DOWNLOAD' + }); + } else if (user.status === 'banned') { + return res.status(702).send({ + message: 'SERVER.CAN_NOT_DOWNLOAD_BANNED' + }); + } else if (user.status === 'idle') { + return res.status(703).send({ + message: 'SERVER.CAN_NOT_DOWNLOAD_IDLE' + }); + } else { + fs.exists(filePath, function (exists) { + if (exists) { + var stat = fs.statSync(filePath); + getTorrentFileData(filePath) + .then(function () { + res.set('Content-Type', 'application/x-bittorrent'); + res.set('Content-Disposition', 'attachment; filename*=UTF-8\'\'' + config.meanTorrentConfig.announce.announcePrefix + encodeURIComponent(req.torrent.torrent_filename)); + res.set('Content-Length', stat.size); + + res.send(benc.encode(torrent_data)); + }) + .catch(function (err) { + mtDebug.debugRed(err); + res.status(422).send(err); + }); + } else { + res.status(422).send({ + message: 'SERVER.FILE_DOES_NOT_EXISTS' }); - } else { - res.status(422).send({ - message: 'FILE_DOES_NOT_EXISTS' - }); - } + } + }); + } + } else { + return res.status(403).json({ + message: 'SERVER.USER_IS_NOT_AUTHORIZED' }); } @@ -549,7 +557,7 @@ exports.download = function (req, res) { reject(message); } else { if (config.meanTorrentConfig.announce.privateTorrentCmsMode) { - var announce = config.meanTorrentConfig.announce.url + '/' + req.user.passkey; + var announce = config.meanTorrentConfig.announce.url + '/' + user.passkey; torrent.metadata.announce = announce; } torrent_data = torrent.metadata;