-
-
Save studiotomi/6c1d19b85137c204bf7ad0052d5b8cc1 to your computer and use it in GitHub Desktop.
Write 404 images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require('axios'); | |
const fs = require('fs'); | |
const headers = { 'x-vol-tenant': '5c49cda1ddca5800122fad4e' }; | |
const materialApi = 'https://api.material.com/images'; | |
const getImages = async (url, headers) => { | |
if (!fs.existsSync('404s.txt')) { | |
fs.writeFileSync('404s.txt', ''); | |
} | |
const params = { | |
pageSize: 100, | |
startIndex: 0, | |
}; | |
let counter = 0; | |
try { | |
fs.open('404s.txt', 'a', async (err, fd) => { | |
if (err) throw err; | |
let response; | |
do { | |
response = await axios.get(url, { headers, params }); | |
const {data} = response; | |
data.map(async image => { | |
axios | |
.head(image.fullUri) | |
.then(res => { | |
console.log(`${image.id} ${res.statusText}`); | |
}) | |
.catch(error => { | |
fs.appendFile(fd, `${image.id}\n`, err => { }); | |
console.log(`${image.id} returned 404`); | |
}); | |
}); | |
params.startIndex = (++counter) * params.pageSize; | |
} while (response.data.length > 0); | |
}); | |
} catch (error) { console.log(error) } | |
}; | |
getImages(materialApi, headers); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment