Fix incorrect path when for single-file torrents

Fixes #457
This commit is contained in:
DC
2016-05-10 22:48:04 -07:00
parent 905cc527d0
commit 2b8c1fe709

View File

@@ -33,7 +33,6 @@ function CreateTorrentPage (state) {
// Sanity check: show the number of files and total size // Sanity check: show the number of files and total size
var numFiles = files.length var numFiles = files.length
console.log('FILES', files)
var totalBytes = files var totalBytes = files
.map((f) => f.size) .map((f) => f.size)
.reduce((a, b) => a + b, 0) .reduce((a, b) => a + b, 0)
@@ -41,10 +40,16 @@ function CreateTorrentPage (state) {
// Then, use the name of the base folder (or sole file, for a single file torrent) // Then, use the name of the base folder (or sole file, for a single file torrent)
// as the default name. Show all files relative to the base folder. // as the default name. Show all files relative to the base folder.
var defaultName = files.length === 1 var defaultName, basePath
? files[0].name if (files.length === 1) {
: path.basename(pathPrefix) // Single file torrent: /a/b/foo.jpg -> torrent name "foo.jpg", path "/a/b"
var basePath = path.dirname(pathPrefix) defaultName = files[0].name
basePath = pathPrefix
} else {
// Multi file torrent: /a/b/{foo, bar}.jpg -> torrent name "b", path "/a"
defaultName = files[0].name
basePath = path.basename(pathPrefix)
}
var maxFileElems = 100 var maxFileElems = 100
var fileElems = files.slice(0, maxFileElems).map(function (file) { var fileElems = files.slice(0, maxFileElems).map(function (file) {
var relativePath = files.length === 0 ? file.name : path.relative(pathPrefix, file.path) var relativePath = files.length === 0 ? file.name : path.relative(pathPrefix, file.path)