-
Notifications
You must be signed in to change notification settings - Fork 9
/
checkLogos.js
45 lines (40 loc) · 1.3 KB
/
checkLogos.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const fs = require('fs');
const axios = require('axios').default;
const { glob } = require('glob');
const checkUrls = async () => {
let ret = 0;
return glob("{*/cw20/contracts.json,*/cw721/contracts.json,*/native/tokens.json}").then(async (files) => {
for (const file of files) {
const content = fs.readFileSync(file);
const json = JSON.parse(content);
const logos = new Set();
Object.values(json).forEach(item => {
if (item.logo && item.logo !== "") {
logos.add(item.logo);
}
});
for (const logoUrl of logos) {
try {
const response = await axios.get(logoUrl, { responseType: 'stream', timeout: 10000 });
const contentType = response.headers['content-type'];
if (response.status < 400 && (contentType.startsWith('image/'))) {
console.log(`${file} - ${logoUrl}: OK`);
} else {
console.error(`${file} - ${logoUrl}: FAIL (Not an image)`);
ret = 1;
}
} catch (error) {
console.error(`${file} - ${logoUrl}: FAIL (Request failed)`);
ret = 1;
}
}
}
process.exit(0); // do not prevent deployment
}).catch((e) => {
console.log('Error', e);
process.exit(1);
});
};
checkUrls().then(
console.log('done')
);