/ src / server / cache.js
cache.js
 1  const fs = require('fs')
 2  const log = require('loglevel')
 3  const path = require('path')
 4  const axios = require('axios')
 5  
 6  const OUTPUT_PATH = '/tmp'
 7  
 8  class Url {
 9    constructor(url) {
10      this.url = url
11    }
12  
13    async save() {
14      const filename = this.url.split('/').pop()
15      this.path = path.join(OUTPUT_PATH, filename)
16      const writer = fs.createWriteStream(this.path)
17      const resp = await axios.get(this.url)
18      resp.data.pipe(writer)
19    }
20  }
21  module.exports = Url