« get me outta code hell

Update makeLocalDownloader to support 'file://' strings - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLiam <towerofnix@gmail.com>2017-07-15 18:21:42 -0400
committerLiam <towerofnix@gmail.com>2017-07-15 18:21:42 -0400
commit862d1d02da322ab620d2b741b66f904859209c1f (patch)
treed62ebea901676f7d9c7cd9062cfb479af2d6f5d1
parent6b6840973c120896c2d4f40bd29b1ac86f5973f6 (diff)
Update makeLocalDownloader to support 'file://' strings
-rw-r--r--src/downloaders.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/downloaders.js b/src/downloaders.js
index bc9cf15..c0e54eb 100644
--- a/src/downloaders.js
+++ b/src/downloaders.js
@@ -58,10 +58,17 @@ function makeLocalDownloader() {
   // platform way).
 
   return function(arg) {
+    // It's possible the downloader argument start with the "file://" protocol
+    // string; in that case we'll want to snip it off and URL-decode the
+    // string.
+    const fileProto = 'file://'
+    if (arg.startsWith(fileProto)) {
+      arg = decodeURIComponent(arg.slice(fileProto.length))
+    }
+
     const dir = tempy.directory()
     // TODO: Is it necessary to sanitize here?
-    // haha, the answer to "should I sanitize" is probably always
-    // YES..
+    // Haha, the answer to "should I sanitize" is probably always YES..
     const base = path.basename(arg, path.extname(arg))
     const file = dir + '/' + sanitize(base) + '.mp3'
     return copyFile(arg, file)