Skip to content

Commit

Permalink
修复方法一获取文件时有时候出现的没有正常解码 url编码 的问题;将方法4获取文件名时的时间戳改为ns时间戳,以解决文件名重复的问题(#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoYouChR committed Nov 20, 2024
1 parent 6cb71c4 commit 1416946
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/common/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from datetime import datetime, timedelta, timezone
from email.utils import decode_rfc2231
from functools import wraps
from time import sleep, localtime, time
from time import sleep, localtime, time_ns
from urllib.parse import unquote, parse_qs, urlparse

import httpx
Expand Down Expand Up @@ -214,6 +214,7 @@ def getLinkInfo(url:str, headers:dict, fileName:str="", verify:bool=False, proxy
match = re.search(r'filename\s*=\s*["\']?([^"\';]+)["\']?', headerValue, re.IGNORECASE)
if match:
fileName = match.group(1)
fileName = urllib.parse.unquote(fileName)

# 移除文件名头尾可能存在的引号
if fileName:
Expand Down Expand Up @@ -256,7 +257,7 @@ def getLinkInfo(url:str, headers:dict, fileName:str="", verify:bool=False, proxy
# 什么都 Get 不到的情况
logger.info(f"获取文件名失败, 错误:{e}")
content_type = head["content-type"].split('/')[-1]
fileName = f"downloaded_file{int(time())}.{content_type}"
fileName = f"downloaded_file{int(time_ns())}.{content_type}"
logger.debug(f"方法4获取文件名成功, 文件名:{fileName}")

return url, fileName, fileSize

0 comments on commit 1416946

Please sign in to comment.