mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2025-01-10 17:34:09 +00:00
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:
parent
5a19dae649
commit
b09c61980c
|
@ -745,6 +745,7 @@ def redirect_magnet(torrent_id):
|
||||||
|
|
||||||
|
|
||||||
@app.route('/view/<int:torrent_id>/torrent')
|
@app.route('/view/<int:torrent_id>/torrent')
|
||||||
|
@app.route('/download/<int:torrent_id>.torrent')
|
||||||
def download_torrent(torrent_id):
|
def download_torrent(torrent_id):
|
||||||
torrent = models.Torrent.by_id(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 = flask.Response(_get_cached_torrent_file(torrent))
|
||||||
resp.headers['Content-Type'] = 'application/x-bittorrent'
|
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')))
|
quote(torrent.torrent_name.encode('utf-8')))
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
|
|
|
@ -68,7 +68,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-footer">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue