Fred808 commited on
Commit
252c8e0
·
verified ·
1 Parent(s): ceeca3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -6,6 +6,7 @@ from pathlib import Path
6
  from typing import Optional, Dict, Any
7
  import json
8
  from datetime import datetime
 
9
 
10
  class MiddlewareClient:
11
  def __init__(self, base_url: str = "https://fred808-vssee.hf.space"):
@@ -90,9 +91,8 @@ class MiddlewareClient:
90
  print(f"Error releasing image {file_id}: {e}")
91
 
92
  async def download_file(self, course: str, file_id: str) -> bool:
93
- """Download a file to local storage"""
94
  save_path = self.download_dir / course / file_id
95
- save_path.parent.mkdir(exist_ok=True)
96
 
97
  try:
98
  response = await self.client.get(
@@ -103,13 +103,14 @@ class MiddlewareClient:
103
 
104
  self.stats["downloads_started"] += 1
105
 
106
- async with await aiofiles.open(save_path, 'wb') as f:
107
  async for chunk in response.aiter_bytes():
108
  await f.write(chunk)
109
  self.stats["bytes_downloaded"] += len(chunk)
110
 
111
  self.stats["downloads_completed"] += 1
112
  return True
 
113
 
114
  except Exception as e:
115
  print(f"Error downloading {file_id}: {e}")
 
6
  from typing import Optional, Dict, Any
7
  import json
8
  from datetime import datetime
9
+ import aiofiles
10
 
11
  class MiddlewareClient:
12
  def __init__(self, base_url: str = "https://fred808-vssee.hf.space"):
 
91
  print(f"Error releasing image {file_id}: {e}")
92
 
93
  async def download_file(self, course: str, file_id: str) -> bool:
 
94
  save_path = self.download_dir / course / file_id
95
+ save_path.parent.mkdir(parents=True, exist_ok=True)
96
 
97
  try:
98
  response = await self.client.get(
 
103
 
104
  self.stats["downloads_started"] += 1
105
 
106
+ async with aiofiles.open(save_path, 'wb') as f:
107
  async for chunk in response.aiter_bytes():
108
  await f.write(chunk)
109
  self.stats["bytes_downloaded"] += len(chunk)
110
 
111
  self.stats["downloads_completed"] += 1
112
  return True
113
+ return True
114
 
115
  except Exception as e:
116
  print(f"Error downloading {file_id}: {e}")