From bb4eb523fe0365f659d55a57fc7e47032936d453 Mon Sep 17 00:00:00 2001 From: clujin Date: Sat, 6 Oct 2018 18:59:03 -0700 Subject: [PATCH 1/4] initial commit --- src/renderer/lib/torrent-poster.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/renderer/lib/torrent-poster.js b/src/renderer/lib/torrent-poster.js index 22374a66..50169138 100644 --- a/src/renderer/lib/torrent-poster.js +++ b/src/renderer/lib/torrent-poster.js @@ -110,6 +110,8 @@ function scoreAudioCoverFile (imgFile) { function torrentPosterFromAudio (torrent, cb) { const imageFiles = filterOnExtension(torrent, mediaExtensions.image) + if (!imageFiles.length) return cb(new Error('Generated poster contains no files')); + const bestCover = imageFiles.map(file => { return { file: file, From 788e907502a095c9eed8998bf3880515b925c5e5 Mon Sep 17 00:00:00 2001 From: clujin Date: Sat, 6 Oct 2018 19:14:03 -0700 Subject: [PATCH 2/4] remove semicolon --- src/renderer/lib/torrent-poster.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/lib/torrent-poster.js b/src/renderer/lib/torrent-poster.js index 50169138..01af8bf9 100644 --- a/src/renderer/lib/torrent-poster.js +++ b/src/renderer/lib/torrent-poster.js @@ -110,7 +110,7 @@ function scoreAudioCoverFile (imgFile) { function torrentPosterFromAudio (torrent, cb) { const imageFiles = filterOnExtension(torrent, mediaExtensions.image) - if (!imageFiles.length) return cb(new Error('Generated poster contains no files')); + if (imageFiles.length === 0) return cb(new Error('Generated poster contains no files')) const bestCover = imageFiles.map(file => { return { From 02fefd0a8120aeac8604a11a6222e42e3fb6d73d Mon Sep 17 00:00:00 2001 From: clujin Date: Sun, 7 Oct 2018 10:42:42 -0700 Subject: [PATCH 3/4] remove redundant error check --- src/renderer/lib/torrent-poster.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/renderer/lib/torrent-poster.js b/src/renderer/lib/torrent-poster.js index 01af8bf9..1b1ed92a 100644 --- a/src/renderer/lib/torrent-poster.js +++ b/src/renderer/lib/torrent-poster.js @@ -131,8 +131,6 @@ function torrentPosterFromAudio (torrent, cb) { return b }) - if (!bestCover) return cb(new Error('Generated poster contains no data')) - const extname = path.extname(bestCover.file.name) bestCover.file.getBuffer((err, buf) => cb(err, buf, extname)) } From ab20dc42f13f263a27246b6ac91d3f95fdd8fcdd Mon Sep 17 00:00:00 2001 From: Borewit Date: Sun, 7 Oct 2018 20:15:12 +0200 Subject: [PATCH 4/4] #1426 Consistent error message if no suitable poster image could be found. --- src/renderer/lib/torrent-poster.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/renderer/lib/torrent-poster.js b/src/renderer/lib/torrent-poster.js index 1b1ed92a..b67d66f5 100644 --- a/src/renderer/lib/torrent-poster.js +++ b/src/renderer/lib/torrent-poster.js @@ -5,6 +5,8 @@ const path = require('path') const mediaExtensions = require('./media-extensions') +const msgNoSuitablePoster = 'Cannot generate a poster from any files in the torrent' + function torrentPoster (torrent, cb) { // First, try to use a poster image if available const posterFile = torrent.files.filter(function (file) { @@ -23,7 +25,7 @@ function torrentPoster (torrent, cb) { if (bestScore.size === 0) { // Admit defeat, no video, audio or image had a significant presence - return cb(new Error('Cannot generate a poster from any files in the torrent')) + return cb(new Error(msgNoSuitablePoster)) } // Based on which media type is dominant we select the corresponding poster function @@ -110,7 +112,7 @@ function scoreAudioCoverFile (imgFile) { function torrentPosterFromAudio (torrent, cb) { const imageFiles = filterOnExtension(torrent, mediaExtensions.image) - if (imageFiles.length === 0) return cb(new Error('Generated poster contains no files')) + if (imageFiles.length === 0) return cb(new Error(msgNoSuitablePoster)) const bestCover = imageFiles.map(file => { return { @@ -172,7 +174,7 @@ function torrentPosterFromVideo (torrent, cb) { server.destroy() - if (buf.length === 0) return cb(new Error('Generated poster contains no data')) + if (buf.length === 0) return cb(new Error(msgNoSuitablePoster)) cb(null, buf, '.jpg') }