Add new route for torrent download, fix Content-Disposition

New route is `/download/<torrent_id>.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
This commit is contained in:
TheAMM 2017-05-25 11:15:45 +03:00
parent 5a19dae649
commit b09c61980c
2 changed files with 3 additions and 2 deletions

View File

@ -745,6 +745,7 @@ def redirect_magnet(torrent_id):
@app.route('/view/<int:torrent_id>/torrent')
@app.route('/download/<int:torrent_id>.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

View File

@ -68,7 +68,7 @@
</div>
</div>
<div class="panel-footer">
{% if torrent.has_torrent %}<a href="/view/{{ torrent.id }}/torrent"><i class="fa fa-download fa-fw"></i>Download Torrent</a> or {% endif %}<a href="{{ torrent.magnet_uri }}" class="card-footer-item"><i class="fa fa-magnet fa-fw"></i>Magnet</a>
{% if torrent.has_torrent %}<a href="{{ url_for('download_torrent', torrent_id=torrent.id )}}"><i class="fa fa-download fa-fw"></i>Download Torrent</a> or {% endif %}<a href="{{ torrent.magnet_uri }}" class="card-footer-item"><i class="fa fa-magnet fa-fw"></i>Magnet</a>
</div>
</div>