Conversation
|
有个争议的点: 目前CAS信息只作用于天翼云一个网盘: |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 19a18e4ab8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR adds torrent/ed2k/magnet offline-download support and integrates Cloud189 (天翼云) CAS rapid-upload data into torrent workflows, including backend APIs for parsing/rapid-upload/generating torrents and driver-side hash/torrent generation during upload/transfer flows.
Changes:
- Added
/api/fs/torrent/*endpoints to parse torrents, rapid-upload from embedded CAS metadata, and generate torrents for existing files. - Introduced a new
pkg/torrentpackage (bencode + torrent structs + hashing/generation helpers) to encode/decode torrents and embedx-casextension data. - Enhanced offline-download tooling/189 drivers to handle ed2k routing/aria2 limitations and to compute SHA-1 piece hashes + generate torrents after uploads/transfers.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 16 comments.
Show a summary per file
| File | Description |
|---|---|
| server/router.go | Registers new torrent-related FS API routes. |
| server/handles/torrent.go | Implements torrent parse/upload-parse/rapid-upload/generate handlers. |
| pkg/torrent/bencode.go | Adds bencode encoder/decoder used by torrent parsing/generation. |
| pkg/torrent/torrent.go | Defines torrent/CAS structures and encode/decode + infohash helpers. |
| pkg/torrent/hash_writer.go | Adds streaming hash accumulator (MD5 + slice MD5 + SHA-1 piece hashes). |
| pkg/torrent/generate.go | Adds reader/file-based torrent generation helpers (with/without CAS). |
| internal/offline_download/tool/transfer.go | Adds Cloud189 rapid-upload attempt during transfer + async torrent generation. |
| internal/offline_download/tool/add.go | Adds SimpleHttp scheme rejection and ed2k tool auto-routing. |
| internal/offline_download/aria2/aria2.go | Adds explicit aria2 ed2k rejection with a clearer error. |
| drivers/189pc/utils.go | Computes SHA-1 piece hashes during stream upload and uploads generated .torrent. |
| drivers/189pc/torrent.go | Adds CAS-in-torrent generation + rapid-upload-from-torrent and CAS helpers. |
| drivers/189pc/meta.go | Adds generate_torrent driver config option. |
| drivers/189/util.go | Computes SHA-1 piece hashes during upload and attempts async torrent generation. |
| drivers/189/torrent.go | Adds CAS-in-torrent generation + rapid-upload-from-torrent and helpers for 189 driver. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot apply changes based on the comments in this thread |
|
@copilot resolve the merge conflicts in this pull request |
…ustness improvements - pkg/torrent/torrent.go: Fix GetMD5Str to return uppercase hex as documented - pkg/torrent/bencode.go: Add bounds check (0..100MB) before make([]byte, length) to prevent OOM - pkg/torrent/hash_writer.go: Validate sliceSize/pieceSize > 0 in NewHashWriter, default to DefaultPieceSize - server/handles/torrent.go: - Add 14MB limit on Base64 input to ParseTorrent (~10MB decoded) - Validate pieces length is multiple of 20 bytes per BT spec - Add read permission check (GetNearestMeta + CanRead) to GenerateTorrentForPath - Add 1GB file size limit to GenerateTorrentForPath - Restrict with_cas=true to 189pc storage only - Validate dstDir.IsDir() in TorrentRapidUpload - Map rapid-upload failures to HTTP 400 instead of 500 - internal/offline_download/tool/transfer.go: - Remove racy async generateTorrentForFile calls that raced with temp file deletion - Remove unused generateTorrentForFile function - Simplify tryRapidUpload189 to only compute fileMD5 (sliceMD5 was unused) - drivers/189pc/torrent.go: - Use cas.SliceSize from torrent instead of recomputing with partSize(fileSize) - Replace fmt.Printf with utils.Log for proper structured logging Agent-Logs-Url: https://github.com/OpenListTeam/OpenList/sessions/2752452f-b9e2-4f09-a5f0-837ea189aa28 Co-authored-by: PIKACHUIM <40362270+PIKACHUIM@users.noreply.github.com>
Head branch was pushed to by a user without write access
…t and named constant Agent-Logs-Url: https://github.com/OpenListTeam/OpenList/sessions/2752452f-b9e2-4f09-a5f0-837ea189aa28 Co-authored-by: PIKACHUIM <40362270+PIKACHUIM@users.noreply.github.com>
Applied all changes from the review thread in commits Security & correctness fixes:
Correctness fixes:
Race condition fix:
Cleanup:
|
Resolved conflicts in drivers/189/util.go: - Integrated main branch's rapid upload logic (compute MD5 upfront) - Preserved SHA-1 piece hash computation for torrent generation - Updated variable references to use fileMd5Hex from main branch - Captured necessary variables for async torrent generation goroutine Co-authored-by: PIKACHUIM <40362270+PIKACHUIM@users.noreply.github.com>
Resolved merge conflicts with main branch in commit Conflict resolution in
The merge maintains both features:
|
Description / 描述
支持BT种子文件/ED2K/磁力链离线下载,支持天翼云CAS秒传
功能支持项
ed2k://和magnet:?链接发起离线下载任务预期的逻辑
后端改动
新增文件
pkg/torrent/bencode.gopkg/torrent/torrent.gopkg/torrent/hash_writer.gopkg/torrent/generate.godrivers/189pc/torrent.godrivers/189/torrent.goserver/handles/torrent.go修改文件
drivers/189pc/meta.goGenerateTorrent配置选项drivers/189pc/utils.godrivers/189/util.gointernal/offline_download/tool/transfer.goserver/router.go新增 API
/api/fs/torrent/parse/api/fs/torrent/upload_parse/api/fs/torrent/rapid_upload/api/fs/torrent/generate前端改动
新增文件
src/types/torrent.tssrc/pages/home/toolbar/OfflineDownloadEnhanced.tsxsrc/pages/home/toolbar/TorrentFileList.tsx修改文件
src/types/index.tssrc/utils/api.tssrc/utils/bus.tstorrent_parsed事件类型src/pages/home/toolbar/operations.tsoffline_download_torrent操作图标src/pages/home/toolbar/Toolbar.tsxsrc/pages/home/folder/context-menu.tsxsrc/lang/en/home.jsonBT文件逻辑
graph TD A[上传文件] --> B[按 10MB 分片] B --> C[每片计算 MD5<br/>用于天翼云秒传] B --> D[每片计算 SHA-1<br/>用于 BT piece hash] C --> E[fileMD5 + sliceMD5] D --> F[pieces 字段] E --> G[x-cas 扩展<br/>存储在 info 外部] F --> H[info 字典] G --> I[生成 .torrent 文件] H --> I J[收到 .torrent] --> K{有 x-cas?} K -->|是| L[提取 fileMD5 + sliceMD5] L --> M[调用秒传接口] M --> N[文件恢复成功] K -->|否| O[需要下载后计算 MD5] O --> P[注入 CAS 信息到 torrent]离线下载完整流程
graph TD A[用户上传/选择 .torrent] --> B[解析 torrent] B --> C{有 CAS 信息?} C -->|是| D[直接 CAS 秒传<br/>不需要选择下载工具] D --> E{秒传成功?} E -->|是| F[完成 ✅] E -->|否| G[提示失败<br/>用户决定下一步] C -->|否| H[选择下载工具] H --> I[提交离线下载] I --> J[aria2/qBit 下载] J --> K[下载完成] K --> L{目标是天翼云?} L -->|是| M[计算 MD5 尝试秒传] M --> N{秒传成功?} N -->|是| F N -->|否| O[普通上传] O --> F L -->|否| OCAS 秒传接口说明
秒传使用新版
initMultiUpload接口(同时传fileMd5+sliceMd5+sliceSize),与正常上传使用的接口完全一致,确保能匹配到通过新版接口上传的文件。旧版createUploadFile.action接口作为回退方案。设计要点
pkg/torrent包不依赖任何驱动,所有存储均可使用initMultiUpload+commitMultiUploadFile接口,兼容新旧上传方式Motivation and Context / 背景
实现 BT 种子生态与网盘秒传的融合,使得:
How Has This Been Tested? / 测试
Checklist / 检查清单
go fmtor prettier.我已使用
go fmt或 prettier 格式化提交的代码。我已为此 PR 添加了适当的标签(如无权限或需要的标签不存在,请在描述中说明,管理员将后续处理)。
我已在适当情况下使用"Request review"功能请求相关代码作者进行审查。
我已阅读 CONTRIBUTING 文档。
我已相应更新了相关仓库(若适用)。