Skip to content

Commit a2f9e6e

Browse files
committed
fix: 修复下载权限问题并添加完整代理支持
- 修复 aria2 容器文件权限问题,设置 PUID/PGID=0 确保与 mynest 容器权限一致 - 在 download_service.go 中添加显式 chmod 操作,确保 aria2 可写入目录 - 为 mynest 和 aria2 服务添加完整代理环境变量配置 - 扩展 .env.example 配置模板,包含详细的代理配置说明和使用指南 - 支持 Telegram Bot API 和国际下载通过代理访问,同时排除内部服务通信
1 parent fd7d0e5 commit a2f9e6e

3 files changed

Lines changed: 64 additions & 9 deletions

File tree

.env.example

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,48 @@
1-
# PostgreSQL 配置
1+
# MyNest 环境变量配置示例
2+
3+
# ===================
4+
# 基础配置
5+
# ===================
6+
# 服务端口
7+
PORT=3001
8+
9+
# Docker 用户名和版本
10+
DOCKER_USERNAME=sunxiao0721
11+
VERSION=latest
12+
13+
# ===================
14+
# 数据库配置
15+
# ===================
216
POSTGRES_PASSWORD=mynest123
317

4-
# aria2 配置
18+
# ===================
19+
# Aria2 配置
20+
# ===================
521
ARIA2_SECRET=mynest123
22+
23+
# ===================
24+
# 目录配置
25+
# ===================
26+
# 下载目录(相对于 docker-compose.yml)
627
DOWNLOAD_DIR=./downloads
728

8-
# MyNest 服务端口
9-
PORT=3000
29+
# 日志目录(相对于 docker-compose.yml)
30+
LOG_DIR=./logs
31+
32+
# ===================
33+
# 代理配置(可选)
34+
# ===================
35+
# 如果需要代理访问外网,取消注释并填入你的代理地址
36+
# 支持 Telegram Bot API 和 Aria2 下载
37+
# HTTP_PROXY=http://127.0.0.1:7890
38+
# HTTPS_PROXY=http://127.0.0.1:7890
39+
40+
# 不需要代理的地址(保持默认即可)
41+
# NO_PROXY=localhost,127.0.0.1,postgres,aria2
1042

11-
# Docker 镜像配置(可选,默认从 Docker Hub 拉取)
12-
DOCKER_USERNAME=yourusername
13-
VERSION=latest
43+
# ===================
44+
# 使用说明
45+
# ===================
46+
# 1. 复制此文件为 .env: cp .env.example .env
47+
# 2. 根据需要修改配置项
48+
# 3. 启动服务: docker-compose up -d

backend/service/download_service.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ func (s *DownloadService) SubmitDownload(ctx context.Context, req types.Download
9898
log.Printf("[Download] Failed to create directory %s: %v", fullPath, err)
9999
} else {
100100
log.Printf("[Download] Created directory: %s", fullPath)
101+
// 确保 aria2 容器可以写入
102+
if err := os.Chmod(fullPath, 0755); err != nil {
103+
log.Printf("[Download] Failed to change directory permissions: %v", err)
104+
}
101105
}
102106
options["dir"] = fullPath
103107
log.Printf("[Download] Using dir mode: %s", fullPath)
@@ -111,6 +115,10 @@ func (s *DownloadService) SubmitDownload(ctx context.Context, req types.Download
111115
log.Printf("[Download] Failed to create directory %s: %v", fullDirPath, err)
112116
} else {
113117
log.Printf("[Download] Created directory: %s", fullDirPath)
118+
// 确保 aria2 容器可以写入
119+
if err := os.Chmod(fullDirPath, 0755); err != nil {
120+
log.Printf("[Download] Failed to change directory permissions: %v", err)
121+
}
114122
}
115123

116124
options["dir"] = fullDirPath

docker-compose.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ services:
2828
- LISTEN_PORT=6888
2929
- RPC_PORT=6800
3030
- UMASK_SET=022
31-
- PUID=1000
32-
- PGID=1000
31+
- PUID=0
32+
- PGID=0
3333
- RPC_LISTEN_ALL=true
34+
# 代理配置(可选)
35+
- HTTP_PROXY=${HTTP_PROXY:-}
36+
- HTTPS_PROXY=${HTTPS_PROXY:-}
37+
- http_proxy=${HTTP_PROXY:-}
38+
- https_proxy=${HTTPS_PROXY:-}
39+
- NO_PROXY=${NO_PROXY:-localhost,127.0.0.1}
3440
ports:
3541
- "6801:6800" # 外部访问端口
3642
- "6889:6888" # BT 端口
@@ -69,6 +75,12 @@ services:
6975
ARIA2_RPC_URL: http://aria2:6800/jsonrpc
7076
ARIA2_RPC_SECRET: ${ARIA2_SECRET:-mynest123}
7177
ARIA2_DOWNLOAD_DIR: /downloads
78+
# 代理配置(可选)
79+
HTTP_PROXY: ${HTTP_PROXY:-}
80+
HTTPS_PROXY: ${HTTPS_PROXY:-}
81+
http_proxy: ${HTTP_PROXY:-}
82+
https_proxy: ${HTTPS_PROXY:-}
83+
NO_PROXY: ${NO_PROXY:-localhost,127.0.0.1,postgres,aria2}
7284
volumes:
7385
- ${DOWNLOAD_DIR:-./downloads}:/downloads
7486
- ${LOG_DIR:-./logs}:/app/logs

0 commit comments

Comments
 (0)