Skip to content

Commit

Permalink
download file bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
benben17 committed May 15, 2024
1 parent e00acd7 commit 1c7127d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
10 changes: 5 additions & 5 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ PORT=6000
SECRET_KEY="ae6xxxxxaf4f90de0bb"
APPID="xxx" # 微信小程序id
APPSECRET= # 微信小程序密钥
MAIL_USERNAME=[email protected] # 发件邮箱用户名
MAIL_PASSWORD=xxxx # 发件邮箱密码 注意申请客户端授权码
MAIL_USERNAME=[email protected]# 发件邮箱用户名
MAIL_PASSWORD=xxxx# 发件邮箱密码 注意申请客户端授权码
MAIL_DEFAULT_SENDER='"rss2ebook"<[email protected]>'
MAIL_ATT_MAX_SIZE=20 # 设置附件大小 单位M
MAIL_ATT_MAX_SIZE=20# 设置附件大小 单位M

RSS2EBOOK_KEY= # key

GOOGLE_ID=xxx-.apps.googleusercontent.com # google id
GOOGLE_SEARCH_KEY=xxx-xxx # google search key
GOOGLE_ID=xxx-.apps.googleusercontent.com# google id
GOOGLE_SEARCH_KEY=xxx-xxx# google search key
UPGRADE_USER_URL= # 升级用户url
58 changes: 29 additions & 29 deletions book/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,35 +162,35 @@ def download_net_book(ipfs_cid, filename):
if os.path.exists(file_path) and os.path.getsize(file_path) > 0:
return file_path

# url_list = [
# 'https://dweb.link',
# 'https://cloudflare-ipfs.com',
# 'https://gateway.pinata.cloud',
# 'https://gateway.ipfs.io',
# 'https://ipfs.joaoleitao.org',
# 'https://cf-ipfs.com',
# 'https://hardbin.com'
# ]
file_download_url = 'https://netfile.rss2ebook.com'
# for url in url_list:
full_url = f"{file_download_url}/ipfs/{ipfs_cid}?filename={filename}"
for attempt in range(3):
try:
response = requests.get(full_url, stream=True, timeout=30)
response.raise_for_status() # Raise exception if response status code is not 200

with open(file_path, 'wb') as f:
for data in response.iter_content(chunk_size=2048):
f.write(data)
logging.info(f"{filename}:File downloaded successfully")
return file_path
except RequestException as e:
logging.error(f"Error downloading from {full_url} on attempt {attempt + 1}: {e}")
if attempt == 2: # If this was the last attempt
return None
time.sleep(5)
# logging.error(f"{filename} Could not download file from any of the URLs provided")
# return None
url_list = [
'https://dweb.link',
'https://cloudflare-ipfs.com',
'https://gateway.pinata.cloud',
'https://gateway.ipfs.io',
'https://ipfs.joaoleitao.org',
'https://cf-ipfs.com',
'https://hardbin.com'
]
# file_download_url = 'https://netfile.rss2ebook.com'
for url in url_list:
full_url = f"{url}/ipfs/{ipfs_cid}?filename={filename}"
for attempt in range(3):
try:
response = requests.get(full_url, stream=True, timeout=30)
response.raise_for_status() # Raise exception if response status code is not 200

with open(file_path, 'wb') as f:
for data in response.iter_content(chunk_size=2048):
f.write(data)
logging.info(f"{filename}:File downloaded successfully")
return file_path
except RequestException as e:
logging.error(f"Error downloading from {full_url} on attempt {attempt + 1}: {e}")
if attempt == 2: # If this was the last attempt
return None
time.sleep(5)
# logging.error(f"{filename} Could not download file from any of the URLs provided")
# return None


def is_file_24_hours(file_path):
Expand Down

0 comments on commit 1c7127d

Please sign in to comment.