Skip to content

Fix bangumi post#17

Merged
sun128764 merged 2 commits intomasterfrom
fix_bangumi_new
Mar 4, 2026
Merged

Fix bangumi post#17
sun128764 merged 2 commits intomasterfrom
fix_bangumi_new

Conversation

@sun128764
Copy link
Copy Markdown
Collaborator

This pull request refactors the BangumiAdapter class 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:

  • Replaces the previous two-step process (uploading the torrent file to get a file ID, then posting metadata) with a single MultipartFormDataContent form submission in PostAsync, sending both the file and metadata together. This removes the need for the UploadTorrent method and streamlines the posting logic. [1] [2]
  • Changes the construction of tags to use a comma-separated string (tag_ids) instead of an array, and adds a new "btskey" field with value "undefined" to the post form.

Code quality improvements:

  • Makes the category field readonly for better immutability and thread safety.
  • Minor formatting improvement in PingAsync for clarity and consistency.

- 将 category 字段改为 readonly,提升不可变性
- 优化 PingAsync 返回逻辑,提升可读性
- tag_ids 使用集合展开语法,简化代码
- 上传种子时增加 team_id 字段,完善请求参数
重构 BangumiAdapter.cs,将原先的种子文件单独上传与发布两步流程合并为一步,直接通过 MultipartFormDataContent 一次性提交所有表单数据和种子文件,删除了 UploadTorrent 方法。调整表单字段构造方式,tag_ids 改为逗号分隔字符串,新增 btskey 字段,teamsync 字段改为字符串 "0"。简化流程,减少 HTTP 请求,提高效率。
Copilot AI review requested due to automatic review settings March 4, 2026 08:21
@sun128764 sun128764 merged commit 4f8f775 into master Mar 4, 2026
16 checks passed
@sun128764 sun128764 deleted the fix_bangumi_new branch March 4, 2026 08:22
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PostAsync to MultipartFormDataContent submission (file + fields) instead of JSON AddRequest with a separate upload step.
  • Make category immutable (readonly) and apply minor formatting tweaks in PingAsync.

💡 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";
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
private const string uploadUrl = "v2/torrent/upload";

Copilot uses AI. Check for mistakes.
private string category;
private readonly string category;
private string teamID = "";
private string tagID = ""; // string[]?
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
private string tagID = ""; // string[]?

Copilot uses AI. Check for mistakes.
Comment on lines +115 to 118
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)
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants