From bafbf3d841a2bd0c7817ff953bad2a1961f106a7 Mon Sep 17 00:00:00 2001 From: DC Date: Wed, 25 May 2016 23:15:26 -0700 Subject: [PATCH] Show error when drag-dropping hidden files ...or anytime the user tries to create a torrent consisting only of hidden files, specifically dotfiles Fixes #586 --- renderer/views/create-torrent-page.js | 34 ++++++++++++++++++++------- 1 file changed, 26 insertions(+), 8 deletions(-) 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` +
+

Create torrent

+

+

+ Sorry, you must select at least one file that is not a hidden file. +

+

+ Hidden files, starting with a . character, are not included. +

+

+

+ +

+
+ ` +} + // Finds the longest common prefix function findCommonPrefix (a, b) { for (var i = 0; i < a.length && i < b.length; i++) {