Spaces:
Paused
Paused
Upload 11 files
Browse files- Dockerfile +4 -3
- README.md +213 -213
- entrypoint.sh +2 -0
Dockerfile
CHANGED
|
@@ -22,8 +22,9 @@ RUN apk add --no-cache \
|
|
| 22 |
# 设置时区为亚洲/上海
|
| 23 |
ENV TZ=Asia/Shanghai
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
RUN mkdir -p ./clash_core ./subconverter ./data
|
|
|
|
| 27 |
|
| 28 |
# 下载并安装Clash Meta
|
| 29 |
RUN echo "Downloading Clash Meta..." && \
|
|
@@ -89,7 +90,7 @@ COPY entrypoint.sh ./
|
|
| 89 |
RUN chmod +x ./entrypoint.sh
|
| 90 |
|
| 91 |
# 暴露单一端口 (Hugging Face Spaces要求)
|
| 92 |
-
EXPOSE
|
| 93 |
|
| 94 |
# 使用entrypoint脚本启动应用
|
| 95 |
ENTRYPOINT ["/app/entrypoint.sh"]
|
|
|
|
| 22 |
# 设置时区为亚洲/上海
|
| 23 |
ENV TZ=Asia/Shanghai
|
| 24 |
|
| 25 |
+
# 创建必要的目录并设置权限
|
| 26 |
+
RUN mkdir -p ./clash_core ./subconverter ./data && \
|
| 27 |
+
chmod -R 777 ./data
|
| 28 |
|
| 29 |
# 下载并安装Clash Meta
|
| 30 |
RUN echo "Downloading Clash Meta..." && \
|
|
|
|
| 90 |
RUN chmod +x ./entrypoint.sh
|
| 91 |
|
| 92 |
# 暴露单一端口 (Hugging Face Spaces要求)
|
| 93 |
+
EXPOSE 8000
|
| 94 |
|
| 95 |
# 使用entrypoint脚本启动应用
|
| 96 |
ENTRYPOINT ["/app/entrypoint.sh"]
|
README.md
CHANGED
|
@@ -1,214 +1,214 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: Simple Clash Relay
|
| 3 |
-
emoji: 🚀
|
| 4 |
-
colorFrom: blue
|
| 5 |
-
colorTo: indigo
|
| 6 |
-
sdk: docker
|
| 7 |
-
app_port:
|
| 8 |
-
pinned: false
|
| 9 |
-
---
|
| 10 |
-
|
| 11 |
-
# Simple Clash Relay
|
| 12 |
-
|
| 13 |
-
一个轻量级的自建Clash代理服务,可通过API控制节点切换。
|
| 14 |
-
|
| 15 |
-
## 功能特点
|
| 16 |
-
|
| 17 |
-
- 🚀 **轻量级**:基于Python Flask和Clash Core,最小化依赖
|
| 18 |
-
- 🔄 **机场订阅支持**:自动下载并转换您的机场订阅链接
|
| 19 |
-
- 🔌 **单端口模式**:通过路径区分API和代理流量,适合Hugging Face部署
|
| 20 |
-
- 🔒 **API认证**:通过API Key保护控制API
|
| 21 |
-
- 🔄 **动态切换节点**:通过API随时切换使用的节点
|
| 22 |
-
- 🐳 **容器化**:完整的Docker支持,便于部署
|
| 23 |
-
- 🔥 **Hugging Face友好**:针对Hugging Face Spaces平台优化
|
| 24 |
-
|
| 25 |
-
## 系统要求
|
| 26 |
-
|
| 27 |
-
- Docker (本地开发/部署)
|
| 28 |
-
- 或 Python 3.8+ (本地开发)
|
| 29 |
-
- 机场订阅链接
|
| 30 |
-
- Hugging Face账户 (云部署)
|
| 31 |
-
|
| 32 |
-
## 项目结构
|
| 33 |
-
|
| 34 |
-
```
|
| 35 |
-
simple-clash-relay/
|
| 36 |
-
├── app/ # Flask应用代码
|
| 37 |
-
│ ├── __init__.py
|
| 38 |
-
│ ├── main.py # API路由和应用入口
|
| 39 |
-
│ ├── clash_manager.py # Clash Core管理
|
| 40 |
-
│ ├── sub_manager.py # 订阅管理
|
| 41 |
-
│ └── auth.py # API认证
|
| 42 |
-
├── clash_core/ # Clash Core可执行文件
|
| 43 |
-
├── subconverter/ # subconverter可执行文件
|
| 44 |
-
├── data/ # 运行时数据
|
| 45 |
-
├── Dockerfile # Docker构建文件
|
| 46 |
-
├── entrypoint.sh # 容器启动脚本
|
| 47 |
-
├── requirements.txt # Python依赖
|
| 48 |
-
└── .env.example # 环境变量模板
|
| 49 |
-
```
|
| 50 |
-
|
| 51 |
-
## 快速开始
|
| 52 |
-
|
| 53 |
-
### 准备工作
|
| 54 |
-
|
| 55 |
-
1. 获取可执行文件:
|
| 56 |
-
- 下载Clash Core: [github.com/Dreamacro/clash/releases](https://github.com/Dreamacro/clash/releases)
|
| 57 |
-
- 下载subconverter: [github.com/tindy2013/subconverter/releases](https://github.com/tindy2013/subconverter/releases)
|
| 58 |
-
|
| 59 |
-
2. 将上述文件放入对应目录:
|
| 60 |
-
- `clash-linux-amd64` → `clash_core/`目录
|
| 61 |
-
- `subconverter` → `subconverter/`目录
|
| 62 |
-
|
| 63 |
-
### 本地开发
|
| 64 |
-
|
| 65 |
-
1. 安装依赖:
|
| 66 |
-
```
|
| 67 |
-
pip install -r requirements.txt
|
| 68 |
-
```
|
| 69 |
-
|
| 70 |
-
2. 设置环境变量:
|
| 71 |
-
```
|
| 72 |
-
cp .env.example .env
|
| 73 |
-
# 编辑.env文件,设置SUB_URL和API_KEY
|
| 74 |
-
```
|
| 75 |
-
|
| 76 |
-
3. 启动应用:
|
| 77 |
-
```
|
| 78 |
-
python -m app.main
|
| 79 |
-
```
|
| 80 |
-
|
| 81 |
-
### Docker部署
|
| 82 |
-
|
| 83 |
-
1. 构建Docker镜像:
|
| 84 |
-
```
|
| 85 |
-
docker build -t simple-clash-relay .
|
| 86 |
-
```
|
| 87 |
-
|
| 88 |
-
2. 运行容器:
|
| 89 |
-
```
|
| 90 |
-
docker run -d \
|
| 91 |
-
-p 7860:7860 \
|
| 92 |
-
-e SUB_URL=你的订阅链接 \
|
| 93 |
-
-e API_KEY=你的API密钥 \
|
| 94 |
-
--name clash-relay \
|
| 95 |
-
simple-clash-relay
|
| 96 |
-
```
|
| 97 |
-
|
| 98 |
-
### Hugging Face Spaces部署
|
| 99 |
-
|
| 100 |
-
1. 在Hugging Face上创建Space:
|
| 101 |
-
- 访问 [huggingface.co/spaces](https://huggingface.co/spaces)
|
| 102 |
-
- 点击"Create new Space"
|
| 103 |
-
- 选择"Docker"作为Space SDK
|
| 104 |
-
- 填写名称和其他设置
|
| 105 |
-
|
| 106 |
-
2. 克隆Space仓库:
|
| 107 |
-
```
|
| 108 |
-
git clone https://huggingface.co/spaces/你的用户名/你的Space名称
|
| 109 |
-
cd 你的Space名称
|
| 110 |
-
```
|
| 111 |
-
|
| 112 |
-
3. 复制项目文件:
|
| 113 |
-
```
|
| 114 |
-
# 将所有项目文件复制到此目录
|
| 115 |
-
```
|
| 116 |
-
|
| 117 |
-
4. 提交和推送:
|
| 118 |
-
```
|
| 119 |
-
git add .
|
| 120 |
-
git commit -m "Initial commit"
|
| 121 |
-
git push
|
| 122 |
-
```
|
| 123 |
-
|
| 124 |
-
5. 设置Secrets:
|
| 125 |
-
- 在Hugging Face Space设置页面添加以下secrets:
|
| 126 |
-
- `SUB_URL`: 你的订阅链接
|
| 127 |
-
- `API_KEY`: 你的API密钥
|
| 128 |
-
|
| 129 |
-
## API使用
|
| 130 |
-
|
| 131 |
-
所有API请求需要在请求头中包含`X-API-Key: 你的API密钥`。
|
| 132 |
-
|
| 133 |
-
### 获取节点列表
|
| 134 |
-
|
| 135 |
-
```
|
| 136 |
-
GET /api/nodes
|
| 137 |
-
```
|
| 138 |
-
|
| 139 |
-
响应:
|
| 140 |
-
```json
|
| 141 |
-
{
|
| 142 |
-
"success": true,
|
| 143 |
-
"nodes": ["节点A", "节点B", "节点C"]
|
| 144 |
-
}
|
| 145 |
-
```
|
| 146 |
-
|
| 147 |
-
### 切换节点
|
| 148 |
-
|
| 149 |
-
```
|
| 150 |
-
PUT /api/switch
|
| 151 |
-
Content-Type: application/json
|
| 152 |
-
|
| 153 |
-
{
|
| 154 |
-
"node": "节点B"
|
| 155 |
-
}
|
| 156 |
-
```
|
| 157 |
-
|
| 158 |
-
响应:
|
| 159 |
-
```json
|
| 160 |
-
{
|
| 161 |
-
"success": true,
|
| 162 |
-
"message": "已切换到节点: 节点B"
|
| 163 |
-
}
|
| 164 |
-
```
|
| 165 |
-
|
| 166 |
-
### 获取当前节点
|
| 167 |
-
|
| 168 |
-
```
|
| 169 |
-
GET /api/current
|
| 170 |
-
```
|
| 171 |
-
|
| 172 |
-
响应:
|
| 173 |
-
```json
|
| 174 |
-
{
|
| 175 |
-
"success": true,
|
| 176 |
-
"current_node": "节点B"
|
| 177 |
-
}
|
| 178 |
-
```
|
| 179 |
-
|
| 180 |
-
### 刷新订阅
|
| 181 |
-
|
| 182 |
-
```
|
| 183 |
-
POST /api/refresh
|
| 184 |
-
```
|
| 185 |
-
|
| 186 |
-
响应:
|
| 187 |
-
```json
|
| 188 |
-
{
|
| 189 |
-
"success": true,
|
| 190 |
-
"message": "订阅已刷新,Clash已重启"
|
| 191 |
-
}
|
| 192 |
-
```
|
| 193 |
-
|
| 194 |
-
## 在应用中使用代理
|
| 195 |
-
|
| 196 |
-
由于使用单端口模式,您的应用需要使用以下代理配置:
|
| 197 |
-
|
| 198 |
-
- HTTP代理: `http://your-space-name.hf.space/proxy`
|
| 199 |
-
- SOCKS5代理: `socks5://your-space-name.hf.space/proxy`
|
| 200 |
-
|
| 201 |
-
### 在cursor-to-openai项目中配置
|
| 202 |
-
|
| 203 |
-
修改您的cursor-to-openai项目配置,设置代理地址为`http://your-space-name.hf.space/proxy`。
|
| 204 |
-
|
| 205 |
-
## 注意事项
|
| 206 |
-
|
| 207 |
-
- 本项目仅用于个人学习和研究目的
|
| 208 |
-
- 请遵守当地法律法规,不要用于非法用途
|
| 209 |
-
- 确保设置强密码API Key以保护接口
|
| 210 |
-
- Hugging Face Spaces有资源和流量限制,请合理使用
|
| 211 |
-
|
| 212 |
-
## 许可
|
| 213 |
-
|
| 214 |
MIT
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Simple Clash Relay
|
| 3 |
+
emoji: 🚀
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
pinned: false
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# Simple Clash Relay
|
| 12 |
+
|
| 13 |
+
一个轻量级的自建Clash代理服务,可通过API控制节点切换。
|
| 14 |
+
|
| 15 |
+
## 功能特点
|
| 16 |
+
|
| 17 |
+
- 🚀 **轻量级**:基于Python Flask和Clash Core,最小化依赖
|
| 18 |
+
- 🔄 **机场订阅支持**:自动下载并转换您的机场订阅链接
|
| 19 |
+
- 🔌 **单端口模式**:通过路径区分API和代理流量,适合Hugging Face部署
|
| 20 |
+
- 🔒 **API认证**:通过API Key保护控制API
|
| 21 |
+
- 🔄 **动态切换节点**:通过API随时切换使用的节点
|
| 22 |
+
- 🐳 **容器化**:完整的Docker支持,便于部署
|
| 23 |
+
- 🔥 **Hugging Face友好**:针对Hugging Face Spaces平台优化
|
| 24 |
+
|
| 25 |
+
## 系统要求
|
| 26 |
+
|
| 27 |
+
- Docker (本地开发/部署)
|
| 28 |
+
- 或 Python 3.8+ (本地开发)
|
| 29 |
+
- 机场订阅链接
|
| 30 |
+
- Hugging Face账户 (云部署)
|
| 31 |
+
|
| 32 |
+
## 项目结构
|
| 33 |
+
|
| 34 |
+
```
|
| 35 |
+
simple-clash-relay/
|
| 36 |
+
├── app/ # Flask应用代码
|
| 37 |
+
│ ├── __init__.py
|
| 38 |
+
│ ├── main.py # API路由和应用入口
|
| 39 |
+
│ ├── clash_manager.py # Clash Core管理
|
| 40 |
+
│ ├── sub_manager.py # 订阅管理
|
| 41 |
+
│ └── auth.py # API认证
|
| 42 |
+
├── clash_core/ # Clash Core可执行文件
|
| 43 |
+
├── subconverter/ # subconverter可执行文件
|
| 44 |
+
├── data/ # 运行时数据
|
| 45 |
+
├── Dockerfile # Docker构建文件
|
| 46 |
+
├── entrypoint.sh # 容器启动脚本
|
| 47 |
+
├── requirements.txt # Python依赖
|
| 48 |
+
└── .env.example # 环境变量模板
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
## 快速开始
|
| 52 |
+
|
| 53 |
+
### 准备工作
|
| 54 |
+
|
| 55 |
+
1. 获取可执行文件:
|
| 56 |
+
- 下载Clash Core: [github.com/Dreamacro/clash/releases](https://github.com/Dreamacro/clash/releases)
|
| 57 |
+
- 下载subconverter: [github.com/tindy2013/subconverter/releases](https://github.com/tindy2013/subconverter/releases)
|
| 58 |
+
|
| 59 |
+
2. 将上述文件放入对应目录:
|
| 60 |
+
- `clash-linux-amd64` → `clash_core/`目录
|
| 61 |
+
- `subconverter` → `subconverter/`目录
|
| 62 |
+
|
| 63 |
+
### 本地开发
|
| 64 |
+
|
| 65 |
+
1. 安装依赖:
|
| 66 |
+
```
|
| 67 |
+
pip install -r requirements.txt
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
2. 设置环境变量:
|
| 71 |
+
```
|
| 72 |
+
cp .env.example .env
|
| 73 |
+
# 编辑.env文件,设置SUB_URL和API_KEY
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
3. 启动应用:
|
| 77 |
+
```
|
| 78 |
+
python -m app.main
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
### Docker部署
|
| 82 |
+
|
| 83 |
+
1. 构建Docker镜像:
|
| 84 |
+
```
|
| 85 |
+
docker build -t simple-clash-relay .
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
2. 运行容器:
|
| 89 |
+
```
|
| 90 |
+
docker run -d \
|
| 91 |
+
-p 7860:7860 \
|
| 92 |
+
-e SUB_URL=你的订阅链接 \
|
| 93 |
+
-e API_KEY=你的API密钥 \
|
| 94 |
+
--name clash-relay \
|
| 95 |
+
simple-clash-relay
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
### Hugging Face Spaces部署
|
| 99 |
+
|
| 100 |
+
1. 在Hugging Face上创建Space:
|
| 101 |
+
- 访问 [huggingface.co/spaces](https://huggingface.co/spaces)
|
| 102 |
+
- 点击"Create new Space"
|
| 103 |
+
- 选择"Docker"作为Space SDK
|
| 104 |
+
- 填写名称和其他设置
|
| 105 |
+
|
| 106 |
+
2. 克隆Space仓库:
|
| 107 |
+
```
|
| 108 |
+
git clone https://huggingface.co/spaces/你的用户名/你的Space名称
|
| 109 |
+
cd 你的Space名称
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
3. 复制项目文件:
|
| 113 |
+
```
|
| 114 |
+
# 将所有项目文件复制到此目录
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
4. 提交和推送:
|
| 118 |
+
```
|
| 119 |
+
git add .
|
| 120 |
+
git commit -m "Initial commit"
|
| 121 |
+
git push
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
5. 设置Secrets:
|
| 125 |
+
- 在Hugging Face Space设置页面添加以下secrets:
|
| 126 |
+
- `SUB_URL`: 你的订阅链接
|
| 127 |
+
- `API_KEY`: 你的API密钥
|
| 128 |
+
|
| 129 |
+
## API使用
|
| 130 |
+
|
| 131 |
+
所有API请求需要在请求头中包含`X-API-Key: 你的API密钥`。
|
| 132 |
+
|
| 133 |
+
### 获取节点列表
|
| 134 |
+
|
| 135 |
+
```
|
| 136 |
+
GET /api/nodes
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
响应:
|
| 140 |
+
```json
|
| 141 |
+
{
|
| 142 |
+
"success": true,
|
| 143 |
+
"nodes": ["节点A", "节点B", "节点C"]
|
| 144 |
+
}
|
| 145 |
+
```
|
| 146 |
+
|
| 147 |
+
### 切换节点
|
| 148 |
+
|
| 149 |
+
```
|
| 150 |
+
PUT /api/switch
|
| 151 |
+
Content-Type: application/json
|
| 152 |
+
|
| 153 |
+
{
|
| 154 |
+
"node": "节点B"
|
| 155 |
+
}
|
| 156 |
+
```
|
| 157 |
+
|
| 158 |
+
响应:
|
| 159 |
+
```json
|
| 160 |
+
{
|
| 161 |
+
"success": true,
|
| 162 |
+
"message": "已切换到节点: 节点B"
|
| 163 |
+
}
|
| 164 |
+
```
|
| 165 |
+
|
| 166 |
+
### 获取当前节点
|
| 167 |
+
|
| 168 |
+
```
|
| 169 |
+
GET /api/current
|
| 170 |
+
```
|
| 171 |
+
|
| 172 |
+
响应:
|
| 173 |
+
```json
|
| 174 |
+
{
|
| 175 |
+
"success": true,
|
| 176 |
+
"current_node": "节点B"
|
| 177 |
+
}
|
| 178 |
+
```
|
| 179 |
+
|
| 180 |
+
### 刷新订阅
|
| 181 |
+
|
| 182 |
+
```
|
| 183 |
+
POST /api/refresh
|
| 184 |
+
```
|
| 185 |
+
|
| 186 |
+
响应:
|
| 187 |
+
```json
|
| 188 |
+
{
|
| 189 |
+
"success": true,
|
| 190 |
+
"message": "订阅已刷新,Clash已重启"
|
| 191 |
+
}
|
| 192 |
+
```
|
| 193 |
+
|
| 194 |
+
## 在应用中使用代理
|
| 195 |
+
|
| 196 |
+
由于使用单端口模式,您的应用需要使用以下代理配置:
|
| 197 |
+
|
| 198 |
+
- HTTP代理: `http://your-space-name.hf.space/proxy`
|
| 199 |
+
- SOCKS5代理: `socks5://your-space-name.hf.space/proxy`
|
| 200 |
+
|
| 201 |
+
### 在cursor-to-openai项目中配置
|
| 202 |
+
|
| 203 |
+
修改您的cursor-to-openai项目配置,设置代理地址为`http://your-space-name.hf.space/proxy`。
|
| 204 |
+
|
| 205 |
+
## 注意事项
|
| 206 |
+
|
| 207 |
+
- 本项目仅用于个人学习和研究目的
|
| 208 |
+
- 请遵守当地法律法规,不要用于非法用途
|
| 209 |
+
- 确保设置强密码API Key以保护接口
|
| 210 |
+
- Hugging Face Spaces有资源和流量限制,请合理使用
|
| 211 |
+
|
| 212 |
+
## 许可
|
| 213 |
+
|
| 214 |
MIT
|
entrypoint.sh
CHANGED
|
@@ -36,6 +36,8 @@ WORKER_COUNT=${WORKER_COUNT:-$(( $(nproc) + 1 ))}
|
|
| 36 |
echo "Using $WORKER_COUNT workers"
|
| 37 |
|
| 38 |
exec gunicorn \
|
|
|
|
|
|
|
| 39 |
--workers=$WORKER_COUNT \
|
| 40 |
--bind=0.0.0.0:${FLASK_PORT:-8000} \
|
| 41 |
--log-level=info \
|
|
|
|
| 36 |
echo "Using $WORKER_COUNT workers"
|
| 37 |
|
| 38 |
exec gunicorn \
|
| 39 |
+
--user=root \
|
| 40 |
+
--group=root \
|
| 41 |
--workers=$WORKER_COUNT \
|
| 42 |
--bind=0.0.0.0:${FLASK_PORT:-8000} \
|
| 43 |
--log-level=info \
|