mirror of
https://github.com/dnslin/aria2bot.git
synced 2026-01-11 20:12:20 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64fa02d0b6 | ||
|
|
64b3740bb4 | ||
|
|
b5983f57bd | ||
|
|
8d7b2667e1 |
18
Dockerfile
18
Dockerfile
@@ -18,11 +18,9 @@ FROM python:3.13-slim
|
||||
LABEL maintainer="dnslin"
|
||||
LABEL description="Aria2 Telegram Bot - 通过 Telegram 控制 aria2 下载"
|
||||
|
||||
# 安装 aria2 和必要工具
|
||||
# 安装必要工具(aria2 通过 /install 命令下载)
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
aria2 \
|
||||
ca-certificates \
|
||||
apt-get install -y --no-install-recommends ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& apt-get clean
|
||||
|
||||
@@ -31,13 +29,13 @@ WORKDIR /app
|
||||
# 从构建阶段复制虚拟环境
|
||||
COPY --from=builder /app/.venv /app/.venv
|
||||
|
||||
# 复制应用代码
|
||||
# 复制应用代码和入口脚本
|
||||
COPY src/ ./src/
|
||||
COPY main.py banner.txt ./
|
||||
COPY main.py banner.txt docker-entrypoint.sh ./
|
||||
RUN chmod +x docker-entrypoint.sh
|
||||
|
||||
# 创建必要目录和符号链接
|
||||
RUN mkdir -p /root/.local/bin /root/.config/aria2 /root/downloads && \
|
||||
ln -s /usr/bin/aria2c /root/.local/bin/aria2c
|
||||
# 创建必要目录
|
||||
RUN mkdir -p /root/.local/bin /root/.config/aria2 /root/downloads
|
||||
|
||||
# 设置环境变量
|
||||
ENV PATH="/app/.venv/bin:$PATH"
|
||||
@@ -51,4 +49,4 @@ VOLUME ["/root/downloads", "/root/.config/aria2"]
|
||||
EXPOSE 6800
|
||||
|
||||
# 启动命令
|
||||
CMD ["python", "main.py"]
|
||||
ENTRYPOINT ["./docker-entrypoint.sh"]
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
services:
|
||||
aria2bot:
|
||||
build: .
|
||||
image: dnslin/aria2bot:latest
|
||||
# 方式一:使用预构建镜像(推荐)
|
||||
image: dnslin/aria2bot:v1.1
|
||||
# 方式二:本地构建(取消下行注释,注释上行)
|
||||
# build: .
|
||||
container_name: aria2bot
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
@@ -14,3 +16,4 @@ services:
|
||||
# 可选:暴露 aria2 RPC 端口(如需外部访问)
|
||||
# ports:
|
||||
# - "6800:6800"
|
||||
|
||||
|
||||
8
docker-entrypoint.sh
Normal file
8
docker-entrypoint.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
# Docker 容器入口脚本
|
||||
|
||||
# 创建必要目录
|
||||
mkdir -p /root/.local/bin /root/.config/aria2 /root/downloads
|
||||
|
||||
# 启动应用
|
||||
exec python main.py
|
||||
@@ -257,10 +257,15 @@ class Aria2Installer:
|
||||
|
||||
try:
|
||||
if ARIA2_CONFIG_DIR.exists():
|
||||
shutil.rmtree(ARIA2_CONFIG_DIR)
|
||||
logger.info(f"已删除配置目录: {ARIA2_CONFIG_DIR}")
|
||||
# 删除配置目录中的文件,而不是整个目录(兼容 Docker 挂载卷)
|
||||
for item in ARIA2_CONFIG_DIR.iterdir():
|
||||
if item.is_file():
|
||||
item.unlink()
|
||||
elif item.is_dir():
|
||||
shutil.rmtree(item)
|
||||
logger.info(f"已清空配置目录: {ARIA2_CONFIG_DIR}")
|
||||
except Exception as exc: # noqa: PERF203
|
||||
logger.error(f"删除配置目录失败: {exc}")
|
||||
logger.error(f"清空配置目录失败: {exc}")
|
||||
errors.append(exc)
|
||||
|
||||
try:
|
||||
|
||||
@@ -225,7 +225,7 @@ class Aria2RpcClient:
|
||||
return DownloadTask(
|
||||
gid=data.get("gid", ""),
|
||||
status=data.get("status", "unknown"),
|
||||
name=name[:40] if len(name) > 40 else name, # 截断文件名
|
||||
name=name, # 保留完整文件名,显示时再截断
|
||||
total_length=int(data.get("totalLength", 0)),
|
||||
completed_length=int(data.get("completedLength", 0)),
|
||||
download_speed=int(data.get("downloadSpeed", 0)),
|
||||
|
||||
@@ -778,7 +778,7 @@ class Aria2BotAPI:
|
||||
|
||||
local_path = Path(task.dir) / task.name
|
||||
if not local_path.exists():
|
||||
logger.error(f"频道上传失败:本地文件不存在 GID={gid}")
|
||||
logger.error(f"频道上传失败:本地文件不存在 GID={gid}, dir={task.dir}, name={task.name}, path={local_path}")
|
||||
return
|
||||
|
||||
# 检查文件大小
|
||||
|
||||
Reference in New Issue
Block a user