From 2e68b88fb256a120a8e93792e41ae57d02da7b8e Mon Sep 17 00:00:00 2001 From: yxzlwz Date: Sun, 5 Jan 2025 10:43:07 +0800 Subject: [PATCH] [fix] --- README.md | 2 +- setup.py | 2 +- src/cloudreve/models.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 827c2cd..e338b7e 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ pip3 install cloudreve ## 使用前说明 -- 本项目上传功能目前只适配了**本机存储**和**OneDrive存储**,有别的需求可以提PR。 +- 本项目理论上支持所有存储功能的下载,但上传功能目前只适配了**本机存储**和**OneDrive存储**,有别的需求可以提PR。 - 鉴于Cloudreve V3的诸多问题和已知V4不开源的消息,本人有意向重新维护一个多用户开源网盘项目,目前正在规划中,有意者欢迎通过页面底部联系方式与我交流! ## 示例 diff --git a/setup.py b/setup.py index 6e563b9..8c37d78 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name='cloudreve', - version='1.0.6', + version='1.0.7', package_dir={'': 'src'}, packages=find_packages(where='src'), include_package_data=True, diff --git a/src/cloudreve/models.py b/src/cloudreve/models.py index 8f3bdbe..3638e8d 100644 --- a/src/cloudreve/models.py +++ b/src/cloudreve/models.py @@ -156,6 +156,7 @@ def get_download_url(self, file_id) -> str: url = self.request('put', f'/file/download/{file_id}') if not url.startswith('http'): url = self.base_url + url + return url def download(self, file_id, save_path): ''' @@ -380,6 +381,33 @@ def upload_to_onedrive(self, local_file: Path, sessionID, chunkSize, ) self.request('post', f'/callback/onedrive/finish/{sessionID}', json={}) + def upload_to_oss( + self, + local_file: Path, + sessionID, + chunkSize, + expires, + uploadURLs, + completeURL, + **kwards, + ): + upload_url = uploadURLs[0] + file_size = local_file.stat().st_size + with open(local_file, 'rb') as file: + for i in range(0, file_size, chunkSize): + start = i + end = min(i + chunkSize, file_size) - 1 + r = request( + 'put', + upload_url, + headers={ + 'Content-Type': 'application/octet-stream', + 'Content-Range': f'bytes {start}-{end}/{file_size}', + }, + data=file.read(chunkSize), + ) + request('post', completeURL) + def upload(self, file_path, local_file_path, @@ -426,5 +454,10 @@ def upload(self, local_file=local_file, **r, ) + # elif policy_type == 'oss': + # return self.upload_to_oss( + # local_file=local_file, + # **r, + # ) else: raise ValueError(f'存储策略 {policy_type} 暂时不受支持,若有需求请在GitHub留言')