generated from digshare-scripts/digshare-script-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.ts
39 lines (33 loc) · 931 Bytes
/
script.ts
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
import {script} from '@digshare/script';
import fetch from 'node-fetch';
interface Payload {}
interface Storage {}
const robotFetch = (url: string) =>
fetch(url, {
headers: {
'User-Agent': 'Googlebot/2.1 (+http://www.google.com/bot.html)',
},
}).then(async res =>
res.status === 500 ? Promise.reject({url, html: await res.text()}) : true,
);
export default script<Payload, Storage>(async (payload, {storage}) => {
return Promise.all([
// site
robotFetch('https://www.dingshao.cn/'),
// channel
robotFetch('https://www.dingshao.cn/share/channel/ctGFCB'),
// message
robotFetch('https://www.dingshao.cn/share/message/pRiqbl'),
]).then(
() => {
console.log("It's OK ~");
},
({url, html}) => {
console.error({url, html});
return {
content: `它挂啦它挂啦,它带着 \`500\` 走来啦`,
links: [url],
};
},
);
});