-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from ShilongLee/proxy
Proxy
- Loading branch information
Showing
16 changed files
with
391 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
# API 文档 | ||
|
||
## 代理 | ||
|
||
以下POST请求参数均使用raw json格式,例如添加代理接口参数为:`{"urls": ["http://example.com:1234", "http://example2.com:2345"] }` | ||
|
||
### 添加代理 | ||
|
||
- **功能说明** | ||
|
||
添加完成后,默认为启用状态(`enable = 1`)。 | ||
|
||
- **URL** | ||
|
||
`/proxies/add` | ||
|
||
- **Method** | ||
|
||
`POST` | ||
|
||
- **Data Params** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| urls | true | [string] | url列表 | | ||
|
||
- **Response** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| code | true | int | 0: 成功 1: 参数错误 2: 服务器错误 | | ||
| data | false | null | 数据 | | ||
| msg | true | string | 请求说明(成功、参数错误、服务器错误) | | ||
|
||
### 移除代理 | ||
|
||
- **URL** | ||
|
||
`/proxies/remove` | ||
|
||
- **Method** | ||
|
||
`POST` | ||
|
||
- **Data Params** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| ids | true | [int] | 需要移除的代理id列表,id可以从代理的list接口获取 | | ||
|
||
- **Response** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| code | true | int | 0: 成功 1: 参数错误 2: 服务器错误 | | ||
| data | false | null | 数据 | | ||
| msg | true | string | 请求说明(成功、参数错误、服务器错误) | | ||
|
||
### 代理列表 | ||
|
||
- **URL** | ||
|
||
`/proxies/list` | ||
|
||
- **Method** | ||
|
||
`GET` | ||
|
||
- **URL Params** | ||
|
||
None | ||
|
||
- **Response** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| code | true | int | 0: 成功 1: 参数错误 2: 服务器错误 | | ||
| data | true | list | [ [代理列表](#代理信息) ] | | ||
| msg | true | string | 请求说明(成功、参数错误、服务器错误) | | ||
|
||
#### 代理信息 | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| id | true | int | id(用于管理) | | ||
| url | true | string | 代理地址 | | ||
| ct | true | int | 创建时间戳 | | ||
| ut | true | int | 更新时间戳 | | ||
| enable | true | int | 0: 不启用 1: 启用 | | ||
|
||
### 启用代理 | ||
|
||
- **功能说明** | ||
|
||
请求会轮换使用处于启用状态下的代理。 | ||
|
||
- **URL** | ||
|
||
`/proxies/enable` | ||
|
||
- **Method** | ||
|
||
`POST` | ||
|
||
- **Data Params** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| ids | true | [int] | 需要启用的代理id列表,id可以从代理的list接口获取 | | ||
|
||
- **Response** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| code | true | int | 0: 成功 1: 参数错误 2: 服务器错误 | | ||
| data | false | null | 数据 | | ||
| msg | true | string | 请求说明(成功、参数错误、服务器错误) | | ||
|
||
### 禁用代理 | ||
|
||
- **功能说明** | ||
|
||
禁用状态下的代理不会被使用。 | ||
|
||
- **URL** | ||
|
||
`/proxies/disable` | ||
|
||
- **Method** | ||
|
||
`POST` | ||
|
||
- **Data Params** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| ids | true | [int] | 需要禁用的代理id列表,id可以从代理的list接口获取 | | ||
|
||
- **Response** | ||
|
||
| 参数 | 必选 | 类型 | 说明 | | ||
|:---:|:---:|:---:|:---:| | ||
| code | true | int | 0: 成功 1: 参数错误 2: 服务器错误 | | ||
| data | false | null | 数据 | | ||
| msg | true | string | 请求说明(成功、参数错误、服务器错误) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from data.driver import Proxies | ||
|
||
proxies = Proxies("data/proxies/proxies.db") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from . import views | ||
from fastapi import APIRouter | ||
|
||
router = APIRouter(prefix='/proxies') | ||
|
||
router.add_api_route('/add', views.add, methods=['POST']) | ||
router.add_api_route('/list', views.list, methods=['GET']) | ||
router.add_api_route('/remove', views.remove, methods=['POST']) | ||
router.add_api_route('/disable', views.disable, methods=['POST']) | ||
router.add_api_route('/enable', views.enable, methods=['POST']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .add import add | ||
from .disable import disable | ||
from .enable import enable | ||
from .list import list | ||
from .remove import remove |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from utils.reply import reply | ||
from ..models import proxies | ||
from pydantic import BaseModel | ||
from lib.logger import logger | ||
from typing import List | ||
|
||
class Param(BaseModel): | ||
urls: List[str] | ||
|
||
async def add(param: Param): | ||
''' | ||
增加代理地址,默认开启使用 | ||
''' | ||
for url in param.urls: | ||
await proxies.save(url, 1) | ||
logger.info(f'add proxy, url: {url}') | ||
return reply() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from utils.reply import reply | ||
from ..models import proxies | ||
from pydantic import BaseModel | ||
from lib.logger import logger | ||
from typing import List | ||
|
||
class Param(BaseModel): | ||
ids: List[int] | ||
|
||
async def disable(param: Param): | ||
''' | ||
禁用代理地址 | ||
''' | ||
failed_list = [] | ||
for id in param.ids: | ||
result = await proxies.disable(id) | ||
if(not result): | ||
failed_list.append(id) | ||
logger.error(f"disable proxy failed, id: {id}") | ||
data = None | ||
if(len(failed_list) > 0): | ||
data = {"failed": failed_list} | ||
return reply(data = data) |
Oops, something went wrong.