biangbiang commited on
Commit
6986ced
·
verified ·
1 Parent(s): 549ec84

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +13 -0
  2. index.js +96 -0
  3. package.json +21 -0
Dockerfile ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM node:alpine
2
+
3
+ WORKDIR /app
4
+
5
+ COPY . .
6
+
7
+ EXPOSE 7860
8
+
9
+ RUN apk update && apk add --no-cache openssl curl &&\
10
+ chmod +x index.js &&\
11
+ npm install
12
+
13
+ CMD ["node", "index.js"]
index.js ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const axios = require('axios');
2
+ const moment = require('moment-timezone');
3
+ const http = require('http');
4
+ const cron = require('node-cron');
5
+ const port = process.env.PORT || 7860;
6
+
7
+ // 添加24小时是不间断访问的url数组
8
+ const webpages = [
9
+ // ... 添加更多url
10
+ ];
11
+
12
+ // 添加1:00-6:00暂停,其他时间正常访问的url数组
13
+ const urls = [
14
+ 'https://biangbiang-uptime-kuma.hf.space', //uptime-kuma
15
+ 'https://biangbiang-keep-alive.hf.space', //keep-alive
16
+ 'https://shisb-pan.hf.space', //pan
17
+ 'https://shisb-bai.hf.space', //bingai
18
+ 'https://shisb-lobechat.hf.space', //lobechat
19
+ 'https://shisb-duck2.hf.space/hf', //duck2api
20
+ 'https://biangbiang-newapi.hf.space', //newapi
21
+ 'https://shisb-reader.hf.space', //reader
22
+ 'https://biangbiang-duck2api.hf.space' //duck2api
23
+ // ... 添加更多url
24
+ ];
25
+
26
+ // 遍历网页数组并发请求访问网页
27
+ const visit = async (url) => {
28
+ try {
29
+ const response = await axios.get(url);
30
+ console.log(`${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')} Visited web successfully: ${url} --- Status: ${response.status}\n`);
31
+ } catch (error) {
32
+ console.error(`Failed to visit ${url}: ${error.message}\n`);
33
+ }
34
+ };
35
+ const visitAll = async () => {
36
+ for (let url of urls) {
37
+ await visit(url);
38
+ }
39
+ };
40
+
41
+ // 定判断是否在访问时间段内
42
+ const isWithinTime = () => {
43
+ const now = moment().tz('Asia/Hong_Kong');
44
+ const hour = now.hour();
45
+ if (hour >= 1 && hour < 6) {
46
+ return false;
47
+ }
48
+ return true;
49
+ };
50
+
51
+ // 创建http服务
52
+ const createServer = () => {
53
+ const server = http.createServer((req, res) => {
54
+ if (req.url === '/') {
55
+ res.writeHead(200, {'Content-Type': 'text/plain'});
56
+ res.end('Hello world!');
57
+ } else {
58
+ res.writeHead(404, {'Content-Type': 'text/plain'});
59
+ res.end('404 Not Found');
60
+ }
61
+ });
62
+ server.listen(port, () => {
63
+ console.log(`Server started on port ${port}`);
64
+ });
65
+ };
66
+
67
+ // 执行访问逻辑
68
+ const main = async () => {
69
+ createServer();
70
+ setInterval(async () => {
71
+ if (isWithinTime()) {
72
+ await visitAll();
73
+ } else {
74
+ console.log(`Stop visiting at ${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')}`);
75
+ }
76
+ }, 2 * 60 * 1000); // 指定时间段访问的间隔2分钟
77
+ };
78
+ main();
79
+
80
+ //24小时不间断访问部分
81
+ async function access(url) {
82
+ try {
83
+ const response = await axios.get(url);
84
+ console.log(`${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')} Web visited successfully: ${url} --- status:${response.status}`);
85
+ } catch (error) {
86
+ console.error(`${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')} Failed to visit ${url}, Error ${error.message}`);
87
+ }
88
+ }
89
+
90
+ async function batchVisit() {
91
+
92
+ for (let url of webpages) {
93
+ await access(url);
94
+ }
95
+ }
96
+ cron.schedule('*/2 * * * *', batchVisit); // 24小时访问任务间隔周期,默认2分钟
package.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "keep-alive",
3
+ "version": "1.0.0",
4
+ "description": "keep-web-alive",
5
+ "main": "index.js",
6
+ "author": "eoovve",
7
+ "repository": "",
8
+ "license": "MIT",
9
+ "private": false,
10
+ "scripts": {
11
+ "start": "node index.js"
12
+ },
13
+ "dependencies": {
14
+ "axios": "^1.6.2",
15
+ "node-cron": "^2.0.1",
16
+ "moment-timezone": "latest"
17
+ },
18
+ "engines": {
19
+ "node": ">=14"
20
+ }
21
+ }