frak icon indicating copy to clipboard operation
frak copied to clipboard

replace Got with Axios

Open vankasteelj opened this issue 2 years ago • 1 comments

In gulpfile to download mpv:

  return Promise.all(parsePlatforms().map((platform) => {
    // bundled mpv is for win only
    if (platform.match(/osx|linux/) !== null) {
      console.log('No `mpv` task for', platform)
      return null
    }

    return new Promise((resolve, reject) => {
      console.log('downloading mpv...')
      axios({
        url: pkJson.mpv.url,
        responseType: 'stream'
      }).then(response => {
        const stream = response.data
        stream.pipe(fs.createWriteStream(path.join(temp, 'mpv.7z')))
        stream.on('end', resolve)
      })
    }).then(() => {
      console.log('mpv downloaded, extracting...')
      return Z7.extractFull(path.join(temp, 'mpv.7z'), 'mpv')
    }).then(() => {
      console.log('mpv extracted')
      console.log('downloading youtube-dl...')
      return new Promise((resolve, reject) => {
        axios({
          url: pkJson.mpv['youtube-dl'],
          responseType: 'stream'
        }).then(response => {
          const stream = response.data
          stream.pipe(fs.createWriteStream('mpv/youtube-dl.exe'))
          stream.on('end', resolve)
        })
      })
    }).then(() => {
      console.log('all done.')
    })
  }))

in modules with cheerio:

axios.get(reqUrl, { timeout: 3500, responseType: 'text' }).then(res => {
    const $page = cheerio.load(res.data) ...

vankasteelj avatar Feb 18 '23 13:02 vankasteelj

The switch should be gradual with every step verifier. I would advise to add "axios" to the require() list then change one occurence in the main code, test it, then go on to the next one. And only remove 'got' when it is no longer used anywhere.

vankasteelj avatar Feb 18 '23 13:02 vankasteelj