feat(drivers): add Xiaomi Cloud Dirve#1391
feat(drivers): add Xiaomi Cloud Dirve#1391antecanis8 wants to merge 1 commit intoOpenListTeam:mainfrom
Conversation
目前存在的问题: 大文件获取到的下载链接过长 无法下载 从api获取到的分块下载地址是否能用 部分api还是旧版 是否需要都更换为v2 获取存储详情和移动文件 还未实现 目前只做了302代理的下载 本机代理未实现 新增的依赖是否可以精简
There was a problem hiding this comment.
Pull Request Overview
This PR implements a new Xiaomi Cloud Drive driver for the OpenList project. The implementation supports file listing, downloading, uploading, and folder management through Xiaomi Cloud's API.
- Adds complete MiCloud driver with authentication, file operations, and upload/download functionality
- Implements automatic token renewal to maintain session validity
- Provides file streaming, folder creation, and deletion capabilities
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| go.mod | Adds gjson library dependencies for JSON parsing |
| drivers/micloud/util.go | Core API client implementation with HTTP operations and file management |
| drivers/micloud/types.go | Data structures and API endpoints for MiCloud integration |
| drivers/micloud/meta.go | Driver configuration and registration setup |
| drivers/micloud/driver.go | Main driver interface implementation with OpenList integration |
| drivers/all.go | Registers the new MiCloud driver in the system |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| } | ||
| // 若服务端下发新 cookie,则更新 | ||
| c.updateCookiesFromResponse(resp) | ||
| io.Copy(io.Discard, resp.Body) |
There was a problem hiding this comment.
The error from io.Copy is ignored, which could mask potential issues. Consider logging or handling the error appropriately.
| return nil, 0, err | ||
| } | ||
| buf = buf[:n] | ||
| req, _ := http.NewRequest("POST", uploadURL, strings.NewReader(string(buf))) |
There was a problem hiding this comment.
Error from http.NewRequest is ignored using blank identifier. This could cause unexpected behavior if the request creation fails.
| req, _ := http.NewRequest("POST", uploadURL, strings.NewReader(string(buf))) | |
| req, err := http.NewRequest("POST", uploadURL, strings.NewReader(string(buf))) | |
| if err != nil { | |
| return nil, 0, err | |
| } |
| return nil, 0, err | ||
| } | ||
| defer resp.Body.Close() | ||
| body, _ := io.ReadAll(resp.Body) |
There was a problem hiding this comment.
Error from io.ReadAll is ignored using blank identifier. This could lead to incomplete data being processed without notification.
| body, _ := io.ReadAll(resp.Body) | |
| body, err := io.ReadAll(resp.Body) | |
| if err != nil { | |
| return nil, 0, fmt.Errorf("failed to read response body: %w", err) | |
| } |
| // 由于json包在类型定义中没有直接使用,但可能在方法中需要,我们保留它 | ||
| // 实际上json包在MiCloudClient的实现中使用了,所以保留 |
There was a problem hiding this comment.
These comments are outdated and confusing since no json package is imported in this file. The comments should be removed or clarified.
| // 由于json包在类型定义中没有直接使用,但可能在方法中需要,我们保留它 | |
| // 实际上json包在MiCloudClient的实现中使用了,所以保留 |
| // 直链下载已使用 v2 接口实现,去除 JSONP 下载方式 | ||
|
|
||
| // GetFileDownLoadUrl 获取文件下载URL |
There was a problem hiding this comment.
This comment appears to be a placeholder or outdated note that doesn't describe the following function. It should be removed or updated to properly document the GetFileDownLoadUrl function.
| // 直链下载已使用 v2 接口实现,去除 JSONP 下载方式 | |
| // GetFileDownLoadUrl 获取文件下载URL | |
| // GetFileDownLoadUrl 获取指定文件的直链下载URL。 | |
| // | |
| // 参数 fileId 为文件的唯一标识符。该方法使用 v2 接口获取文件的直链下载地址, | |
| // 并已去除旧的 JSONP 下载方式。返回下载URL字符串和可能的错误信息。 |
| return dl, nil | ||
| } | ||
|
|
||
| // JSONP 下载信息方法已废弃 |
There was a problem hiding this comment.
This standalone comment doesn't provide context and appears to be leftover from code refactoring. It should be removed.
| // JSONP 下载信息方法已废弃 |
| } | ||
|
|
||
| // 上传小文件(小于4MB) | ||
| // uploadSmallFile/uploadLargeFile paths were deprecated and removed. The unified Upload handles both cases. |
There was a problem hiding this comment.
These orphaned comments don't document any actual code and appear to be leftover from refactoring. They should be removed.
| // uploadSmallFile/uploadLargeFile paths were deprecated and removed. The unified Upload handles both cases. |
|
什么?小米有云盘? |
有,云服务里的,纯云盘,没有分享之类的能力 |
|
目前小米云盘的网页使用jsonp方式跨域获取下载地址 电脑客户端直接获取直链下载地址和分块下载地址 4MB一个块 下载地址需要接受一个meta作为校验 当要下载的文件较小时 meta可以作为get请求的参数 当要下载的文件很大时 meta会超出 get请求的 URL 长度限制 必须作为post请求的表单 对于795MB的文件 meta有34.8KB 总结:小文件才能使用302下载 大文件必须代理 |
|
那就直接全部使用代理吧,这样可以保证功能一致性 |
还没写完
已经实现:
list
link
put
mkdir
目前存在的问题:
大文件获取到的下载链接过长 无法下载
从api获取到的分块下载地址是否能用
部分api还是旧版 是否需要都更换为v2
获取存储详情和移动文件 还未实现
目前只做了302代理的下载 本机代理未实现
新增的依赖是否可以精简
Description / 描述
小米云盘驱动😎
Motivation and Context / 背景
为什么一直没人做🧐
api参考 github.com/wangbjun/go-micloud
How Has This Been Tested? / 测试
Checklist / 检查清单
我已阅读 CONTRIBUTING 文档。
go fmtor prettier.我已使用
go fmt或 prettier 格式化提交的代码。我已为此 PR 添加了适当的标签(如无权限或需要的标签不存在,请在描述中说明,管理员将后续处理)。
我已在适当情况下使用"Request review"功能请求相关代码作者进行审查。
我已相应更新了相关仓库(若适用)。