#1426 Consistent error message if no suitable poster image could be found.
This commit is contained in:
@@ -5,6 +5,8 @@ const path = require('path')
|
|||||||
|
|
||||||
const mediaExtensions = require('./media-extensions')
|
const mediaExtensions = require('./media-extensions')
|
||||||
|
|
||||||
|
const msgNoSuitablePoster = 'Cannot generate a poster from any files in the torrent'
|
||||||
|
|
||||||
function torrentPoster (torrent, cb) {
|
function torrentPoster (torrent, cb) {
|
||||||
// First, try to use a poster image if available
|
// First, try to use a poster image if available
|
||||||
const posterFile = torrent.files.filter(function (file) {
|
const posterFile = torrent.files.filter(function (file) {
|
||||||
@@ -23,7 +25,7 @@ function torrentPoster (torrent, cb) {
|
|||||||
|
|
||||||
if (bestScore.size === 0) {
|
if (bestScore.size === 0) {
|
||||||
// Admit defeat, no video, audio or image had a significant presence
|
// 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
|
// Based on which media type is dominant we select the corresponding poster function
|
||||||
@@ -110,7 +112,7 @@ function scoreAudioCoverFile (imgFile) {
|
|||||||
function torrentPosterFromAudio (torrent, cb) {
|
function torrentPosterFromAudio (torrent, cb) {
|
||||||
const imageFiles = filterOnExtension(torrent, mediaExtensions.image)
|
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 => {
|
const bestCover = imageFiles.map(file => {
|
||||||
return {
|
return {
|
||||||
@@ -172,7 +174,7 @@ function torrentPosterFromVideo (torrent, cb) {
|
|||||||
|
|
||||||
server.destroy()
|
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')
|
cb(null, buf, '.jpg')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user