feat: add image proxy route and integrate it into media handling for improved Twitter content fetching
This commit is contained in:
parent
051dbac5bf
commit
907fc4491d
6 changed files with 87 additions and 12 deletions
|
|
@ -4,6 +4,7 @@ import { FormEvent, useEffect, useMemo, useRef, useState } from "react";
|
|||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import Header from "../../components/header";
|
||||
import { proxyMediaUrl } from "../../lib/media";
|
||||
|
||||
type SourceType = "twitter" | "pixiv" | "direct";
|
||||
|
||||
|
|
@ -194,7 +195,7 @@ export default function AddPage() {
|
|||
const mediaItems = data.tweet?.media?.all || data.tweet?.media?.photos || [];
|
||||
const items: PreviewItem[] = mediaItems
|
||||
.map((m) => ({
|
||||
url: (m as any).thumbnail_url || (m as any).url || "",
|
||||
url: proxyMediaUrl((m as any).thumbnail_url || (m as any).url || ""),
|
||||
type: (((m as any).type === "video" || (m as any).type === "gif" || ((m as any).format && (m as any).format.includes("video"))) ? "video" : "image") as "image" | "video"
|
||||
}))
|
||||
.filter((item) => item.url.length > 0);
|
||||
|
|
|
|||
25
apps/frontend/src/lib/media.ts
Normal file
25
apps/frontend/src/lib/media.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* pbs.twimg.com 등 트위터 미디어 URL을 백엔드 프록시 경로로 변환합니다.
|
||||
* 트래킹 보호나 방화벽으로 인해 직접 접근이 막힐 수 있기 때문입니다.
|
||||
*/
|
||||
const PROXIED_HOSTS = [
|
||||
"pbs.twimg.com",
|
||||
"video.twimg.com",
|
||||
"ton.twimg.com",
|
||||
"abs.twimg.com",
|
||||
];
|
||||
|
||||
export function proxyMediaUrl(url: string | undefined | null): string {
|
||||
if (!url) return "";
|
||||
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
if (PROXIED_HOSTS.includes(parsed.hostname)) {
|
||||
return `/api/proxy/image?url=${encodeURIComponent(url)}`;
|
||||
}
|
||||
} catch {
|
||||
// 유효하지 않은 URL이면 그대로 반환
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue