tecuts commited on
Commit
6c4045b
·
verified ·
1 Parent(s): 058a4f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -1,5 +1,5 @@
1
  # app.py
2
- from fastapi import FastAPI, HTTPException
3
  from fastapi.staticfiles import StaticFiles
4
  from pydantic import BaseModel
5
  import subprocess
@@ -65,15 +65,15 @@ app = FastAPI(
65
  version="1.0.0"
66
  )
67
 
 
68
  # Create downloads directory if it doesn't exist
69
  DOWNLOADS_DIR = "downloads"
70
  os.makedirs(DOWNLOADS_DIR, exist_ok=True)
71
 
72
-
73
  # Mount the downloads directory with cache control headers
74
  class CacheControlStaticFiles(StaticFiles):
75
- def __init__(self, directory: str, name: str = None):
76
- super().__init__(directory=directory, name=name)
77
 
78
  async def get_response(self, path: str, scope):
79
  response = await super().get_response(path, scope)
@@ -94,6 +94,7 @@ class DownloadResponse(BaseModel):
94
  download_url: str = None
95
  file_size: int = None # Include file size in the response
96
 
 
97
  @app.post("/download", response_model=DownloadResponse)
98
  async def download_file(request: DownloadRequest):
99
  try:
@@ -147,7 +148,7 @@ async def download_file(request: DownloadRequest):
147
  file_size = os.path.getsize(downloaded_file)
148
 
149
  # Generate the download URL and URL encode the filename
150
- space_url = os.getenv("SPACE_URL", "https://tecuts-vob.hf.space/")
151
  encoded_filename = quote(downloaded_file) # URL encode the filename
152
  download_url = f"{space_url}/files/{timestamp}/{encoded_filename}"
153
  logger.info(f"Generated download URL: {download_url}")
 
1
  # app.py
2
+ from fastapi import FastAPI, HTTPException, Response
3
  from fastapi.staticfiles import StaticFiles
4
  from pydantic import BaseModel
5
  import subprocess
 
65
  version="1.0.0"
66
  )
67
 
68
+
69
  # Create downloads directory if it doesn't exist
70
  DOWNLOADS_DIR = "downloads"
71
  os.makedirs(DOWNLOADS_DIR, exist_ok=True)
72
 
 
73
  # Mount the downloads directory with cache control headers
74
  class CacheControlStaticFiles(StaticFiles):
75
+ def __init__(self, directory: str):
76
+ super().__init__(directory=directory)
77
 
78
  async def get_response(self, path: str, scope):
79
  response = await super().get_response(path, scope)
 
94
  download_url: str = None
95
  file_size: int = None # Include file size in the response
96
 
97
+
98
  @app.post("/download", response_model=DownloadResponse)
99
  async def download_file(request: DownloadRequest):
100
  try:
 
148
  file_size = os.path.getsize(downloaded_file)
149
 
150
  # Generate the download URL and URL encode the filename
151
+ space_url = os.getenv("SPACE_URL", "https://tecuts-vob.hf.space")
152
  encoded_filename = quote(downloaded_file) # URL encode the filename
153
  download_url = f"{space_url}/files/{timestamp}/{encoded_filename}"
154
  logger.info(f"Generated download URL: {download_url}")