-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbios-ver
executable file
·47 lines (34 loc) · 1.12 KB
/
bios-ver
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
46
47
#!/usr/bin/env node
const colors = require('colors');
const sanitizeHtml = require('sanitize-html');
const USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0';
const main = async () => {
if (!process.env.BIOS_PRODUCT) {
throw new Error('BIOS_PRODUCT not defined');
}
const BIOS_URL = `https://us.msi.com/api/v1/product/support/panel?type=bios&product=${process.env.BIOS_PRODUCT}`;
let res = await fetch(BIOS_URL, {
headers: {
'User-Agent': USER_AGENT
}
});
if (!res.ok) {
throw res.statusText;
}
let json = await res.json();
let latest = json.result.downloads['AMI BIOS'][0];
let description = sanitizeHtml(latest.download_description, {
allowedTags: []
});
description = description.split('\n').map(line => {
return line.replace(/^-\s*/, ' - ');
}).join('\n');
console.log(`
${colors.bold.blue('Date')} ${latest.download_release}
${colors.bold.blue('Version')} ${latest.download_version}
${colors.bold.blue('Download')} ${latest.download_url}
${colors.bold.blue('Description')}
${description}
`);
};
main().catch(console.error);