-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcardDownload.js
29 lines (26 loc) · 906 Bytes
/
cardDownload.js
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
27
28
29
const axios = require('axios')
const bfj = require('bfj')
const downloadBulk = async () => {
const { data } = await axios.get('https://api.scryfall.com/bulk-data')
return data
}
const updateCards = async () => {
try {
const { data: response } = await downloadBulk()
const allCardsObject = response.find(f => f.name === 'All Cards')
const { data: file } = await axios.get(allCardsObject.download_uri, {
responseType: 'stream',
onDownloadProgress: progressEvent => {
const percent = (progressEvent.loaded * 100) / allCardsObject.size
console.log(`[${Array.from({ length: 20 }).map((_, i) => (i < percent / 5 ? '█' : '#')).join('')}] ${percent.toFixed(2)}% - ${progressEvent.rate / 1000}KB/s`)
}
})
const data = await bfj.parse(file)
console.log(data)
} catch (error) {
throw new Error(error)
}
}
module.exports = {
updateCards
}