diff --git a/renderer/views/create-torrent-page.js b/renderer/views/create-torrent-page.js index 82fe517e..495b33a2 100644 --- a/renderer/views/create-torrent-page.js +++ b/renderer/views/create-torrent-page.js @@ -8,7 +8,7 @@ var createTorrent = require('create-torrent') var path = require('path') var prettyBytes = require('prettier-bytes') -var {dispatch} = require('../lib/dispatcher') +var {dispatch, dispatcher} = require('../lib/dispatcher') function CreateTorrentPage (state) { var info = state.location.current() @@ -17,17 +17,14 @@ function CreateTorrentPage (state) { var files = info.files .filter((f) => !f.name.startsWith('.')) .map((f) => ({name: f.name, path: f.path, size: f.size})) + if (files.length === 0) return CreateTorrentErrorPage() // First, extract the base folder that the files are all in var pathPrefix = info.folderPath if (!pathPrefix) { - if (files.length > 0) { - pathPrefix = files.map((x) => x.path).reduce(findCommonPrefix) - if (!pathPrefix.endsWith('/') && !pathPrefix.endsWith('\\')) { - pathPrefix = path.dirname(pathPrefix) - } - } else { - pathPrefix = files[0] + pathPrefix = files.map((x) => x.path).reduce(findCommonPrefix) + if (!pathPrefix.endsWith('/') && !pathPrefix.endsWith('\\')) { + pathPrefix = path.dirname(pathPrefix) } } @@ -133,6 +130,27 @@ function CreateTorrentPage (state) { } } +function CreateTorrentErrorPage () { + return hx` +
+
+ Sorry, you must select at least one file that is not a hidden file. +
++ Hidden files, starting with a . character, are not included. +
+ ++ +
+