Skip to content

fix(data): 加固远端数据处理与构建期失败降级 - #744

Open
markd3ng wants to merge 2 commits into
CuteLeaf:masterfrom
markd3ng:ff/external-data
Open

markd3ng wants to merge 2 commits into
CuteLeaf:masterfrom
markd3ng:ff/external-data

Conversation

@markd3ng

@markd3ng markd3ng commented Nov 29, 2026 •

Copy link
Copy Markdown

Summary

External-data cleanup covering three audit findings.

  • FF-11 – NSFW keyword matching now trims and lowercases each tag/genre name against a lowercased keyword set. VNDB lowercase tags, MAL free-text genres ("R18 ") and Bangumi tag fallbacks all use the same normalization; the shared helper has three call sites so they stay in lockstep.
  • FF-14 – formatDateI18n returns "" for invalid input (matching formatDateToYYYYMMDD) instead of rendering Invalid Date, and normalizes zh-CN-style language codes to the zh_CN keys used by the locale map.
  • FF-29 – fetchVndbUlist rejects HTTP-200 responses without a results array. Bilibili requests now check HTTP status and API code, including subsequent pages. A build-time fetch failure sets an explicit state on the Bilibili page and renders a translated error notice instead of publishing "total 0 / avg 0.0"; per-item fetch logs run only in development. Two new i18n keys were added to all seven locale modules.

Files

  • src/utils/nsfw-utils.ts, src/utils/date-utils.ts, src/utils/vndb-utils.ts, src/utils/bilibili-utils.ts
  • src/pages/bilibili.astro, src/i18n/i18nKey.ts, src/i18n/languages/*.ts

Verification

  • corepack pnpm run check: 0 errors, 0 warnings, 0 hints.
  • corepack pnpm exec astro build --force: 40 pages built successfully.
  • corepack pnpm exec biome check on the changed files: no fixes applied.
  • Runtime assertions (throwaway harness, removed after use): 9/9 PASS — lowercase/whitespace NSFW tags, invalid dates, 503 Bilibili response and VNDB body without results all behave as specified.
  • Locale parity: all seven locale modules define both new keys.

Sourcery 摘要

加强远程数据处理,并在构建时获取 Bilibili 数据失败时优雅降级。

Bug 修复:

  • 加强对外部数据的验证和规范化,涵盖 NSFW 匹配、日期格式、VNDB 响应以及 Bilibili API 请求。
  • 构建时获取 Bilibili 数据失败时,优雅地显示本地化错误状态,而非空统计数据。

改进:

  • 仅在开发构建中记录 Bilibili 诊断日志。
  • 为所有受支持的语言添加本地化的 Bilibili 获取失败提示。
Original summary in English

Sourcery 摘要

强化外部数据处理,并在构建过程中无法获取 Bilibili 数据时,以本地化错误提示进行妥善处理。

Bug 修复:

  • 验证外部 VNDB 和 Bilibili 响应;在构建时获取 Bilibili 数据失败时,显示本地化错误状态,而不是空统计数据。
  • 统一不同外部数据源中的 NSFW 匹配规则,并在本地化日期输入无效时返回空结果。

改进:

  • 仅在开发版本中记录 Bilibili 诊断日志,并支持用于日期格式化的标准化区域代码。

杂项:

  • 为所有受支持的语言添加本地化的 Bilibili 数据获取失败提示。
Original summary in English

Summary by Sourcery

Harden external-data processing and gracefully surface localized errors when Bilibili data cannot be fetched during builds.

Bug Fixes:

  • Validate external VNDB and Bilibili responses and handle build-time Bilibili fetch failures with a localized error state instead of empty statistics.
  • Normalize NSFW matching across external data sources and return an empty result for invalid localized date inputs.

Enhancements:

  • Restrict Bilibili diagnostic logging to development builds and support normalized locale codes for date formatting.

Chores:

  • Add localized Bilibili fetch-failure messages across all supported languages.

- FF-11: NSFW 标签匹配前 trim + 小写归一,VNDB/MAL/Bangumi 共用同一词表集合
- FF-14: formatDateI18n 对非法日期返回空串,并将连字符语言码归一到下划线映射
- FF-29: VNDB 响应缺少 results 时报错;Bilibili 校验 HTTP 状态与 API code,拉取失败显示独立提示而非静默 0 值,构建日志仅在开发环境输出
@netlify

netlify Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

👷 Deploy request for demo-firefly pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 16dffed

@sourcery-ai

sourcery-ai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

审阅者指南

数据结构

在所有受支持的区域设置中添加 Bilibili 获取错误键及其翻译,以便页面能够显示本地化的失败状态。

  • src/i18n/i18nKey.ts L235-236
  • src/i18n/languages/en.ts L240-242
  • src/i18n/languages/es.ts L240-242
  • src/i18n/languages/ja.ts L239-241
  • src/i18n/languages/ko.ts L239-241
  • src/i18n/languages/ru.ts L240-242
  • src/i18n/languages/zh_CN.ts L235-236
  • src/i18n/languages/zh_TW.ts L237-238

实现

在关键词匹配之前,对名称进行去空格和小写化处理,确保 VNDB、MAL 和 Bangumi 中的 NSFW 名称格式一致。

  • src/utils/nsfw-utils.ts L25-28(另有 3 处小改动)

让日期格式化逻辑拒绝无效日期,并将带连字符的语言代码转换为区域设置映射所采用的格式。

  • src/utils/date-utils.ts L60-61

拒绝不包含结果数组的 VNDB 响应,并验证 Bilibili 页面请求的 HTTP 状态和 API 代码。

  • src/utils/bilibili-utils.ts L29-36, L50-58, L77-81
  • src/utils/vndb-utils.ts L52-54

UI

跟踪 Bilibili 获取失败的情况,并显示本地化错误提示,而不是空统计数据;同时将页面级诊断日志限制在开发环境中。

  • src/pages/bilibili.astro L28-36, L85-96

提示和命令

与 Sourcery 交互

  • 触发新的审阅: 在拉取请求中评论 @sourcery-ai review。
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 根据审阅评论创建 GitHub issue: 回复审阅评论,让 Sourcery 根据该评论创建 issue。你也可以回复 @sourcery-ai issue,根据该评论创建 issue。
  • 生成拉取请求标题: 在拉取请求标题的任意位置写入 @sourcery-ai,即可随时生成标题。你也可以在拉取请求中评论 @sourcery-ai title,随时重新生成标题。
  • 生成拉取请求摘要: 在拉取请求正文中你希望插入摘要的位置写入 @sourcery-ai summary,即可随时生成 PR 摘要。你也可以在拉取请求中评论 @sourcery-ai summary,随时重新生成摘要。
  • 生成审阅者指南: 在拉取请求中评论 @sourcery-ai guide,即可随时重新生成审阅者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,此功能会很有用。
  • 忽略所有 Sourcery 审阅: 在拉取请求中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 审阅。尤其适用于你想重新开始新一轮审阅的情况——别忘了评论 @sourcery-ai review 来触发新的审阅!

自定义使用体验

访问你的控制面板以:

  • 启用或禁用审阅功能,例如 Sourcery 生成的拉取请求摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、移除或编辑自定义审阅说明。
  • 调整其他审阅设置。

获取帮助

Original review guide in English

Reviewer's Guide

Data structures

Add the Bilibili fetch-error keys and translations across all supported locales so the page can present a localized failure state.

  • src/i18n/i18nKey.ts L235-236
  • src/i18n/languages/en.ts L240-242
  • src/i18n/languages/es.ts L240-242
  • src/i18n/languages/ja.ts L239-241
  • src/i18n/languages/ko.ts L239-241
  • src/i18n/languages/ru.ts L240-242
  • src/i18n/languages/zh_CN.ts L235-236
  • src/i18n/languages/zh_TW.ts L237-238

Implementation

Normalize NSFW names consistently across VNDB, MAL, and Bangumi by trimming and lowercasing before keyword matching.

  • src/utils/nsfw-utils.ts L25-28 (+3 small edits)

Make date formatting reject invalid dates and map hyphenated language codes to the locale-map convention.

  • src/utils/date-utils.ts L60-61

Reject VNDB responses that do not contain a results array, and validate HTTP status and API codes for Bilibili pages.

  • src/utils/bilibili-utils.ts L29-36, L50-58, L77-81
  • src/utils/vndb-utils.ts L52-54

UI

Track Bilibili fetch failures and render a localized error notice instead of empty statistics, while limiting page-level diagnostic logging to development.

  • src/pages/bilibili.astro L28-36, L85-96

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

嗨——我发现了 1 个问题

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/utils/bilibili-utils.ts" line_range="29" />
<code_context>
 	const firstRes = await fetch(
 		`${BILIBILI_API}?type=${type}&vmid=${uid}&pn=1&ps=${PAGE_SIZE}`,
 	);
+	if (!firstRes.ok) {
+		throw new Error(`[Bilibili] 首页请求失败 (状态码: ${firstRes.status})`);
+	}
</code_context>
<issue_to_address>
**API errors appear as empty results**

When bilibili returns HTTP 200 with a nonzero API code for the first page, `fetchBilibiliByType` returns an empty list instead of throwing, so `fetchBilibiliList` resolves and the page presents zero or partial totals rather than its fetch-error notice.

Throw when the first-page JSON has a nonzero API code, and reserve the empty-list return for successful responses with no items.

Also at `src/utils/bilibili-utils.ts:53`.
</issue_to_address>

Sourcery 评估

等待批准。 请先处理 1 项发现。

阻塞性发现:src/utils/bilibili-utils.ts:29


Sourcery 对开源项目免费——如果你喜欢我们的评审,请考虑分享 ✨
Original comment in English

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/utils/bilibili-utils.ts" line_range="29" />
<code_context>
 	const firstRes = await fetch(
 		`${BILIBILI_API}?type=${type}&vmid=${uid}&pn=1&ps=${PAGE_SIZE}`,
 	);
+	if (!firstRes.ok) {
+		throw new Error(`[Bilibili] 首页请求失败 (状态码: ${firstRes.status})`);
+	}
</code_context>
<issue_to_address>
**API errors appear as empty results**

When bilibili returns HTTP 200 with a nonzero API code for the first page, `fetchBilibiliByType` returns an empty list instead of throwing, so `fetchBilibiliList` resolves and the page presents zero or partial totals rather than its fetch-error notice.

Throw when the first-page JSON has a nonzero API code, and reserve the empty-list return for successful responses with no items.

Also at `src/utils/bilibili-utils.ts:53`.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: src/utils/bilibili-utils.ts:29


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/utils/bilibili-utils.ts Resolved
- Treat a non-zero first-page code as an error instead of an empty list, matching subsequent-page handling.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

This branch has not been deployed

No deployments
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.

1 participant