已修改
Browse filesserver.py
:
引入 tempfile 模块,使用 tempfile.mkdtemp 在可写的临时目录下创建下载文件夹,避免权限问题。
不再使用仓库根目录的 downloads 目录。
server.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from fastapi import FastAPI, HTTPException
|
| 2 |
from fastapi.responses import FileResponse, HTMLResponse
|
| 3 |
import os, shutil, glob
|
|
|
|
| 4 |
from main import Run
|
| 5 |
|
| 6 |
app = FastAPI(
|
|
@@ -30,11 +31,9 @@ def root():
|
|
| 30 |
|
| 31 |
@app.get("/download")
|
| 32 |
def download(book_id: str):
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
shutil.rmtree(save_path)
|
| 37 |
-
os.makedirs(save_path, exist_ok=True)
|
| 38 |
|
| 39 |
# 调用下载核心
|
| 40 |
try:
|
|
|
|
| 1 |
from fastapi import FastAPI, HTTPException
|
| 2 |
from fastapi.responses import FileResponse, HTMLResponse
|
| 3 |
import os, shutil, glob
|
| 4 |
+
import tempfile
|
| 5 |
from main import Run
|
| 6 |
|
| 7 |
app = FastAPI(
|
|
|
|
| 31 |
|
| 32 |
@app.get("/download")
|
| 33 |
def download(book_id: str):
|
| 34 |
+
# 在临时目录创建下载文件夹
|
| 35 |
+
save_path = tempfile.mkdtemp(prefix="tomato_")
|
| 36 |
+
# mkdtemp 已创建空目录,无需清理
|
|
|
|
|
|
|
| 37 |
|
| 38 |
# 调用下载核心
|
| 39 |
try:
|