Skip to content

Commit

Permalink
fix #65,#68,69
Browse files Browse the repository at this point in the history
  • Loading branch information
zaxtyson committed Dec 30, 2021
1 parent b49dd2f commit 5b9624f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
## `v2.6.6`

- 修复 pickle 库反序列化导致内存溢出的问题[#65](https://github.com/zaxtyson/LanZouCloud-API/issues/65)
- 更换为最新域名, 防止解析失败[#68](https://github.com/zaxtyson/LanZouCloud-API/pull/68)

## `v2.6.5`

Expand Down
2 changes: 1 addition & 1 deletion lanzou/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from lanzou.api.core import LanZouCloud

version = '2.6.5.1'
version = '2.6.6'

__all__ = ['utils', 'types', 'models', 'LanZouCloud', 'version']
16 changes: 8 additions & 8 deletions lanzou/api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self):
self._timeout = 15 # 每个请求的超时(不包含下载响应体的用时)
self._max_size = 100 # 单个文件大小上限 MB
self._upload_delay = (0, 0) # 文件上传延时
self._host_url = 'https://pan.lanzoui.com'
self._host_url = 'https://pan.lanzouo.com'
self._doupload_url = 'https://pc.woozooo.com/doupload.php'
self._account_url = 'https://pc.woozooo.com/account.php'
self._mydisk_url = 'https://pc.woozooo.com/mydisk.php'
Expand Down Expand Up @@ -83,11 +83,11 @@ def _post(self, url, data, **kwargs):
def _all_possible_urls(url: str) -> List[str]:
"""蓝奏云的主域名有时会挂掉, 此时尝试切换到备用域名"""
available_domains = [
'lanzoui.com', # 鲁ICP备15001327号-6, 2020-06-09, SEO 排名最低
'lanzoux.com', # 鲁ICP备15001327号-5, 2020-06-09
'lanzous.com' # 主域名, 备案异常, 部分地区已经无法访问
'lanzouw.com', # 鲁ICP备15001327号-7, 2021-09-02
'lanzoui.com', # 鲁ICP备15001327号-6, 2020-06-09
'lanzoux.com' # 鲁ICP备15001327号-5, 2020-06-09
]
return [url.replace('lanzous.com', d) for d in available_domains]
return [url.replace('lanzouo.com', d) for d in available_domains]

def ignore_limits(self):
"""解除官方限制"""
Expand Down Expand Up @@ -1046,14 +1046,13 @@ def down_file_by_url(self, share_url, pwd='', save_path='./Download', *, callbac
f.seek(-512, os.SEEK_END)
last_512_bytes = f.read()
file_info = un_serialize(last_512_bytes)
# Python3.6 序列化时默认使用 pickle 第三版协议,
# 导致计算时文件尾部多写了 5 字节, 保险期起见处理一下
# Python3.7 序列化时默认使用 pickle 第三版协议,
# 导致计算时文件尾部多写了 5 字节, 应该都是用3.8, 保险期起见处理一下
if not file_info:
is_protocol_3 = True
f.seek(-517, os.SEEK_END)
last_517_bytes = f.read()
file_info = un_serialize(last_517_bytes)


# 大文件的记录文件也可以反序列化出 name,但是没有 padding 字段
if file_info is not None and 'padding' in file_info:
Expand All @@ -1069,6 +1068,7 @@ def down_file_by_url(self, share_url, pwd='', save_path='./Download', *, callbac
# 截断最后 512 字节隐藏信息, 还原文件
with open(new_file_path, 'rb+') as f:
truncate_size = 517 if is_protocol_3 else 512
logger.debug(f"Truncate last {truncate_size} bytes of file")
f.seek(-truncate_size, os.SEEK_END)
f.truncate()
file_path = new_file_path # 保存文件重命名后真实路径
Expand Down
10 changes: 5 additions & 5 deletions lanzou/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def is_name_valid(filename: str) -> bool:

def is_file_url(share_url: str) -> bool:
"""判断是否为文件的分享链接"""
base_pat = r'https?://[a-zA-Z0-9-]*?\.?lanzou[six].com/.+' # 子域名可个性化设置或者不存在
user_pat = r'https?://[a-zA-Z0-9-]*?\.?lanzou[six].com/i[a-zA-Z0-9]{5,}/?' # 普通用户 URL 规则
base_pat = r'https?://[a-zA-Z0-9-]*?\.?lanzou[a-z].com/.+' # 子域名可个性化设置或者不存在
user_pat = r'https?://[a-zA-Z0-9-]*?\.?lanzou[a-z].com/i[a-zA-Z0-9]{5,}/?' # 普通用户 URL 规则
if not re.fullmatch(base_pat, share_url):
return False
elif re.fullmatch(user_pat, share_url):
Expand All @@ -95,8 +95,8 @@ def is_file_url(share_url: str) -> bool:

def is_folder_url(share_url: str) -> bool:
"""判断是否为文件夹的分享链接"""
base_pat = r'https?://[a-zA-Z0-9-]*?\.?lanzou[six].com/.+'
user_pat = r'https?://[a-zA-Z0-9-]*?\.?lanzou[six].com/(/s/)?b[a-zA-Z0-9]{7,}/?'
base_pat = r'https?://[a-zA-Z0-9-]*?\.?lanzou[a-z].com/.+'
user_pat = r'https?://[a-zA-Z0-9-]*?\.?lanzou[a-z].com/(/s/)?b[a-zA-Z0-9]{7,}/?'
if not re.fullmatch(base_pat, share_url):
return False
elif re.fullmatch(user_pat, share_url):
Expand Down Expand Up @@ -198,7 +198,7 @@ def let_me_upload(file_path):
chunk = in_f.read(4096)
# 构建文件 "报尾" 保存真实文件名,大小 512 字节
# 追加数据到文件尾部,并不会影响文件的使用,无需修改即可分享给其他人使用,自己下载时则会去除,确保数据无误
# protocol=4py3.8默认), 序列化后空字典占 42 字节
# protocol=4(py3.8默认), 序列化后空字典占 42 字节
padding = 512 - len(file_name.encode('utf-8')) - 42
data = {'name': file_name, 'padding': b'\x00' * padding}
data = pickle.dumps(data, protocol=4)
Expand Down

0 comments on commit 5b9624f

Please sign in to comment.