Conversation
- 将 category 字段改为 readonly,提升不可变性 - 优化 PingAsync 返回逻辑,提升可读性 - tag_ids 使用集合展开语法,简化代码 - 上传种子时增加 team_id 字段,完善请求参数
重构 BangumiAdapter.cs,将原先的种子文件单独上传与发布两步流程合并为一步,直接通过 MultipartFormDataContent 一次性提交所有表单数据和种子文件,删除了 UploadTorrent 方法。调整表单字段构造方式,tag_ids 改为逗号分隔字符串,新增 btskey 字段,teamsync 字段改为字符串 "0"。简化流程,减少 HTTP 请求,提高效率。
There was a problem hiding this comment.
Pull request overview
This PR refactors BangumiAdapter torrent posting to send the torrent file and metadata in a single multipart form submission, removing the prior upload-then-post flow.
Changes:
- Switch
PostAsynctoMultipartFormDataContentsubmission (file + fields) instead of JSONAddRequestwith a separate upload step. - Make
categoryimmutable (readonly) and apply minor formatting tweaks inPingAsync.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -16,7 +16,7 @@ internal class BangumiAdapter : AdapterBase | |||
| private const string pingUrl = "team/myteam"; | |||
| private const string postUrl = "torrent/add"; | |||
| private const string uploadUrl = "v2/torrent/upload"; | |||
There was a problem hiding this comment.
uploadUrl is now unused after removing UploadTorrent, which will trigger an unused-field warning (and can fail builds if warnings are treated as errors). Remove the constant (or reintroduce usage if still needed).
| private const string uploadUrl = "v2/torrent/upload"; |
| private string category; | ||
| private readonly string category; | ||
| private string teamID = ""; | ||
| private string tagID = ""; // string[]? |
There was a problem hiding this comment.
tagID is assigned in PingAsync but never used. If Bangumi requires the team tag id to be included in the post (in addition to team_id), incorporate it into the tags you submit; otherwise remove the unused field/assignment to avoid dead code and confusion.
| private string tagID = ""; // string[]? |
| var response = await httpClient.PostAsyncWithRetry(postUrl, form); | ||
| var raw = await response.Content.ReadAsStringAsync(); | ||
| var result = await response.Content.ReadFromJsonAsync(BangumiModelsSourceGenerationContext.Default.AddResponse); | ||
| if (!response.IsSuccessStatusCode || result == null) |
There was a problem hiding this comment.
The previous implementation had an explicit wait+retry to handle Bangumi's posting frequency limit. With the single-step post, any rate-limit response that isn't a transient HTTP error (e.g., HTTP 429 or a 200 response with success=false) will now fail immediately. Consider adding async backoff + retry logic around this PostAsyncWithRetry call / the subsequent success check for known rate-limit responses.
This pull request refactors the
BangumiAdapterclass to simplify and modernize how torrent posting works, particularly by switching from a two-step upload-post process to a single multipart form submission. It also introduces minor code improvements for immutability and clarity.Refactor and simplification of torrent posting:
MultipartFormDataContentform submission inPostAsync, sending both the file and metadata together. This removes the need for theUploadTorrentmethod and streamlines the posting logic. [1] [2]tag_ids) instead of an array, and adds a new"btskey"field with value"undefined"to the post form.Code quality improvements:
categoryfieldreadonlyfor better immutability and thread safety.PingAsyncfor clarity and consistency.