XxxX
Browse files- Dockerfile +22 -0
- README.md +3 -5
- app.js +73 -0
- package.json +6 -0
Dockerfile
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 使用Node.js基础镜像
|
2 |
+
FROM node:alpine
|
3 |
+
|
4 |
+
# 设置大陆时区
|
5 |
+
ENV TZ Asia/Shanghai
|
6 |
+
|
7 |
+
# 设置工作目录
|
8 |
+
WORKDIR /XxxX
|
9 |
+
|
10 |
+
# 安装主程序
|
11 |
+
COPY . .
|
12 |
+
|
13 |
+
# 安装依赖
|
14 |
+
RUN npm install -g pnpm
|
15 |
+
RUN pnpm install
|
16 |
+
|
17 |
+
# 赋予权限/归递
|
18 |
+
RUN chmod -R 777 /tmp
|
19 |
+
RUN chmod -R 777 /XxxX
|
20 |
+
|
21 |
+
# 启动!
|
22 |
+
CMD ["node", "app.js"]
|
README.md
CHANGED
@@ -1,10 +1,8 @@
|
|
1 |
---
|
2 |
title: RBD
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
---
|
9 |
-
|
10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
title: RBD
|
3 |
+
emoji: 💻
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: pink
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
---
|
|
|
|
app.js
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const express = require('express');
|
2 |
+
const axios = require('axios');
|
3 |
+
|
4 |
+
const app = express();
|
5 |
+
const port = 7860;
|
6 |
+
|
7 |
+
const sites = [
|
8 |
+
{ name: 'X1', url: 'https://QSignX-X1.hf.space' },
|
9 |
+
{ name: 'X2', url: 'https://QSignX-X2.hf.space' },
|
10 |
+
{ name: 'X3', url: 'https://QSignX-X3.hf.space' },
|
11 |
+
{ name: 'X4', url: 'https://QSignX-X4.hf.space' },
|
12 |
+
{ name: 'X5', url: 'https://QSignX-X5.hf.space' }
|
13 |
+
];
|
14 |
+
|
15 |
+
const timeout = 30000; // 访问超时
|
16 |
+
|
17 |
+
// 使用中间件,接收所有请求
|
18 |
+
app.use((req, res, next) => {
|
19 |
+
const userIP = req.ip;
|
20 |
+
const currentDate = new Date().toLocaleString('zh-CN', { hour12: false });
|
21 |
+
//console.log(`[${currentDate}] 收到来自 IP ${userIP} 的请求`);
|
22 |
+
res.locals.userIP = userIP; // 将 userIP 存储在 res.locals 中,以便在后续中间件和路由中使用
|
23 |
+
next();
|
24 |
+
});
|
25 |
+
|
26 |
+
app.get('/', (req, res) => {
|
27 |
+
const userIP = res.locals.userIP; // 从 res.locals 中获取 userIP
|
28 |
+
const currentDate = new Date().toLocaleString('zh-CN', { hour12: false });
|
29 |
+
// 并发请求
|
30 |
+
const requests = sites.map(site =>
|
31 |
+
axios.get(site.url, { timeout })
|
32 |
+
.then(response => ({ name: site.name, status: response.status, url: site.url }))
|
33 |
+
.catch(error => {
|
34 |
+
if (error.code === 'ECONNABORTED') {
|
35 |
+
return { name: site.name, error: '请求超时', url: site.url };
|
36 |
+
} else {
|
37 |
+
return { name: site.name, error: error.message, url: site.url };
|
38 |
+
}
|
39 |
+
})
|
40 |
+
);
|
41 |
+
|
42 |
+
Promise.all(requests)
|
43 |
+
.then(results => {
|
44 |
+
const availableSites = results.filter(result => result.status === 200);
|
45 |
+
|
46 |
+
if (availableSites.length > 0) {
|
47 |
+
// 从可用地址中随机选择一个
|
48 |
+
const randomIndex = Math.floor(Math.random() * availableSites.length);
|
49 |
+
const randomSite = availableSites[randomIndex];
|
50 |
+
console.log(`[${currentDate}] ${userIP} → ${randomSite.url}`);
|
51 |
+
res.redirect(302, randomSite.url); // 使用 302 作为临时重定向状态码
|
52 |
+
} else {
|
53 |
+
console.log(`[${currentDate}] ${userIP} 没有可用的地址`);
|
54 |
+
res.json({ message: '少女为主人痛哭...' });
|
55 |
+
}
|
56 |
+
})
|
57 |
+
.catch(err => {
|
58 |
+
console.error(`[${currentDate}] ${userIP} 请求时出错: ${err.message}`);
|
59 |
+
res.status(500).json({ error: `发生错误: ${err.message}` });
|
60 |
+
});
|
61 |
+
});
|
62 |
+
|
63 |
+
app.use((req, res) => {
|
64 |
+
const userIP = res.locals.userIP; // 从 res.locals 中获取 userIP
|
65 |
+
const requestedRoute = req.originalUrl;
|
66 |
+
const currentDate = new Date().toLocaleString('zh-CN', { hour12: false });
|
67 |
+
console.log(`[${currentDate}] ${userIP} 错误路由 ${requestedRoute}`);
|
68 |
+
res.status(404).json({ error: '少女做不到...' });
|
69 |
+
});
|
70 |
+
|
71 |
+
app.listen(port, '0.0.0.0', () => {
|
72 |
+
console.log(`少女为您祈福 0.0.0.0:${port}`);
|
73 |
+
});
|
package.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"dependencies": {
|
3 |
+
"axios": "*",
|
4 |
+
"express": "*"
|
5 |
+
}
|
6 |
+
}
|