Skip to content

Commit

Permalink
[fix]
Browse files Browse the repository at this point in the history
  • Loading branch information
yxzlwz committed Jan 5, 2025
1 parent e597bce commit 2e68b88
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pip3 install cloudreve

## 使用前说明

- 本项目上传功能目前只适配了**本机存储****OneDrive存储**,有别的需求可以提PR。
- 本项目理论上支持所有存储功能的下载,但上传功能目前只适配了**本机存储****OneDrive存储**,有别的需求可以提PR。
- 鉴于Cloudreve V3的诸多问题和已知V4不开源的消息,本人有意向重新维护一个多用户开源网盘项目,目前正在规划中,有意者欢迎通过页面底部联系方式与我交流!

## 示例
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
33 changes: 33 additions & 0 deletions src/cloudreve/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
'''
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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留言')

0 comments on commit 2e68b88

Please sign in to comment.