Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Fix "Save Torrent File" feature
Browse files Browse the repository at this point in the history
This feature broke again after PR #8325. My fault for not catching it
during review. This PR fixes the code that is now on `master`.

Addresses these comments:

-
#8446 (comment)
-
#8146 (comment)
52

It is better to add the '?download=true' querystring param with
`url.parse` and `url.format` since blindly tacking on a
'?download=true' can lead to invalid URLs.

A couple examples:

magnet:?a=b&c=d?download=true should use &download=true instead
https://example.com/file.torrent#ix=1?download=true should not add a
query param after a hash

Also, this names the downloaded file correctly, which didn't seem to be
working either after PR #8325.
  • Loading branch information
feross committed Apr 29, 2017
1 parent 4d2b95e commit 26d31c4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions js/webtorrent/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,15 @@ function stop () {
}

function saveTorrentFile () {
let a = document.createElement('a')
const parsedUrl = url.parse(store.torrentId, true)
parsedUrl.query.download = true
const name = path.basename(parsedUrl.pathname) || 'untitled.torrent'
const href = url.format(parsedUrl)

const a = document.createElement('a')
a.target = '_blank'
a.download = true
a.href = `${store.torrentId}?download=ok`
a.download = name
a.href = href
a.click()
}

Expand Down

0 comments on commit 26d31c4

Please sign in to comment.