# Python alist proxy and monitor.
## 安装
你可以从 [pypi](https://pypi.org/project/alist_proxy/) 安装
```console
pip install -U alist_proxy
```
## 用法
### 作为模块使用
```python
>>> import alist_proxy
>>> help(alist_proxy)
Help on package alist_proxy:
NAME
alist_proxy - # encoding: utf-8
PACKAGE CONTENTS
__main__
FUNCTIONS
make_application(base_url: str = 'http://localhost:5244', collect: None | collections.abc.Callable[[dict], typing.Any] = None, project: None | collections.abc.Callable[[dict], typing.Any] = None, methods: list[str] = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH', 'MKCOL', 'COPY', 'MOVE', 'PROPFIND', 'PROPPATCH', 'LOCK', 'UNLOCK', 'REPORT', 'ACL'], threaded: bool = False) -> blacksheep.server.application.Application
创建一个 blacksheep 应用,用于反向代理 alist,并持续收集每个请求事件的消息
:param alist_token: alist 的 token,提供此参数可在 115 网盘遭受 405 风控时自动扫码刷新 cookies
:param base_url: alist 的 base_url
:param collect: 调用以收集 alist 请求事件的消息(在 project 调用之后),如果为 None,则输出到日志
:param webhooks: 一组 webhook 的链接,事件会用 POST 请求发送给每一个链接,响应头为 {"Content-type": "application/json; charset=utf-8"}
:param project: 调用以对请求事件的消息进行映射处理,如果结果为 None,则丢弃此消息
:param methods: 需要监听的 HTTP 方法集
:param threaded: collect 和 project,如果不是 async 函数,就放到单独的线程中运行
:return: 一个 blacksheep 应用,你可以二次扩展,并用 uvicorn 运行
make_application_with_fs_event_stream(alist_token: str, base_url: str = 'http://localhost:5244', db_uri: str = 'sqlite')
只收集和文件系统操作有关的事件,存储到 redis streams,并且可以通过 websocket 拉取
:param alist_token: alist 的 token,用来追踪后台任务列表(若不提供,则不追踪任务列表)
:param base_url: alist 的 base_url
:param db_uri: 数据库连接的 URI,格式为 "{dbtype}://{host}:{port}/{path}
- dbtype: 数据库类型,目前仅支持 "sqlite"、"mongodb" 和 "redis"
- host: (非 "sqlite")ip 或 hostname,如果忽略,则用 "localhost"
- port: (非 "sqlite")端口号,如果忽略,则自动使用此数据库的默认端口号
- path: (限 "sqlite")文件路径,如果忽略,则为 ""(会使用一个临时文件)
如果你只输入 dbtype 的名字,则视为 "{dbtype}://"
如果你输入了值,但不能被视为 dbtype,则自动视为 path,即 "sqlite:///{path}"
:param webhooks: 一组 webhook 的链接,事件会用 POST 请求发送给每一个链接,响应头为 {"Content-type": "application/json; charset=utf-8"}
:return: 一个 blacksheep 应用,你可以二次扩展,并用 uvicorn 运行
make_application_with_fs_events(alist_token: str, base_url: str = 'http://localhost:5244', collect: None | collections.abc.Callable[[dict], typing.Any] = None, threaded: bool = False) -> blacksheep.server.application.Application
只收集和文件系统操作有关的事件
:param alist_token: alist 的 token,用来追踪后台任务列表(若不提供,则不追踪任务列表)
:param base_url: alist 的 base_url
:param collect: 调用以收集 alist 请求事件的消息(在 project 调用之后),如果为 None,则输出到日志
:param webhooks: 一组 webhook 的链接,事件会用 POST 请求发送给每一个链接,响应头为 {"Content-type": "application/json; charset=utf-8"}
:param threaded: collect 如果不是 async 函数,就放到单独的线程中运行
:return: 一个 blacksheep 应用,你可以二次扩展,并用 uvicorn 运行
DATA
__all__ = ['make_application', 'make_application_with_fs_events', 'make_application_with_fs_event_stream']
VERSION
(0, 0, 8)
AUTHOR
ChenyangGao <https://chenyanggao.github.io>
```
### 命令行使用
```console
$ alist-proxy -h
usage: alist-proxy [-h] [-H HOST] [-P PORT] [-b BASE_URL] [-t TOKEN] [-u DB_URI] [-d] [-v]
🌍🚢 alist 网络代理抓包 🕷️🕸️
options:
-h, --help show this help message and exit
-H HOST, --host HOST ip 或 hostname,默认值:'0.0.0.0'
-P PORT, --port PORT 端口号,默认值:5245
-b BASE_URL, --base-url BASE_URL
被代理的 alist 服务的 base_url,默认值:'http://localhost:5244'
-t TOKEN, --token TOKEN
alist 的 token,用来追踪后台任务列表(若不提供,则不追踪任务列表)
-u DB_URI, --db-uri DB_URI
数据库连接的 URI,格式为 "{dbtype}://{host}:{port}/{path}"
- dbtype: 数据库类型,目前仅支持 "sqlite"、"mongodb" 和 "redis"
- host: (非 "sqlite")ip 或 hostname,如果忽略,则用 "localhost"
- port: (非 "sqlite")端口号,如果忽略,则自动使用此数据库的默认端口号
- path: (限 "sqlite")文件路径,如果忽略,则为 ""(会使用一个临时文件)
如果你只输入 dbtype 的名字,则视为 "{dbtype}://"
如果你输入了值,但不能被视为 dbtype,则自动视为 path,即 "sqlite:///{path}"
-w [webhook ...], --webhooks [webhook ...]
一组 webhook 的链接,事件会用 POST 请求发送给每一个链接,响应头为 {"Content-type": "application/json; charset=utf-8"}
-d, --debug 启用 debug 模式(会输出更详细的信息)
-v, --version 输出版本号
$ alist-proxy
INFO: Started server process [64373]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:5245 (Press CTRL+C to quit)
```
#### 启动准备
首先要求有一个正在运行中的 alist 服务,假设地址为 http://localhost:5244
然后在命令行中运行
```console
alist-proxy --base-url http://localhost:5244
```
就可以开始代理监听了。如果 --base-url 就是默认地址 http://localhost:5244,是可以省略的。
如果你还需要监听后台的 **复制**、**上传**、**离线下载转存** 事件,则需要在命令行中提供 alist 的 token。
```console
ALIST_TOKEN='alist-xxxx'
alist-proxy --token "$ALIST_TOKEN"
```
如果你需要使用 webhook,则需要指定 -w/--webhooks 参数。
如果你需要使用 websocket,则需要指定 --db-uri 参数,以将数据存储到数据库,目前只支持 sqlite、mongodb 和 redis。
#### webhook 接口
如果你指定了 -w/--webhooks 参数,就会发送事件到指定的这组链接上
```console
alist-proxy -w http://localhost:8888/webhook
```
客户端代码
```python
from flask import request, Flask
app = Flask(__name__)
@app.route("/webhook", methods=["POST"])
def handle_post():
data = request.get_json()
print(f"Received: {data}")
return "", 200
app.run(port=8888, threaded=True)
```
#### websocket 接口
如果你指定了 -u/--db-uri 参数,就可以使用 websocket 接口 <kbd>/pull</kbd>
```console
alist-proxy -u sqlite
```
客户端代码
```python
from asyncio import run
from json import loads
import websockets
async def pull():
uri = "ws://localhost:5245/pull"
async with websockets.connect(uri) as websocket:
while True:
data = loads(await websocket.recv())
print(f"Received: {data}")
run(pull())
```
##### redis
<kbd>/pull</kbd> 接口支持 3 个查询参数,均可省略,省略则从当前开始拉取最新数据
- `lastid`: 从这个 id(不含)开始读取。省略时,如果指定了非空的 `group`,则继续这个组的读取进度,否则从当前开始(不管以前)读取。如果要从头开始读取,指定 '0' 即可
- `group`: 组名称。如果组不存在,则自动创建。
- `name`: 消费者名称。
##### mongodb
<kbd>/pull</kbd> 接口支持 3 个查询参数,均可省略,省略则从当前开始拉取最新数据
- `lastid`: 从这个 id(不含)开始读取,是一个字符串,表示 UUID。
- `from_datetime`: 从这个时间点开始,是一个字符串。
##### sqlite
<kbd>/pull</kbd> 接口支持 3 个查询参数,均可省略,省略则从当前开始拉取最新数据
- `lastid`: 从这个 id(不含)开始读取,是一个整数,表示自增主键。
- `from_datetime`: 从这个时间点开始,是一个字符串。
#### 事件说明
命令行程序只采集和文件系统操作有关的事件消息
你可以从 <kbd>/pull</kbd> 接口拉取 json 格式的数据。这些数据有几个共同的字段
1. category: 任务类别。有 3 个可能的值:
- <kbd>web</kbd>: 由网页直接调用接口成功后产生
- <kbd>dav</kbd>: 通过 webdav 的成功操作产生
- <kbd>task</kbd>: 监控后台任务,由执行成功的任务产生
2. type: 任务类型。可能的取值如下:
- <kbd>upload</kbd>: 上传/创建 文件
- <kbd>rename</kbd>: 文件或目录的改名
- <kbd>move</kbd>: 移动文件或目录(webdav 还包括改名)
- <kbd>remove</kbd>: 删除文件或目录
- <kbd>copy</kbd>: 复制文件或目录
- <kbd>mkdir</kbd>: 创建空目录
- <kbd>find</kbd>: 查询文件或目录的信息,或罗列目录
3. method: 具体的操作方法
4. payload: 和路径有关的数据,每组(由 (method, category, type) 一起确定)都有所不同
同一种 category 的各个 method 的 payload 的字段构成近似。
- <kbd>web</kbd>: payload 收集了相关的查询参数,详见 https://alist.nn.ci/guide/api/fs.html
- <kbd>dav</kbd>: 一般包含
- <kbd>path</kbd>: 被操作的路径
- <kbd>is_dir</kbd>: 是否目录
可能包含
- <kbd>to_path</kbd>: 操作后的路径(COPY 或 MOVE)
- <kbd>task</kbd>: 目前有 3 种情况
- <kbd>method</kbd> 为 copy,即复制,包含
- <kbd>src_path</kbd>: 源路径
- <kbd>dst_path</kbd>: 目标路径
- <kbd>src_storage</kbd>: 源所在存储
- <kbd>dst_storage</kbd>: 目标所在存储
- <kbd>src_dir</kbd>: 源所在目录
- <kbd>dst_dir</kbd>: 目标所在目录
- <kbd>name</kbd>: 名字
- <kbd>is_dir</kbd>: 是否目录
- <kbd>method</kbd> 为 upload,即上传,包含
- <kbd>path</kbd>: 目标路径
- <kbd>dst_storage</kbd>: 目标所在存储
- <kbd>dst_dir</kbd>: 目标所在目录
- <kbd>name</kbd>: 名字
- <kbd>is_dir</kbd>: 是否目录,必为 False
- <kbd>method</kbd> 为 transfer,即离线下载后上传,包含
- <kbd>path</kbd>: 目标路径
- <kbd>dst_dir</kbd>: 目标所在目录
- <kbd>name</kbd>: 名字
- <kbd>is_dir</kbd>: 是否目录,必为 False
Raw data
{
"_id": null,
"home_page": "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-alist-proxy",
"name": "alist_proxy",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": "alist, proxy, monitor",
"author": "ChenyangGao",
"author_email": "wosiwujm@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ca/11/e33ffe34dfe85a2fbd837dbbda6e520389862113bb296c176478f2e7a856/alist_proxy-0.0.9.1.tar.gz",
"platform": null,
"description": "# Python alist proxy and monitor.\n\n## \u5b89\u88c5\n\n\u4f60\u53ef\u4ee5\u4ece [pypi](https://pypi.org/project/alist_proxy/) \u5b89\u88c5\n\n```console\npip install -U alist_proxy\n```\n\n## \u7528\u6cd5\n\n### \u4f5c\u4e3a\u6a21\u5757\u4f7f\u7528\n\n```python\n>>> import alist_proxy\n>>> help(alist_proxy)\nHelp on package alist_proxy:\n\nNAME\n alist_proxy - # encoding: utf-8\n\nPACKAGE CONTENTS\n __main__\n\nFUNCTIONS\n make_application(base_url: str = 'http://localhost:5244', collect: None | collections.abc.Callable[[dict], typing.Any] = None, project: None | collections.abc.Callable[[dict], typing.Any] = None, methods: list[str] = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH', 'MKCOL', 'COPY', 'MOVE', 'PROPFIND', 'PROPPATCH', 'LOCK', 'UNLOCK', 'REPORT', 'ACL'], threaded: bool = False) -> blacksheep.server.application.Application\n \u521b\u5efa\u4e00\u4e2a blacksheep \u5e94\u7528\uff0c\u7528\u4e8e\u53cd\u5411\u4ee3\u7406 alist\uff0c\u5e76\u6301\u7eed\u6536\u96c6\u6bcf\u4e2a\u8bf7\u6c42\u4e8b\u4ef6\u7684\u6d88\u606f\n\n :param alist_token: alist \u7684 token\uff0c\u63d0\u4f9b\u6b64\u53c2\u6570\u53ef\u5728 115 \u7f51\u76d8\u906d\u53d7 405 \u98ce\u63a7\u65f6\u81ea\u52a8\u626b\u7801\u5237\u65b0 cookies\n :param base_url: alist \u7684 base_url\n :param collect: \u8c03\u7528\u4ee5\u6536\u96c6 alist \u8bf7\u6c42\u4e8b\u4ef6\u7684\u6d88\u606f\uff08\u5728 project \u8c03\u7528\u4e4b\u540e\uff09\uff0c\u5982\u679c\u4e3a None\uff0c\u5219\u8f93\u51fa\u5230\u65e5\u5fd7\n :param webhooks: \u4e00\u7ec4 webhook \u7684\u94fe\u63a5\uff0c\u4e8b\u4ef6\u4f1a\u7528 POST \u8bf7\u6c42\u53d1\u9001\u7ed9\u6bcf\u4e00\u4e2a\u94fe\u63a5\uff0c\u54cd\u5e94\u5934\u4e3a {\"Content-type\": \"application/json; charset=utf-8\"}\n :param project: \u8c03\u7528\u4ee5\u5bf9\u8bf7\u6c42\u4e8b\u4ef6\u7684\u6d88\u606f\u8fdb\u884c\u6620\u5c04\u5904\u7406\uff0c\u5982\u679c\u7ed3\u679c\u4e3a None\uff0c\u5219\u4e22\u5f03\u6b64\u6d88\u606f\n :param methods: \u9700\u8981\u76d1\u542c\u7684 HTTP \u65b9\u6cd5\u96c6\n :param threaded: collect \u548c project\uff0c\u5982\u679c\u4e0d\u662f async \u51fd\u6570\uff0c\u5c31\u653e\u5230\u5355\u72ec\u7684\u7ebf\u7a0b\u4e2d\u8fd0\u884c\n\n :return: \u4e00\u4e2a blacksheep \u5e94\u7528\uff0c\u4f60\u53ef\u4ee5\u4e8c\u6b21\u6269\u5c55\uff0c\u5e76\u7528 uvicorn \u8fd0\u884c\n\n make_application_with_fs_event_stream(alist_token: str, base_url: str = 'http://localhost:5244', db_uri: str = 'sqlite')\n \u53ea\u6536\u96c6\u548c\u6587\u4ef6\u7cfb\u7edf\u64cd\u4f5c\u6709\u5173\u7684\u4e8b\u4ef6\uff0c\u5b58\u50a8\u5230 redis streams\uff0c\u5e76\u4e14\u53ef\u4ee5\u901a\u8fc7 websocket \u62c9\u53d6\n \n :param alist_token: alist \u7684 token\uff0c\u7528\u6765\u8ffd\u8e2a\u540e\u53f0\u4efb\u52a1\u5217\u8868\uff08\u82e5\u4e0d\u63d0\u4f9b\uff0c\u5219\u4e0d\u8ffd\u8e2a\u4efb\u52a1\u5217\u8868\uff09\n :param base_url: alist \u7684 base_url\n :param db_uri: \u6570\u636e\u5e93\u8fde\u63a5\u7684 URI\uff0c\u683c\u5f0f\u4e3a \"{dbtype}://{host}:{port}/{path}\n\n - dbtype: \u6570\u636e\u5e93\u7c7b\u578b\uff0c\u76ee\u524d\u4ec5\u652f\u6301 \"sqlite\"\u3001\"mongodb\" \u548c \"redis\"\n - host: \uff08\u975e \"sqlite\"\uff09ip \u6216 hostname\uff0c\u5982\u679c\u5ffd\u7565\uff0c\u5219\u7528 \"localhost\"\n - port: \uff08\u975e \"sqlite\"\uff09\u7aef\u53e3\u53f7\uff0c\u5982\u679c\u5ffd\u7565\uff0c\u5219\u81ea\u52a8\u4f7f\u7528\u6b64\u6570\u636e\u5e93\u7684\u9ed8\u8ba4\u7aef\u53e3\u53f7\n - path: \uff08\u9650 \"sqlite\"\uff09\u6587\u4ef6\u8def\u5f84\uff0c\u5982\u679c\u5ffd\u7565\uff0c\u5219\u4e3a \"\"\uff08\u4f1a\u4f7f\u7528\u4e00\u4e2a\u4e34\u65f6\u6587\u4ef6\uff09\n\n \u5982\u679c\u4f60\u53ea\u8f93\u5165 dbtype \u7684\u540d\u5b57\uff0c\u5219\u89c6\u4e3a \"{dbtype}://\"\n \u5982\u679c\u4f60\u8f93\u5165\u4e86\u503c\uff0c\u4f46\u4e0d\u80fd\u88ab\u89c6\u4e3a dbtype\uff0c\u5219\u81ea\u52a8\u89c6\u4e3a path\uff0c\u5373 \"sqlite:///{path}\"\n :param webhooks: \u4e00\u7ec4 webhook \u7684\u94fe\u63a5\uff0c\u4e8b\u4ef6\u4f1a\u7528 POST \u8bf7\u6c42\u53d1\u9001\u7ed9\u6bcf\u4e00\u4e2a\u94fe\u63a5\uff0c\u54cd\u5e94\u5934\u4e3a {\"Content-type\": \"application/json; charset=utf-8\"}\n\n :return: \u4e00\u4e2a blacksheep \u5e94\u7528\uff0c\u4f60\u53ef\u4ee5\u4e8c\u6b21\u6269\u5c55\uff0c\u5e76\u7528 uvicorn \u8fd0\u884c\n\n make_application_with_fs_events(alist_token: str, base_url: str = 'http://localhost:5244', collect: None | collections.abc.Callable[[dict], typing.Any] = None, threaded: bool = False) -> blacksheep.server.application.Application\n \u53ea\u6536\u96c6\u548c\u6587\u4ef6\u7cfb\u7edf\u64cd\u4f5c\u6709\u5173\u7684\u4e8b\u4ef6\n \n :param alist_token: alist \u7684 token\uff0c\u7528\u6765\u8ffd\u8e2a\u540e\u53f0\u4efb\u52a1\u5217\u8868\uff08\u82e5\u4e0d\u63d0\u4f9b\uff0c\u5219\u4e0d\u8ffd\u8e2a\u4efb\u52a1\u5217\u8868\uff09\n :param base_url: alist \u7684 base_url\n :param collect: \u8c03\u7528\u4ee5\u6536\u96c6 alist \u8bf7\u6c42\u4e8b\u4ef6\u7684\u6d88\u606f\uff08\u5728 project \u8c03\u7528\u4e4b\u540e\uff09\uff0c\u5982\u679c\u4e3a None\uff0c\u5219\u8f93\u51fa\u5230\u65e5\u5fd7\n :param webhooks: \u4e00\u7ec4 webhook \u7684\u94fe\u63a5\uff0c\u4e8b\u4ef6\u4f1a\u7528 POST \u8bf7\u6c42\u53d1\u9001\u7ed9\u6bcf\u4e00\u4e2a\u94fe\u63a5\uff0c\u54cd\u5e94\u5934\u4e3a {\"Content-type\": \"application/json; charset=utf-8\"}\n :param threaded: collect \u5982\u679c\u4e0d\u662f async \u51fd\u6570\uff0c\u5c31\u653e\u5230\u5355\u72ec\u7684\u7ebf\u7a0b\u4e2d\u8fd0\u884c\n\n :return: \u4e00\u4e2a blacksheep \u5e94\u7528\uff0c\u4f60\u53ef\u4ee5\u4e8c\u6b21\u6269\u5c55\uff0c\u5e76\u7528 uvicorn \u8fd0\u884c\n\nDATA\n __all__ = ['make_application', 'make_application_with_fs_events', 'make_application_with_fs_event_stream']\n\nVERSION\n (0, 0, 8)\n\nAUTHOR\n ChenyangGao <https://chenyanggao.github.io>\n```\n\n### \u547d\u4ee4\u884c\u4f7f\u7528\n\n```console\n$ alist-proxy -h\nusage: alist-proxy [-h] [-H HOST] [-P PORT] [-b BASE_URL] [-t TOKEN] [-u DB_URI] [-d] [-v]\n\n\t\t\ud83c\udf0d\ud83d\udea2 alist \u7f51\u7edc\u4ee3\u7406\u6293\u5305 \ud83d\udd77\ufe0f\ud83d\udd78\ufe0f\n\noptions:\n -h, --help show this help message and exit\n -H HOST, --host HOST ip \u6216 hostname\uff0c\u9ed8\u8ba4\u503c\uff1a'0.0.0.0'\n -P PORT, --port PORT \u7aef\u53e3\u53f7\uff0c\u9ed8\u8ba4\u503c\uff1a5245\n -b BASE_URL, --base-url BASE_URL\n \u88ab\u4ee3\u7406\u7684 alist \u670d\u52a1\u7684 base_url\uff0c\u9ed8\u8ba4\u503c\uff1a'http://localhost:5244'\n -t TOKEN, --token TOKEN\n alist \u7684 token\uff0c\u7528\u6765\u8ffd\u8e2a\u540e\u53f0\u4efb\u52a1\u5217\u8868\uff08\u82e5\u4e0d\u63d0\u4f9b\uff0c\u5219\u4e0d\u8ffd\u8e2a\u4efb\u52a1\u5217\u8868\uff09\n -u DB_URI, --db-uri DB_URI\n \u6570\u636e\u5e93\u8fde\u63a5\u7684 URI\uff0c\u683c\u5f0f\u4e3a \"{dbtype}://{host}:{port}/{path}\"\n - dbtype: \u6570\u636e\u5e93\u7c7b\u578b\uff0c\u76ee\u524d\u4ec5\u652f\u6301 \"sqlite\"\u3001\"mongodb\" \u548c \"redis\"\n - host: \uff08\u975e \"sqlite\"\uff09ip \u6216 hostname\uff0c\u5982\u679c\u5ffd\u7565\uff0c\u5219\u7528 \"localhost\"\n - port: \uff08\u975e \"sqlite\"\uff09\u7aef\u53e3\u53f7\uff0c\u5982\u679c\u5ffd\u7565\uff0c\u5219\u81ea\u52a8\u4f7f\u7528\u6b64\u6570\u636e\u5e93\u7684\u9ed8\u8ba4\u7aef\u53e3\u53f7\n - path: \uff08\u9650 \"sqlite\"\uff09\u6587\u4ef6\u8def\u5f84\uff0c\u5982\u679c\u5ffd\u7565\uff0c\u5219\u4e3a \"\"\uff08\u4f1a\u4f7f\u7528\u4e00\u4e2a\u4e34\u65f6\u6587\u4ef6\uff09\n \u5982\u679c\u4f60\u53ea\u8f93\u5165 dbtype \u7684\u540d\u5b57\uff0c\u5219\u89c6\u4e3a \"{dbtype}://\"\n \u5982\u679c\u4f60\u8f93\u5165\u4e86\u503c\uff0c\u4f46\u4e0d\u80fd\u88ab\u89c6\u4e3a dbtype\uff0c\u5219\u81ea\u52a8\u89c6\u4e3a path\uff0c\u5373 \"sqlite:///{path}\"\n -w [webhook ...], --webhooks [webhook ...]\n \u4e00\u7ec4 webhook \u7684\u94fe\u63a5\uff0c\u4e8b\u4ef6\u4f1a\u7528 POST \u8bf7\u6c42\u53d1\u9001\u7ed9\u6bcf\u4e00\u4e2a\u94fe\u63a5\uff0c\u54cd\u5e94\u5934\u4e3a {\"Content-type\": \"application/json; charset=utf-8\"}\n -d, --debug \u542f\u7528 debug \u6a21\u5f0f\uff08\u4f1a\u8f93\u51fa\u66f4\u8be6\u7ec6\u7684\u4fe1\u606f\uff09\n -v, --version \u8f93\u51fa\u7248\u672c\u53f7\n\n$ alist-proxy\nINFO: Started server process [64373]\nINFO: Waiting for application startup.\nINFO: Application startup complete.\nINFO: Uvicorn running on http://0.0.0.0:5245 (Press CTRL+C to quit)\n```\n\n#### \u542f\u52a8\u51c6\u5907\n\n\u9996\u5148\u8981\u6c42\u6709\u4e00\u4e2a\u6b63\u5728\u8fd0\u884c\u4e2d\u7684 alist \u670d\u52a1\uff0c\u5047\u8bbe\u5730\u5740\u4e3a http://localhost:5244\n\n\u7136\u540e\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\n\n```console\nalist-proxy --base-url http://localhost:5244\n```\n\n\u5c31\u53ef\u4ee5\u5f00\u59cb\u4ee3\u7406\u76d1\u542c\u4e86\u3002\u5982\u679c --base-url \u5c31\u662f\u9ed8\u8ba4\u5730\u5740 http://localhost:5244\uff0c\u662f\u53ef\u4ee5\u7701\u7565\u7684\u3002\n\n\u5982\u679c\u4f60\u8fd8\u9700\u8981\u76d1\u542c\u540e\u53f0\u7684 **\u590d\u5236**\u3001**\u4e0a\u4f20**\u3001**\u79bb\u7ebf\u4e0b\u8f7d\u8f6c\u5b58** \u4e8b\u4ef6\uff0c\u5219\u9700\u8981\u5728\u547d\u4ee4\u884c\u4e2d\u63d0\u4f9b alist \u7684 token\u3002\n\n```console\nALIST_TOKEN='alist-xxxx'\nalist-proxy --token \"$ALIST_TOKEN\"\n```\n\n\u5982\u679c\u4f60\u9700\u8981\u4f7f\u7528 webhook\uff0c\u5219\u9700\u8981\u6307\u5b9a -w/--webhooks \u53c2\u6570\u3002\n\n\u5982\u679c\u4f60\u9700\u8981\u4f7f\u7528 websocket\uff0c\u5219\u9700\u8981\u6307\u5b9a --db-uri \u53c2\u6570\uff0c\u4ee5\u5c06\u6570\u636e\u5b58\u50a8\u5230\u6570\u636e\u5e93\uff0c\u76ee\u524d\u53ea\u652f\u6301 sqlite\u3001mongodb \u548c redis\u3002\n\n#### webhook \u63a5\u53e3\n\n\u5982\u679c\u4f60\u6307\u5b9a\u4e86 -w/--webhooks \u53c2\u6570\uff0c\u5c31\u4f1a\u53d1\u9001\u4e8b\u4ef6\u5230\u6307\u5b9a\u7684\u8fd9\u7ec4\u94fe\u63a5\u4e0a\n\n```console\nalist-proxy -w http://localhost:8888/webhook\n```\n\n\u5ba2\u6237\u7aef\u4ee3\u7801\n\n```python\nfrom flask import request, Flask\n\napp = Flask(__name__)\n\n@app.route(\"/webhook\", methods=[\"POST\"])\ndef handle_post():\n data = request.get_json()\n print(f\"Received: {data}\")\n return \"\", 200\n\napp.run(port=8888, threaded=True)\n```\n\n#### websocket \u63a5\u53e3\n\n\u5982\u679c\u4f60\u6307\u5b9a\u4e86 -u/--db-uri \u53c2\u6570\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 websocket \u63a5\u53e3 <kbd>/pull</kbd>\n\n```console\nalist-proxy -u sqlite\n```\n\n\u5ba2\u6237\u7aef\u4ee3\u7801\n\n```python\nfrom asyncio import run\nfrom json import loads\n\nimport websockets\n\nasync def pull():\n uri = \"ws://localhost:5245/pull\"\n async with websockets.connect(uri) as websocket:\n while True:\n data = loads(await websocket.recv())\n print(f\"Received: {data}\")\n\nrun(pull())\n```\n\n##### redis\n\n<kbd>/pull</kbd> \u63a5\u53e3\u652f\u6301 3 \u4e2a\u67e5\u8be2\u53c2\u6570\uff0c\u5747\u53ef\u7701\u7565\uff0c\u7701\u7565\u5219\u4ece\u5f53\u524d\u5f00\u59cb\u62c9\u53d6\u6700\u65b0\u6570\u636e\n\n- `lastid`: \u4ece\u8fd9\u4e2a id\uff08\u4e0d\u542b\uff09\u5f00\u59cb\u8bfb\u53d6\u3002\u7701\u7565\u65f6\uff0c\u5982\u679c\u6307\u5b9a\u4e86\u975e\u7a7a\u7684 `group`\uff0c\u5219\u7ee7\u7eed\u8fd9\u4e2a\u7ec4\u7684\u8bfb\u53d6\u8fdb\u5ea6\uff0c\u5426\u5219\u4ece\u5f53\u524d\u5f00\u59cb\uff08\u4e0d\u7ba1\u4ee5\u524d\uff09\u8bfb\u53d6\u3002\u5982\u679c\u8981\u4ece\u5934\u5f00\u59cb\u8bfb\u53d6\uff0c\u6307\u5b9a '0' \u5373\u53ef\n- `group`: \u7ec4\u540d\u79f0\u3002\u5982\u679c\u7ec4\u4e0d\u5b58\u5728\uff0c\u5219\u81ea\u52a8\u521b\u5efa\u3002\n- `name`: \u6d88\u8d39\u8005\u540d\u79f0\u3002\n\n##### mongodb\n\n<kbd>/pull</kbd> \u63a5\u53e3\u652f\u6301 3 \u4e2a\u67e5\u8be2\u53c2\u6570\uff0c\u5747\u53ef\u7701\u7565\uff0c\u7701\u7565\u5219\u4ece\u5f53\u524d\u5f00\u59cb\u62c9\u53d6\u6700\u65b0\u6570\u636e\n\n- `lastid`: \u4ece\u8fd9\u4e2a id\uff08\u4e0d\u542b\uff09\u5f00\u59cb\u8bfb\u53d6\uff0c\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u8868\u793a UUID\u3002\n- `from_datetime`: \u4ece\u8fd9\u4e2a\u65f6\u95f4\u70b9\u5f00\u59cb\uff0c\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\n\n##### sqlite\n\n<kbd>/pull</kbd> \u63a5\u53e3\u652f\u6301 3 \u4e2a\u67e5\u8be2\u53c2\u6570\uff0c\u5747\u53ef\u7701\u7565\uff0c\u7701\u7565\u5219\u4ece\u5f53\u524d\u5f00\u59cb\u62c9\u53d6\u6700\u65b0\u6570\u636e\n\n- `lastid`: \u4ece\u8fd9\u4e2a id\uff08\u4e0d\u542b\uff09\u5f00\u59cb\u8bfb\u53d6\uff0c\u662f\u4e00\u4e2a\u6574\u6570\uff0c\u8868\u793a\u81ea\u589e\u4e3b\u952e\u3002\n- `from_datetime`: \u4ece\u8fd9\u4e2a\u65f6\u95f4\u70b9\u5f00\u59cb\uff0c\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\n\n#### \u4e8b\u4ef6\u8bf4\u660e\n\n\u547d\u4ee4\u884c\u7a0b\u5e8f\u53ea\u91c7\u96c6\u548c\u6587\u4ef6\u7cfb\u7edf\u64cd\u4f5c\u6709\u5173\u7684\u4e8b\u4ef6\u6d88\u606f\n\n\u4f60\u53ef\u4ee5\u4ece <kbd>/pull</kbd> \u63a5\u53e3\u62c9\u53d6 json \u683c\u5f0f\u7684\u6570\u636e\u3002\u8fd9\u4e9b\u6570\u636e\u6709\u51e0\u4e2a\u5171\u540c\u7684\u5b57\u6bb5\n\n1. category: \u4efb\u52a1\u7c7b\u522b\u3002\u6709 3 \u4e2a\u53ef\u80fd\u7684\u503c\uff1a\n - <kbd>web</kbd>: \u7531\u7f51\u9875\u76f4\u63a5\u8c03\u7528\u63a5\u53e3\u6210\u529f\u540e\u4ea7\u751f\n - <kbd>dav</kbd>: \u901a\u8fc7 webdav \u7684\u6210\u529f\u64cd\u4f5c\u4ea7\u751f\n - <kbd>task</kbd>: \u76d1\u63a7\u540e\u53f0\u4efb\u52a1\uff0c\u7531\u6267\u884c\u6210\u529f\u7684\u4efb\u52a1\u4ea7\u751f\n2. type: \u4efb\u52a1\u7c7b\u578b\u3002\u53ef\u80fd\u7684\u53d6\u503c\u5982\u4e0b\uff1a\n - <kbd>upload</kbd>: \u4e0a\u4f20/\u521b\u5efa \u6587\u4ef6\n - <kbd>rename</kbd>: \u6587\u4ef6\u6216\u76ee\u5f55\u7684\u6539\u540d\n - <kbd>move</kbd>: \u79fb\u52a8\u6587\u4ef6\u6216\u76ee\u5f55\uff08webdav \u8fd8\u5305\u62ec\u6539\u540d\uff09\n - <kbd>remove</kbd>: \u5220\u9664\u6587\u4ef6\u6216\u76ee\u5f55\n - <kbd>copy</kbd>: \u590d\u5236\u6587\u4ef6\u6216\u76ee\u5f55\n - <kbd>mkdir</kbd>: \u521b\u5efa\u7a7a\u76ee\u5f55\n - <kbd>find</kbd>: \u67e5\u8be2\u6587\u4ef6\u6216\u76ee\u5f55\u7684\u4fe1\u606f\uff0c\u6216\u7f57\u5217\u76ee\u5f55\n3. method: \u5177\u4f53\u7684\u64cd\u4f5c\u65b9\u6cd5\n4. payload: \u548c\u8def\u5f84\u6709\u5173\u7684\u6570\u636e\uff0c\u6bcf\u7ec4\uff08\u7531 (method, category, type) \u4e00\u8d77\u786e\u5b9a\uff09\u90fd\u6709\u6240\u4e0d\u540c\n\n\u540c\u4e00\u79cd category \u7684\u5404\u4e2a method \u7684 payload \u7684\u5b57\u6bb5\u6784\u6210\u8fd1\u4f3c\u3002\n\n- <kbd>web</kbd>: payload \u6536\u96c6\u4e86\u76f8\u5173\u7684\u67e5\u8be2\u53c2\u6570\uff0c\u8be6\u89c1 https://alist.nn.ci/guide/api/fs.html\n- <kbd>dav</kbd>: \u4e00\u822c\u5305\u542b\n - <kbd>path</kbd>: \u88ab\u64cd\u4f5c\u7684\u8def\u5f84 \n - <kbd>is_dir</kbd>: \u662f\u5426\u76ee\u5f55\n\n \u53ef\u80fd\u5305\u542b\n\n - <kbd>to_path</kbd>: \u64cd\u4f5c\u540e\u7684\u8def\u5f84\uff08COPY \u6216 MOVE\uff09\n- <kbd>task</kbd>: \u76ee\u524d\u6709 3 \u79cd\u60c5\u51b5\n - <kbd>method</kbd> \u4e3a copy\uff0c\u5373\u590d\u5236\uff0c\u5305\u542b \n - <kbd>src_path</kbd>: \u6e90\u8def\u5f84\n - <kbd>dst_path</kbd>: \u76ee\u6807\u8def\u5f84\n - <kbd>src_storage</kbd>: \u6e90\u6240\u5728\u5b58\u50a8\n - <kbd>dst_storage</kbd>: \u76ee\u6807\u6240\u5728\u5b58\u50a8\n - <kbd>src_dir</kbd>: \u6e90\u6240\u5728\u76ee\u5f55\n - <kbd>dst_dir</kbd>: \u76ee\u6807\u6240\u5728\u76ee\u5f55\n - <kbd>name</kbd>: \u540d\u5b57\n - <kbd>is_dir</kbd>: \u662f\u5426\u76ee\u5f55\n - <kbd>method</kbd> \u4e3a upload\uff0c\u5373\u4e0a\u4f20\uff0c\u5305\u542b\n - <kbd>path</kbd>: \u76ee\u6807\u8def\u5f84\n - <kbd>dst_storage</kbd>: \u76ee\u6807\u6240\u5728\u5b58\u50a8\n - <kbd>dst_dir</kbd>: \u76ee\u6807\u6240\u5728\u76ee\u5f55\n - <kbd>name</kbd>: \u540d\u5b57\n - <kbd>is_dir</kbd>: \u662f\u5426\u76ee\u5f55\uff0c\u5fc5\u4e3a False\n - <kbd>method</kbd> \u4e3a transfer\uff0c\u5373\u79bb\u7ebf\u4e0b\u8f7d\u540e\u4e0a\u4f20\uff0c\u5305\u542b\n - <kbd>path</kbd>: \u76ee\u6807\u8def\u5f84\n - <kbd>dst_dir</kbd>: \u76ee\u6807\u6240\u5728\u76ee\u5f55\n - <kbd>name</kbd>: \u540d\u5b57\n - <kbd>is_dir</kbd>: \u662f\u5426\u76ee\u5f55\uff0c\u5fc5\u4e3a False\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python alist proxy and monitor.",
"version": "0.0.9.1",
"project_urls": {
"Homepage": "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-alist-proxy",
"Repository": "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-alist-proxy"
},
"split_keywords": [
"alist",
" proxy",
" monitor"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "38f74a746667e15b1e2df0faf3103f3f20347459a2691d9596857d4ae13efa63",
"md5": "3ccf0768a78bb9ba2b8e64f4bd8b2d7c",
"sha256": "3087ff87d37e91b818ccfb226a2c3999fb3133928866fe505645724196c8e341"
},
"downloads": -1,
"filename": "alist_proxy-0.0.9.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3ccf0768a78bb9ba2b8e64f4bd8b2d7c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 17543,
"upload_time": "2024-11-08T05:06:07",
"upload_time_iso_8601": "2024-11-08T05:06:07.128491Z",
"url": "https://files.pythonhosted.org/packages/38/f7/4a746667e15b1e2df0faf3103f3f20347459a2691d9596857d4ae13efa63/alist_proxy-0.0.9.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ca11e33ffe34dfe85a2fbd837dbbda6e520389862113bb296c176478f2e7a856",
"md5": "c506081145f283484e479cc3d02c4286",
"sha256": "35cd77dc841b3a72f40762c99213ccd05d0ed912acbe8dd55854c8c13396fa8e"
},
"downloads": -1,
"filename": "alist_proxy-0.0.9.1.tar.gz",
"has_sig": false,
"md5_digest": "c506081145f283484e479cc3d02c4286",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 14542,
"upload_time": "2024-11-08T05:06:09",
"upload_time_iso_8601": "2024-11-08T05:06:09.585849Z",
"url": "https://files.pythonhosted.org/packages/ca/11/e33ffe34dfe85a2fbd837dbbda6e520389862113bb296c176478f2e7a856/alist_proxy-0.0.9.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-08 05:06:09",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ChenyangGao",
"github_project": "web-mount-packs",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "alist_proxy"
}