generated from digshare-scripts/digshare-script-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.ts
59 lines (46 loc) · 1.23 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import {script} from '@digshare/script';
import {getCert} from './@cert';
const DAY_IN_MS = 24 * 3600 * 1000;
const EXPIRATION_WARN_THRESHOLD = 7 * DAY_IN_MS;
const COMMON_NAMES = ['dingshao.cn'];
export default script<{}>(async () => {
interface Problem {
emoji: string;
commonName: string;
description: string;
}
const problems: Problem[] = [];
const now = Date.now();
for (const commonName of COMMON_NAMES) {
const cert = await getCert(commonName);
if (cert) {
const duration = new Date(cert.valid_to).getTime() - now;
if (duration < EXPIRATION_WARN_THRESHOLD) {
problems.push({
emoji: '⚠️',
commonName,
description: `证书将在 ${Math.ceil(duration / DAY_IN_MS)} 天内到期`,
});
}
} else {
problems.push({
emoji: '❌',
commonName,
description: '无效的证书',
});
}
}
if (problems.length === 0) {
console.info('没有发现证书问题');
return;
}
return {
message: `\
发现了 ${problems.length} 个证书问题,请及时处理:
${problems
.map(
problem => `${problem.emoji} ${problem.commonName}\n${problem.description}`,
)
.join('\n\n')}`,
};
});