Nanny7 commited on
Commit
587773e
·
1 Parent(s): 0a6678e

已修改

Browse files

server.py


引入 tempfile 模块,使用 tempfile.mkdtemp 在可写的临时目录下创建下载文件夹,避免权限问题。
不再使用仓库根目录的 downloads 目录。

Files changed (1) hide show
  1. server.py +4 -5
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
- save_path = "downloads"
34
- # 清理旧文件
35
- if os.path.exists(save_path):
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: