diff options
-rw-r--r-- | crawlers.js | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/crawlers.js b/crawlers.js index 1db02fd..daf8221 100644 --- a/crawlers.js +++ b/crawlers.js @@ -231,7 +231,7 @@ function crawlLocal(dirPath, extensions = [ 'ogg', 'oga', 'wav', 'mp3', 'mp4', 'm4a', 'aac', 'mod' -]) { +], isTop = true) { // If the passed path is a file:// URL, try to decode it: try { const url = new URL(dirPath) @@ -252,7 +252,7 @@ function crawlLocal(dirPath, extensions = [ return stat(itemPath).then(stats => { if (stats.isDirectory()) { - return crawlLocal(itemPath, extensions) + return crawlLocal(itemPath, extensions, false) .then(group => Object.assign({name: item}, group)) } else if (stats.isFile()) { // Extname returns a string starting with a dot; we don't want the @@ -271,11 +271,23 @@ function crawlLocal(dirPath, extensions = [ return null } } - }) + }, statErr => null) })) }, err => { if (err.code === 'ENOENT') { - return [] + if (isTop) { + throw 'That directory path does not exist!' + } else { + return [] + } + } else if (err.code === 'EACCES') { + if (isTop) { + throw 'You do not have permission to open that directory.' + } else { + return [] + } + } else { + throw err } }).then(items => items.filter(Boolean)) .then(filteredItems => ({items: filteredItems})) @@ -319,7 +331,12 @@ async function crawlYouTube(url) { }) // Pass false so it doesn't show logging. - await promisifyProcess(ytdl, false) + try { + await promisifyProcess(ytdl, false) + } catch (error) { + // Yeow. + throw 'Youtube-dl failed.' + } return { items: items.map(item => { |