Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,7 @@ import tempfile
|
|
| 11 |
from pathlib import Path
|
| 12 |
from dotenv import load_dotenv
|
| 13 |
from urllib.parse import quote
|
|
|
|
| 14 |
|
| 15 |
# Set up logging
|
| 16 |
logging.basicConfig(level=logging.INFO)
|
|
@@ -69,6 +70,8 @@ app = FastAPI(
|
|
| 69 |
|
| 70 |
|
| 71 |
|
|
|
|
|
|
|
| 72 |
# Create downloads directory if it doesn't exist
|
| 73 |
DOWNLOADS_DIR = "downloads"
|
| 74 |
TEMP_DIR = "temp"
|
|
@@ -149,13 +152,16 @@ async def download_file(request: DownloadRequest):
|
|
| 149 |
downloaded_file = files[0]
|
| 150 |
logger.info(f"Downloaded file: {downloaded_file}")
|
| 151 |
|
|
|
|
|
|
|
|
|
|
| 152 |
# Get the file size
|
| 153 |
file_size = os.path.getsize(downloaded_file)
|
| 154 |
|
| 155 |
-
# Check for
|
| 156 |
if process.stderr:
|
| 157 |
raise Exception(f"Error in downloaded file: {process.stderr}")
|
| 158 |
-
|
| 159 |
# Move the completed download to the final directory
|
| 160 |
final_download_subdir = os.path.join(DOWNLOADS_DIR, timestamp)
|
| 161 |
os.makedirs(final_download_subdir, exist_ok=True)
|
|
|
|
| 11 |
from pathlib import Path
|
| 12 |
from dotenv import load_dotenv
|
| 13 |
from urllib.parse import quote
|
| 14 |
+
import time
|
| 15 |
|
| 16 |
# Set up logging
|
| 17 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
+
|
| 74 |
+
|
| 75 |
# Create downloads directory if it doesn't exist
|
| 76 |
DOWNLOADS_DIR = "downloads"
|
| 77 |
TEMP_DIR = "temp"
|
|
|
|
| 152 |
downloaded_file = files[0]
|
| 153 |
logger.info(f"Downloaded file: {downloaded_file}")
|
| 154 |
|
| 155 |
+
# Ensure the file is fully written
|
| 156 |
+
time.sleep(1) # Sleep for 1 second
|
| 157 |
+
|
| 158 |
# Get the file size
|
| 159 |
file_size = os.path.getsize(downloaded_file)
|
| 160 |
|
| 161 |
+
# Check for potential issues in file handling
|
| 162 |
if process.stderr:
|
| 163 |
raise Exception(f"Error in downloaded file: {process.stderr}")
|
| 164 |
+
|
| 165 |
# Move the completed download to the final directory
|
| 166 |
final_download_subdir = os.path.join(DOWNLOADS_DIR, timestamp)
|
| 167 |
os.makedirs(final_download_subdir, exist_ok=True)
|