-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdateLinks.js
38 lines (30 loc) · 1.03 KB
/
updateLinks.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
import fetch from "node-fetch"
import { createRequire } from "module";
const require = createRequire(import.meta.url);
let data = require("./src/info.json")
const fs = require('fs');
const main = async () => {
const USERNAME = process.env.BUILD_LINKS_USERNAME;
const PASSWORD = process.env.BUILD_LINKS_PASSWORD
const URL = process.env.BUILD_LINKS_URL
try {
const re = await fetch(URL, {
method: "GET", headers: {
'Authorization': 'Basic ' + Buffer.from(`${USERNAME}:${PASSWORD}`, 'binary').toString('base64')
}
})
const links = await re.json()
data.links = links;
await fs.promises.writeFile('./src/data.json', JSON.stringify(data), 'utf-8')
console.log(`Updated data.json - inserted ${links.length} URLS`)
} catch (err) {
if (err.code === 'ERR_INVALID_URL') {
console.log("ERR_INVALID_URL");
process.exit(0)
}
console.log(err)
process.exit(0)
}
process.exit(0)
}
main();