fix: 修复哔哩哔哩平台封面图无法显示的问题
- 后端 Bilibili 适配器添加 URL 规范化,处理协议相对路径和 http 协议 - 前端 Image 组件添加 referrerPolicy="no-referrer" 绕过 CDN 防盗链 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6cc703ada2
commit
e933c71b3d
@ -1,6 +1,13 @@
|
|||||||
import type { ContentItem, PlatformAdapter } from "@muse/shared";
|
import type { ContentItem, PlatformAdapter } from "@muse/shared";
|
||||||
import { tikhubFetch } from "../tikhub";
|
import { tikhubFetch } from "../tikhub";
|
||||||
|
|
||||||
|
/** Ensure Bilibili URLs use https:// (API may return protocol-relative "//..." or http) */
|
||||||
|
function normalizeUrl(url: string): string {
|
||||||
|
if (url.startsWith("//")) return `https:${url}`;
|
||||||
|
if (url.startsWith("http://")) return url.replace("http://", "https://");
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
export class BilibiliAdapter implements PlatformAdapter {
|
export class BilibiliAdapter implements PlatformAdapter {
|
||||||
async fetchTrending(count: number): Promise<ContentItem[]> {
|
async fetchTrending(count: number): Promise<ContentItem[]> {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
@ -44,10 +51,10 @@ export class BilibiliAdapter implements PlatformAdapter {
|
|||||||
return {
|
return {
|
||||||
id: String(aid || bvid),
|
id: String(aid || bvid),
|
||||||
title: raw?.title || "无标题",
|
title: raw?.title || "无标题",
|
||||||
cover_url: raw?.pic || undefined,
|
cover_url: raw?.pic ? normalizeUrl(raw.pic) : undefined,
|
||||||
video_url: undefined,
|
video_url: undefined,
|
||||||
author_name: owner?.name || raw?.author || "未知作者",
|
author_name: owner?.name || raw?.author || "未知作者",
|
||||||
author_avatar: owner?.face || undefined,
|
author_avatar: owner?.face ? normalizeUrl(owner.face) : undefined,
|
||||||
play_count: stat?.view ?? undefined,
|
play_count: stat?.view ?? undefined,
|
||||||
like_count: stat?.like ?? undefined,
|
like_count: stat?.like ?? undefined,
|
||||||
collect_count: stat?.favorite ?? undefined,
|
collect_count: stat?.favorite ?? undefined,
|
||||||
|
|||||||
@ -35,6 +35,7 @@ export function ContentCard({ item }: ContentCardProps) {
|
|||||||
alt={item.title}
|
alt={item.title}
|
||||||
fill
|
fill
|
||||||
unoptimized
|
unoptimized
|
||||||
|
referrerPolicy="no-referrer"
|
||||||
className="object-cover"
|
className="object-cover"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
sizes="(max-width: 640px) 100vw, (max-width: 960px) 50vw, (max-width: 1240px) 33vw, 25vw"
|
sizes="(max-width: 640px) 100vw, (max-width: 960px) 50vw, (max-width: 1240px) 33vw, 25vw"
|
||||||
@ -84,6 +85,7 @@ export function ContentCard({ item }: ContentCardProps) {
|
|||||||
width={20}
|
width={20}
|
||||||
height={20}
|
height={20}
|
||||||
unoptimized
|
unoptimized
|
||||||
|
referrerPolicy="no-referrer"
|
||||||
className="rounded-full object-cover"
|
className="rounded-full object-cover"
|
||||||
onError={(e) => {
|
onError={(e) => {
|
||||||
(e.target as HTMLImageElement).style.display = "none";
|
(e.target as HTMLImageElement).style.display = "none";
|
||||||
|
|||||||
@ -46,6 +46,7 @@ export function DetailPanel({ item }: DetailPanelProps) {
|
|||||||
alt={item.title}
|
alt={item.title}
|
||||||
fill
|
fill
|
||||||
unoptimized
|
unoptimized
|
||||||
|
referrerPolicy="no-referrer"
|
||||||
className="object-cover"
|
className="object-cover"
|
||||||
priority
|
priority
|
||||||
sizes="(max-width: 768px) 100vw, 768px"
|
sizes="(max-width: 768px) 100vw, 768px"
|
||||||
@ -87,6 +88,7 @@ export function DetailPanel({ item }: DetailPanelProps) {
|
|||||||
width={40}
|
width={40}
|
||||||
height={40}
|
height={40}
|
||||||
unoptimized
|
unoptimized
|
||||||
|
referrerPolicy="no-referrer"
|
||||||
className="rounded-full object-cover"
|
className="rounded-full object-cover"
|
||||||
onError={(e) => {
|
onError={(e) => {
|
||||||
(e.target as HTMLImageElement).style.display = "none";
|
(e.target as HTMLImageElement).style.display = "none";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user