已将下载根目录切换到系统临时文件夹,避免在只读环境下创建 downloads 文件夹:
Browse files定义 DOWNLOAD_ROOT = os.path.join(tempfile.gettempdir(), "tomato_downloads")
在 /tmp 下创建并挂载为静态目录
修改后台队列 save_path 指向 DOWNLOAD_ROOT
现在不再使用容器根目录,权限问题已解决。
- __pycache__/main.cpython-313.pyc +0 -0
- __pycache__/server.cpython-313.pyc +0 -0
- server.py +16 -4
__pycache__/main.cpython-313.pyc
ADDED
|
Binary file (29 kB). View file
|
|
|
__pycache__/server.cpython-313.pyc
ADDED
|
Binary file (10.2 kB). View file
|
|
|
server.py
CHANGED
|
@@ -19,7 +19,7 @@ def process_queue():
|
|
| 19 |
while True:
|
| 20 |
book_id = TASK_QUEUE.get()
|
| 21 |
STATUS[book_id] = "in-progress"
|
| 22 |
-
save_path = os.path.join(
|
| 23 |
os.makedirs(save_path, exist_ok=True)
|
| 24 |
try:
|
| 25 |
fetch_api_endpoints_from_server()
|
|
@@ -42,9 +42,10 @@ app = FastAPI(
|
|
| 42 |
description="通过 /download?book_id=xxx 获取小说文本文件",
|
| 43 |
)
|
| 44 |
|
| 45 |
-
# 挂载本地下载目录并创建文件夹
|
| 46 |
-
os.
|
| 47 |
-
|
|
|
|
| 48 |
|
| 49 |
# 启动后台下载处理线程
|
| 50 |
@app.on_event("startup")
|
|
@@ -59,8 +60,18 @@ def root():
|
|
| 59 |
<head>
|
| 60 |
<meta charset=\"UTF-8\">
|
| 61 |
<title>番茄小说下载器</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
</head>
|
| 63 |
<body>
|
|
|
|
| 64 |
<h1>番茄小说下载器</h1>
|
| 65 |
<label for=\"book_ids\">小说ID列表(逗号或空格分隔):</label><br/>
|
| 66 |
<textarea id=\"book_ids\" rows=\"4\" cols=\"50\"></textarea><br/>
|
|
@@ -111,6 +122,7 @@ def root():
|
|
| 111 |
});
|
| 112 |
});
|
| 113 |
</script>
|
|
|
|
| 114 |
</body>
|
| 115 |
</html>
|
| 116 |
"""
|
|
|
|
| 19 |
while True:
|
| 20 |
book_id = TASK_QUEUE.get()
|
| 21 |
STATUS[book_id] = "in-progress"
|
| 22 |
+
save_path = os.path.join(DOWNLOAD_ROOT, book_id)
|
| 23 |
os.makedirs(save_path, exist_ok=True)
|
| 24 |
try:
|
| 25 |
fetch_api_endpoints_from_server()
|
|
|
|
| 42 |
description="通过 /download?book_id=xxx 获取小说文本文件",
|
| 43 |
)
|
| 44 |
|
| 45 |
+
# 挂载本地下载目录并创建文件夹 (使用临时目录)
|
| 46 |
+
DOWNLOAD_ROOT = os.path.join(tempfile.gettempdir(), "tomato_downloads")
|
| 47 |
+
os.makedirs(DOWNLOAD_ROOT, exist_ok=True)
|
| 48 |
+
app.mount("/files", StaticFiles(directory=DOWNLOAD_ROOT), name="files")
|
| 49 |
|
| 50 |
# 启动后台下载处理线程
|
| 51 |
@app.on_event("startup")
|
|
|
|
| 60 |
<head>
|
| 61 |
<meta charset=\"UTF-8\">
|
| 62 |
<title>番茄小说下载器</title>
|
| 63 |
+
<style>
|
| 64 |
+
body { background: url("https://bing.img.run/uhd.php") no-repeat center center fixed; background-size: cover; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; color: #fff; margin: 0; padding: 0; }
|
| 65 |
+
.container { background: rgba(0, 0, 0, 0.6); max-width: 800px; margin: 50px auto; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.5); }
|
| 66 |
+
textarea, button { width: 100%; font-size: 16px; margin-top: 10px; padding: 10px; border-radius: 4px; border: none; }
|
| 67 |
+
button { background: #ff5722; color: #fff; cursor: pointer; }
|
| 68 |
+
button:hover { background: #e64a19; }
|
| 69 |
+
progress { width: 100%; margin-top: 10px; }
|
| 70 |
+
a.download-link { color: #ffcc00; text-decoration: none; display: block; margin-top: 10px; }
|
| 71 |
+
</style>
|
| 72 |
</head>
|
| 73 |
<body>
|
| 74 |
+
<div class="container">
|
| 75 |
<h1>番茄小说下载器</h1>
|
| 76 |
<label for=\"book_ids\">小说ID列表(逗号或空格分隔):</label><br/>
|
| 77 |
<textarea id=\"book_ids\" rows=\"4\" cols=\"50\"></textarea><br/>
|
|
|
|
| 122 |
});
|
| 123 |
});
|
| 124 |
</script>
|
| 125 |
+
</div>
|
| 126 |
</body>
|
| 127 |
</html>
|
| 128 |
"""
|