Skip to content

Commit e10e0e0

Browse files
Use fetch
1 parent 65f91de commit e10e0e0

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

lib/update.js

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,7 @@
1-
const https = require('https');
21
const path = require('path');
32
const fs = require('fs');
43
const { spawnSync } = require('child_process');
54

6-
https.get('https://api.github.com/repos/next-theme/hexo-theme-next/releases', {
7-
headers: {
8-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36'
9-
}
10-
}, res => {
11-
let data = '';
12-
res.on('data', chunk => {
13-
data += chunk;
14-
});
15-
res.on('end', () => {
16-
if (res.statusCode === 200) {
17-
data = JSON.parse(data);
18-
parse(data);
19-
}
20-
});
21-
}).on('error', err => {
22-
console.error('Failed to download release messages.');
23-
console.log(err);
24-
});
25-
265
function parse(data) {
276
data.sort((a, b) => {
287
return new Date(b.created_at) - new Date(a.created_at);
@@ -53,3 +32,11 @@ ${body}
5332
stdio: "inherit"
5433
});
5534
}
35+
36+
fetch('https://api.github.com/repos/next-theme/hexo-theme-next/releases', {
37+
headers: {
38+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36'
39+
}
40+
})
41+
.then(res => res.json())
42+
.then(parse);

0 commit comments

Comments
 (0)