Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/i18n/i18nKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ enum I18nKey {
bilibiliSubtitle = "bilibiliSubtitle",
bilibiliNotConfigured = "bilibiliNotConfigured",
bilibiliNotConfiguredDesc = "bilibiliNotConfiguredDesc",
bilibiliFetchError = "bilibiliFetchError",
bilibiliFetchErrorDesc = "bilibiliFetchErrorDesc",

// 追番 - 公共组件
animeTotal = "animeTotal",
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ export const en: Translation = {
[Key.bilibiliNotConfigured]: "Bilibili not configured",
[Key.bilibiliNotConfiguredDesc]:
"Configure bilibili.uid in src/config/siteConfig.ts",
[Key.bilibiliFetchError]: "Failed to load Bilibili data",
[Key.bilibiliFetchErrorDesc]:
"Could not fetch the follow list during the build. Please try again later.",

// Anime Tracking - Shared components
[Key.animeTotal]: "Total",
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ export const es: Translation = {
[Key.bilibiliNotConfigured]: "Bilibili no configurado",
[Key.bilibiliNotConfiguredDesc]:
"Configura bilibili.uid en src/config/siteConfig.ts",
[Key.bilibiliFetchError]: "No se pudieron cargar los datos de Bilibili",
[Key.bilibiliFetchErrorDesc]:
"No se pudo obtener la lista de seguimiento durante la compilación. Inténtalo de nuevo más tarde.",

// Anime Tracking - Shared components
[Key.animeTotal]: "Total",
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ export const ja: Translation = {
[Key.bilibiliNotConfigured]: "Bilibiliデータソースが未設定",
[Key.bilibiliNotConfiguredDesc]:
"src/config/siteConfig.ts で bilibili.uid を設定してください",
[Key.bilibiliFetchError]: "Bilibili データの読み込みに失敗しました",
[Key.bilibiliFetchErrorDesc]:
"ビルド時に追番データを取得できませんでした。しばらくしてからお試しください。",

// 追番 - 共通コンポーネント
[Key.animeTotal]: "合計",
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/languages/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ export const ko: Translation = {
[Key.bilibiliNotConfigured]: "Bilibili 데이터 소스가 설정되지 않았습니다",
[Key.bilibiliNotConfiguredDesc]:
"src/config/siteConfig.ts에서 bilibili.uid를 설정하세요",
[Key.bilibiliFetchError]: "Bilibili 데이터를 불러오지 못했습니다",
[Key.bilibiliFetchErrorDesc]:
"빌드 중 시청 목록을 가져올 수 없습니다. 나중에 다시 시도해 주세요.",

// Anime Tracking - Shared components
[Key.animeTotal]: "총계",
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/languages/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ export const ru: Translation = {
[Key.bilibiliNotConfigured]: "Источник данных Bilibili не настроен",
[Key.bilibiliNotConfiguredDesc]:
"Настройте bilibili.uid в src/config/siteConfig.ts",
[Key.bilibiliFetchError]: "Не удалось загрузить данные Bilibili",
[Key.bilibiliFetchErrorDesc]:
"Не удалось получить список подписок во время сборки. Повторите попытку позже.",

// Отслеживание аниме - общие компоненты
[Key.animeTotal]: "Всего",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/languages/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ export const zh_CN: Translation = {
[Key.bilibiliNotConfigured]: "未配置哔哩哔哩数据源",
[Key.bilibiliNotConfiguredDesc]:
"请在 src/config/siteConfig.ts 中配置 bilibili.uid",
[Key.bilibiliFetchError]: "哔哩哔哩数据加载失败",
[Key.bilibiliFetchErrorDesc]: "构建时无法获取追番数据,请稍后重试。",

// 追番 - 公共组件
[Key.animeTotal]: "总追番",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/languages/zh_TW.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ export const zh_TW: Translation = {
[Key.bilibiliNotConfigured]: "未配置嗶哩嗶哩資料來源",
[Key.bilibiliNotConfiguredDesc]:
"請在 src/config/siteConfig.ts 中配置 bilibili.uid",
[Key.bilibiliFetchError]: "嗶哩嗶哩資料載入失敗",
[Key.bilibiliFetchErrorDesc]: "建置時無法取得追番資料,請稍後重試。",

// 追番 - 公共組件
[Key.animeTotal]: "總追番",
Expand Down
17 changes: 16 additions & 1 deletion src/pages/bilibili.astro
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ const isConfigured = !!BILIBILI_UID && BILIBILI_UID.trim() !== "";

// 获取 Bilibili 追番 + 追剧数据
let animeList: StandardizedAnime[] = [];
let fetchFailed = false;
if (BILIBILI_UID) {
try {
animeList = await fetchBilibiliList(BILIBILI_UID);
console.log(`[Bilibili] Page data: ${animeList.length} items`);
if (import.meta.env.DEV)
console.log(`[Bilibili] Page data: ${animeList.length} items`);
} catch (error) {
console.error("[Bilibili] Failed to fetch data:", error);
fetchFailed = true;
}
}

Expand Down Expand Up @@ -79,6 +82,18 @@ const bilibiliAverageRating =
{i18n(I18nKey.bilibiliNotConfiguredDesc)}
</p>
</div>
) : fetchFailed ? (
<div class="text-center py-16">
<div class="inline-flex items-center justify-center w-16 h-16 bg-(--btn-regular-bg) rounded-full mb-6 border border-(--line-divider)">
<Icon name="material-symbols:error-outline" class="text-[2rem] text-red-500" />
</div>
<h2 class="text-xl font-semibold text-black/80 dark:text-white/80 mb-3">
{i18n(I18nKey.bilibiliFetchError)}
</h2>
<p class="text-black/60 dark:text-white/60 mb-4 max-w-md mx-auto">
{i18n(I18nKey.bilibiliFetchErrorDesc)}
</p>
</div>
) : (
<>
<!-- 统计卡片 -->
Expand Down
27 changes: 21 additions & 6 deletions src/utils/bilibili-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ async function fetchBilibiliByType(
const firstRes = await fetch(
`${BILIBILI_API}?type=${type}&vmid=${uid}&pn=1&ps=${PAGE_SIZE}`,
);
if (!firstRes.ok) {
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
throw new Error(`[Bilibili] 首页请求失败 (状态码: ${firstRes.status})`);
}
const firstJson = await firstRes.json();
if (firstJson.code !== 0 || !firstJson.data?.list?.length) return items;
if (firstJson.code !== 0) {
throw new Error(`[Bilibili] API code ${firstJson.code}`);
}
if (!firstJson.data?.list?.length) return items;

items.push(...firstJson.data.list);
const total = firstJson.data.total || items.length;
Expand All @@ -41,8 +47,15 @@ async function fetchBilibiliByType(
fetch(
`${BILIBILI_API}?type=${type}&vmid=${uid}&pn=${pn}&ps=${PAGE_SIZE}`,
)
.then((r) => r.json())
.then((j) => j.data?.list || []),
.then((r) => {
if (!r.ok)
throw new Error(`[Bilibili] 请求失败 (状态码: ${r.status})`);
return r.json();
})
.then((j) => {
if (j.code !== 0) throw new Error(`[Bilibili] API code ${j.code}`);
return j.data?.list || [];
}),
);
}
const remaining = await Promise.all(promises);
Expand All @@ -61,9 +74,11 @@ export async function fetchBilibiliList(
fetchBilibiliByType(uid, 1),
fetchBilibiliByType(uid, 2),
]);
console.log(
`[Bilibili] Fetched ${animeItems.length + dramaItems.length} items (anime: ${animeItems.length}, drama: ${dramaItems.length}).`,
);
if (import.meta.env.DEV) {
console.log(
`[Bilibili] Fetched ${animeItems.length + dramaItems.length} items (anime: ${animeItems.length}, drama: ${dramaItems.length}).`,
);
}

return [...animeItems, ...dramaItems].map((item) => ({
id: item.media_id,
Expand Down
3 changes: 2 additions & 1 deletion src/utils/date-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export function formatDateI18n(
includeTime?: boolean,
): string {
const date = typeof dateInput === "string" ? new Date(dateInput) : dateInput;
const lang = siteConfig.lang || "en";
if (!date || Number.isNaN(date.getTime())) return "";
const lang = (siteConfig.lang || "en").replace("-", "_");

// 根据语言设置不同的日期格式
const options: Intl.DateTimeFormatOptions = {
Expand Down
10 changes: 7 additions & 3 deletions src/utils/nsfw-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@ const NSFW_KEYWORDS = [
"エロ",
];

const NSFW_KEYWORDS_LOWER = new Set(NSFW_KEYWORDS.map((k) => k.toLowerCase()));
const isNsfwName = (name?: string) =>
name ? NSFW_KEYWORDS_LOWER.has(name.trim().toLowerCase()) : false;

export function isVndbNsfw(item: VndbUlistEntry): boolean {
const img = item.vn?.image;
// VNDB 以自带图片评分为权威信号,共用词表作为标签补充
return (
(img?.sexual ?? 0) > 1 ||
(img?.violence ?? 0) > 1 ||
(item.vn?.tags ?? []).some((t) => NSFW_KEYWORDS.includes(t.name))
(item.vn?.tags ?? []).some((t) => isNsfwName(t.name))
);
}

export function isMalNsfw(item: MalListItem): boolean {
return (item.node?.genres ?? []).some((g) => NSFW_KEYWORDS.includes(g.name));
return (item.node?.genres ?? []).some((g) => isNsfwName(g.name));
}

export function isBangumiNsfw(item: UserSubjectCollection): boolean {
Expand All @@ -42,7 +46,7 @@ export function isBangumiNsfw(item: UserSubjectCollection): boolean {
...(item.tags ?? []),
...(item.subject?.tags ?? []).map((t) => t.name),
];
return names.some((n) => NSFW_KEYWORDS.includes(n)); // 标签回退
return names.some((n) => isNsfwName(n));
}

// mode === "hide" 时过滤掉 NSFW 条目
Expand Down
3 changes: 3 additions & 0 deletions src/utils/vndb-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export async function fetchVndbUlist(
}

const data = (await response.json()) as VndbUlistResponse;
if (!Array.isArray(data?.results)) {
throw new Error("[VNDB] 响应缺少 results");
}
return {
...data,
results: data.results.map((item) => {
Expand Down