« get me outta code hell

downloaders.js - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/downloaders.js
blob: f5df4d22d936c19115efa57b035b0cf702b23a82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const removeFileProtocol = arg => {
  const fileProto = 'file://'
  if (arg.startsWith(fileProto)) {
    return decodeURIComponent(arg.slice(fileProto.length))
  } else {
    return arg
  }
}

const downloaders = {
  fetch: arg => {
    return fetch(arg)
      .then(response => response.blob())
      .then(blob => URL.createObjectURL(blob))
  },

  getDownloaderFor: arg => {
    if (arg.startsWith('http://') || arg.startsWith('https://')) {
      return downloaders.http
    } else {
      return null
    }
  }
}

module.exports = downloaders