From b09c61980c9a5d9c7a707b5864dbbb7281eb9559 Mon Sep 17 00:00:00 2001 From: TheAMM Date: Thu, 25 May 2017 11:15:45 +0300 Subject: [PATCH] Add new route for torrent download, fix Content-Disposition New route is `/download/.torrent`, which will help people using tools that do not consider headers. Old torrent download route still works. Updated one remaining link to use url_for. Added plain `filename="..."` to `Content-Disposition`, since it is still the most common standard with percent encoded UTF-8. Fixes part 2 of #45 --- nyaa/routes.py | 3 ++- nyaa/templates/view.html | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/nyaa/routes.py b/nyaa/routes.py index 952f19e..419320e 100644 --- a/nyaa/routes.py +++ b/nyaa/routes.py @@ -745,6 +745,7 @@ def redirect_magnet(torrent_id): @app.route('/view//torrent') +@app.route('/download/.torrent') def download_torrent(torrent_id): torrent = models.Torrent.by_id(torrent_id) @@ -753,7 +754,7 @@ def download_torrent(torrent_id): resp = flask.Response(_get_cached_torrent_file(torrent)) resp.headers['Content-Type'] = 'application/x-bittorrent' - resp.headers['Content-Disposition'] = 'inline; filename*=UTF-8\'\'{}'.format( + resp.headers['Content-Disposition'] = 'inline; filename="{0}"; filename*=UTF-8\'\'{0}'.format( quote(torrent.torrent_name.encode('utf-8'))) return resp diff --git a/nyaa/templates/view.html b/nyaa/templates/view.html index 70b9565..bef4690 100644 --- a/nyaa/templates/view.html +++ b/nyaa/templates/view.html @@ -68,7 +68,7 @@