From 84ad73f638fe0b03e173b8ffb545d8edb43acc3c Mon Sep 17 00:00:00 2001 From: Florrie Date: Tue, 26 Jun 2018 11:59:28 -0300 Subject: File:// support in crawl-local --- crawlers.js | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'crawlers.js') diff --git a/crawlers.js b/crawlers.js index 61f422b..82ef78e 100644 --- a/crawlers.js +++ b/crawlers.js @@ -190,6 +190,17 @@ function crawlLocal(dirPath, extensions = [ 'wav', 'mp3', 'mp4', 'm4a', 'aac', 'mod' ]) { + // If the passed path is a file:// URL, try to decode it: + try { + const url = new URL(dirPath) + if (url.protocol === 'file:') { + dirPath = decodeURIComponent(url.pathname) + } + } catch (error) { + // If it's not a URL, don't do anything special - it's (assumedly) an + // ordinary path ("/path/to/the directory"). + } + return readDir(dirPath).then(items => { items.sort(sortIgnoreCase(naturalSort())) -- cgit 1.3.0-6-gf8a5