增加桜色动漫数据源
This commit is contained in:
@@ -374,7 +374,11 @@ interface SiteConfig {
|
||||
TMDBApiKey?: string;
|
||||
TMDBProxy?: string;
|
||||
TMDBReverseProxy?: string;
|
||||
BangumiDataSource?: 'direct' | 'server-proxy' | 'custom-baseurl';
|
||||
BangumiDataSource?:
|
||||
| 'direct'
|
||||
| 'server-proxy'
|
||||
| 'custom-baseurl'
|
||||
| 'sakura';
|
||||
BangumiApiBaseUrl?: string;
|
||||
BangumiImageBaseUrl?: string;
|
||||
BangumiProxy?: string;
|
||||
@@ -11513,6 +11517,7 @@ const SiteConfigComponent = ({
|
||||
{[
|
||||
{ value: 'direct', label: '直连' },
|
||||
{ value: 'server-proxy', label: '服务器代理' },
|
||||
{ value: 'sakura', label: '桜色镜像站' },
|
||||
{ value: 'custom-baseurl', label: '自定义 Base URL' },
|
||||
].map((option) => (
|
||||
<button
|
||||
|
||||
@@ -107,7 +107,11 @@ export async function POST(request: NextRequest) {
|
||||
TMDBApiKey?: string;
|
||||
TMDBProxy?: string;
|
||||
TMDBReverseProxy?: string;
|
||||
BangumiDataSource?: 'direct' | 'server-proxy' | 'custom-baseurl';
|
||||
BangumiDataSource?:
|
||||
| 'direct'
|
||||
| 'server-proxy'
|
||||
| 'custom-baseurl'
|
||||
| 'sakura';
|
||||
BangumiApiBaseUrl?: string;
|
||||
BangumiImageBaseUrl?: string;
|
||||
BangumiProxy?: string;
|
||||
@@ -179,7 +183,8 @@ export async function POST(request: NextRequest) {
|
||||
(BangumiDataSource !== undefined &&
|
||||
BangumiDataSource !== 'direct' &&
|
||||
BangumiDataSource !== 'server-proxy' &&
|
||||
BangumiDataSource !== 'custom-baseurl') ||
|
||||
BangumiDataSource !== 'custom-baseurl' &&
|
||||
BangumiDataSource !== 'sakura') ||
|
||||
(BangumiApiBaseUrl !== undefined &&
|
||||
typeof BangumiApiBaseUrl !== 'string') ||
|
||||
(BangumiImageBaseUrl !== undefined &&
|
||||
|
||||
@@ -40,8 +40,10 @@ function isBangumiImageUrl(url: string): boolean {
|
||||
return (
|
||||
hostname === 'lain.bgm.tv' ||
|
||||
hostname === 'r.bgm.tv' ||
|
||||
hostname === 'bangumi.lol' ||
|
||||
hostname.endsWith('.bgm.tv') ||
|
||||
hostname.endsWith('.bangumi.tv')
|
||||
hostname.endsWith('.bangumi.tv') ||
|
||||
hostname.endsWith('.bangumi.lol')
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
|
||||
@@ -16,7 +16,7 @@ import Image from 'next/image';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
|
||||
import { getBangumiSubject } from '@/lib/bangumi.client';
|
||||
import { getBangumiSubject, getBangumiSubjectUrl } from '@/lib/bangumi.client';
|
||||
import { appendSpecialSourceParam } from '@/lib/special-source.client';
|
||||
import { getTMDBImageUrl } from '@/lib/tmdb.client';
|
||||
import { processImageUrl } from '@/lib/utils';
|
||||
@@ -159,7 +159,7 @@ const DetailPanel: React.FC<DetailPanelProps> = ({
|
||||
if (currentSource === 'bangumi') {
|
||||
const actualBangumiId = bangumiId || doubanId;
|
||||
if (actualBangumiId) {
|
||||
return `https://bgm.tv/subject/${actualBangumiId}`;
|
||||
return getBangumiSubjectUrl(actualBangumiId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -321,6 +321,7 @@ export const UserMenu: React.FC = () => {
|
||||
const animeDataSourceOptions = [
|
||||
{ value: 'direct', label: '直连(浏览器直连 Bangumi)' },
|
||||
{ value: 'server-proxy', label: '服务器代理(由服务器访问 Bangumi)' },
|
||||
{ value: 'sakura', label: '桜色镜像站(bangumi.lol)' },
|
||||
{ value: 'custom-baseurl', label: '自定义 Base URL' },
|
||||
];
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import {
|
||||
saveFavorite,
|
||||
subscribeToDataUpdates,
|
||||
} from '@/lib/db.client';
|
||||
import { getBangumiSubjectUrl } from '@/lib/bangumi.client';
|
||||
import { isNetdiskSource } from '@/lib/netdisk/source';
|
||||
import {
|
||||
base58Decode,
|
||||
@@ -836,7 +837,7 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(
|
||||
icon: <Link size={20} />,
|
||||
onClick: () => {
|
||||
const url = isBangumi
|
||||
? `https://bgm.tv/subject/${actualDoubanId.toString()}`
|
||||
? getBangumiSubjectUrl(actualDoubanId.toString())
|
||||
: `https://movie.douban.com/subject/${actualDoubanId.toString()}`;
|
||||
window.open(url, '_blank', 'noopener,noreferrer');
|
||||
},
|
||||
@@ -1432,7 +1433,7 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(
|
||||
<a
|
||||
href={
|
||||
isBangumi
|
||||
? `https://bgm.tv/subject/${actualDoubanId.toString()}`
|
||||
? getBangumiSubjectUrl(actualDoubanId.toString())
|
||||
: `https://movie.douban.com/subject/${actualDoubanId.toString()}`
|
||||
}
|
||||
target='_blank'
|
||||
|
||||
@@ -28,7 +28,11 @@ export interface AdminConfig {
|
||||
TMDBProxy?: string;
|
||||
TMDBReverseProxy?: string;
|
||||
// 动漫/Bangumi配置
|
||||
BangumiDataSource?: 'direct' | 'server-proxy' | 'custom-baseurl';
|
||||
BangumiDataSource?:
|
||||
| 'direct'
|
||||
| 'server-proxy'
|
||||
| 'custom-baseurl'
|
||||
| 'sakura';
|
||||
BangumiApiBaseUrl?: string;
|
||||
BangumiImageBaseUrl?: string;
|
||||
BangumiProxy?: string;
|
||||
|
||||
+35
-15
@@ -1,6 +1,26 @@
|
||||
'use client';
|
||||
|
||||
export type AnimeDataSource = 'direct' | 'server-proxy' | 'custom-baseurl';
|
||||
export type AnimeDataSource =
|
||||
| 'direct'
|
||||
| 'server-proxy'
|
||||
| 'custom-baseurl'
|
||||
| 'sakura';
|
||||
|
||||
/** 桜色镜像站:全域名镜像 bgm.tv → bangumi.lol */
|
||||
export const BANGUMI_SAKURA_API_BASE_URL = 'https://api.bangumi.lol';
|
||||
export const BANGUMI_SAKURA_SITE_URL = 'https://bangumi.lol';
|
||||
export const BANGUMI_OFFICIAL_SITE_URL = 'https://bgm.tv';
|
||||
|
||||
export function isValidAnimeDataSource(
|
||||
value: string | null | undefined
|
||||
): value is AnimeDataSource {
|
||||
return (
|
||||
value === 'direct' ||
|
||||
value === 'server-proxy' ||
|
||||
value === 'custom-baseurl' ||
|
||||
value === 'sakura'
|
||||
);
|
||||
}
|
||||
|
||||
export interface BangumiCalendarData {
|
||||
weekday: {
|
||||
@@ -63,22 +83,14 @@ function getPrimaryAnimeDataSource(): AnimeDataSource {
|
||||
const saved = localStorage.getItem(
|
||||
'animeDataSource'
|
||||
) as AnimeDataSource | null;
|
||||
if (
|
||||
saved === 'direct' ||
|
||||
saved === 'server-proxy' ||
|
||||
saved === 'custom-baseurl'
|
||||
) {
|
||||
if (isValidAnimeDataSource(saved)) {
|
||||
return saved;
|
||||
}
|
||||
|
||||
const runtimeValue = getRuntimeConfig().BANGUMI_DATA_SOURCE as
|
||||
| AnimeDataSource
|
||||
| undefined;
|
||||
if (
|
||||
runtimeValue === 'direct' ||
|
||||
runtimeValue === 'server-proxy' ||
|
||||
runtimeValue === 'custom-baseurl'
|
||||
) {
|
||||
if (isValidAnimeDataSource(runtimeValue)) {
|
||||
return runtimeValue;
|
||||
}
|
||||
|
||||
@@ -94,10 +106,7 @@ function getBackupAnimeDataSource(
|
||||
const saved = localStorage.getItem(
|
||||
'animeDataSourceBackup'
|
||||
) as AnimeDataSource | null;
|
||||
const backup =
|
||||
saved === 'direct' || saved === 'server-proxy' || saved === 'custom-baseurl'
|
||||
? saved
|
||||
: 'server-proxy';
|
||||
const backup = isValidAnimeDataSource(saved) ? saved : 'server-proxy';
|
||||
|
||||
return backup === primary ? null : backup;
|
||||
}
|
||||
@@ -120,12 +129,23 @@ function buildBangumiUrl(source: AnimeDataSource, path: string): string {
|
||||
}
|
||||
return `${customBaseUrl}${normalizedPath}`;
|
||||
}
|
||||
case 'sakura':
|
||||
return `${BANGUMI_SAKURA_API_BASE_URL}${normalizedPath}`;
|
||||
case 'direct':
|
||||
default:
|
||||
return `${BANGUMI_OFFICIAL_BASE_URL}${normalizedPath}`;
|
||||
}
|
||||
}
|
||||
|
||||
/** 按当前动漫数据源生成 Bangumi 条目外链(桜色镜像站 → bangumi.lol) */
|
||||
export function getBangumiSubjectUrl(id: string | number): string {
|
||||
const origin =
|
||||
getPrimaryAnimeDataSource() === 'sakura'
|
||||
? BANGUMI_SAKURA_SITE_URL
|
||||
: BANGUMI_OFFICIAL_SITE_URL;
|
||||
return `${origin}/subject/${encodeURIComponent(String(id))}`;
|
||||
}
|
||||
|
||||
async function fetchBangumiJson<T>(
|
||||
source: AnimeDataSource,
|
||||
path: string
|
||||
|
||||
@@ -3,9 +3,15 @@
|
||||
import { HttpsProxyAgent } from 'https-proxy-agent';
|
||||
import nodeFetch from 'node-fetch';
|
||||
|
||||
export type AnimeDataSource = 'direct' | 'server-proxy' | 'custom-baseurl';
|
||||
export type AnimeDataSource =
|
||||
| 'direct'
|
||||
| 'server-proxy'
|
||||
| 'custom-baseurl'
|
||||
| 'sakura';
|
||||
|
||||
export const DEFAULT_BANGUMI_BASE_URL = 'https://api.bgm.tv';
|
||||
/** 桜色镜像站 API */
|
||||
export const BANGUMI_SAKURA_API_BASE_URL = 'https://api.bangumi.lol';
|
||||
|
||||
function isCloudflareEnvironment(): boolean {
|
||||
return (
|
||||
|
||||
+30
-3
@@ -140,15 +140,21 @@ function isBangumiImageUrl(url: string): boolean {
|
||||
return (
|
||||
hostname === 'lain.bgm.tv' ||
|
||||
hostname === 'r.bgm.tv' ||
|
||||
hostname === 'bangumi.lol' ||
|
||||
hostname.endsWith('.bgm.tv') ||
|
||||
hostname.endsWith('.bangumi.tv')
|
||||
hostname.endsWith('.bangumi.tv') ||
|
||||
hostname.endsWith('.bangumi.lol')
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
type AnimeImageSource = 'direct' | 'server-proxy' | 'custom-baseurl';
|
||||
type AnimeImageSource =
|
||||
| 'direct'
|
||||
| 'server-proxy'
|
||||
| 'custom-baseurl'
|
||||
| 'sakura';
|
||||
|
||||
const BANGUMI_IMAGE_FALLBACK_UNTIL_KEY = 'bangumiImageFallbackUntil';
|
||||
const BANGUMI_IMAGE_FALLBACK_SIGNATURE_KEY = 'bangumiImageFallbackSignature';
|
||||
@@ -158,12 +164,31 @@ function normalizeBaseUrl(baseUrl: string): string {
|
||||
return baseUrl.trim().replace(/\/+$/, '');
|
||||
}
|
||||
|
||||
/** 官方域名 → 桜色镜像站(bgm.tv → bangumi.lol 等) */
|
||||
function rewriteBangumiUrlToSakura(url: string): string {
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
const hostname = parsed.hostname.toLowerCase();
|
||||
if (hostname === 'bgm.tv' || hostname === 'bangumi.tv') {
|
||||
parsed.hostname = 'bangumi.lol';
|
||||
} else if (hostname.endsWith('.bgm.tv')) {
|
||||
parsed.hostname = `${hostname.slice(0, -'.bgm.tv'.length)}.bangumi.lol`;
|
||||
} else if (hostname.endsWith('.bangumi.tv')) {
|
||||
parsed.hostname = `${hostname.slice(0, -'.bangumi.tv'.length)}.bangumi.lol`;
|
||||
}
|
||||
return parsed.toString();
|
||||
} catch {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeAnimeImageSource(
|
||||
value: string | null | undefined
|
||||
): AnimeImageSource {
|
||||
return value === 'server-proxy' ||
|
||||
value === 'custom-baseurl' ||
|
||||
value === 'direct'
|
||||
value === 'direct' ||
|
||||
value === 'sakura'
|
||||
? value
|
||||
: 'direct';
|
||||
}
|
||||
@@ -304,6 +329,8 @@ function buildBangumiImageUrl(
|
||||
const imageBaseUrl = getBangumiImageBaseUrl();
|
||||
return imageBaseUrl ? `${imageBaseUrl}/${originalUrl}` : originalUrl;
|
||||
}
|
||||
case 'sakura':
|
||||
return rewriteBangumiUrlToSakura(originalUrl);
|
||||
case 'direct':
|
||||
default:
|
||||
return originalUrl;
|
||||
|
||||
Reference in New Issue
Block a user