Files
douyin-archive/app/author/[secUid]/page.tsx
T
feie9454andClaude Opus 5.5 b84fcec77b feat: 播放页按来源列表切换,新增作者/搜索/hashtag 侧栏
- 播放上下文:作品链接带上来源(搜索、标签、作者、hashtag),上一条/下一条
  在该列表内移动;当前作品不在列表中时退回全部作品的发布时间顺序
- 顶部提示标签显示当前列表与位置,点击打开侧栏列表,✕ 退出
- 侧栏改为「评论 | TA的作品 | 搜索结果/#hashtag」标签页,作品封面网格可就地切换
- 作者模式:打开「TA的作品」进入,关闭侧栏不退出,点提示 ✕ 后回到原来的列表
- 从搜索结果进入或点 hashtag 时自动打开对应列表
- 描述中的 hashtag 可点击,按完整 hashtag 精确匹配(#丰川祥子 不含 #丰川祥子cos)
- 新增 /api/playlist;搜索 SQL 抽到 lib/search-query.ts 与播放页共用,保证顺序一致
- 移动端:底部抽屉、点作品后收起,媒体区支持上下滑切换

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 00:50:09 +08:00

158 lines
5.4 KiB
TypeScript

import { prisma } from "@/lib/prisma";
import { getFileUrl } from "@/lib/minio";
import { playbackContextQuery } from "@/lib/playback-context";
import FeedMasonry from "@/app/components/FeedMasonry";
import BackButton from "@/app/components/BackButton";
import { FeedItem } from "@/app/types/feed";
import { notFound } from "next/navigation";
import Image from "next/image";
import { ExternalLink } from "lucide-react";
export default async function AuthorPage({
params,
}: {
params: Promise<{ secUid: string }>;
}) {
const secUid = (await params).secUid;
const author = await prisma.author.findUnique({
where: { sec_uid: secUid },
});
if (!author) {
notFound();
}
// Initial feed fetch
const limit = 24;
const [videos, posts] = await Promise.all([
prisma.video.findMany({
where: { authorId: secUid },
orderBy: { created_at: "desc" },
take: limit,
include: { author: true },
}),
prisma.imagePost.findMany({
where: { authorId: secUid },
orderBy: { created_at: "desc" },
take: limit,
include: { author: true, images: { orderBy: { order: "asc" }, take: 1 } },
}),
]);
const initialItems: FeedItem[] = [
...videos.map((v) => ({
type: "video" as const,
aweme_id: v.aweme_id,
created_at: v.created_at,
desc: v.desc,
video_url: getFileUrl(v.video_url),
cover_url: getFileUrl(v.cover_url ?? "default_cover.png"),
width: v.width ?? null,
height: v.height ?? null,
author: {
nickname: v.author.nickname,
avatar_url: getFileUrl(v.author.avatar_url ?? ""),
sec_uid: v.author.sec_uid,
},
likes: Number(v.digg_count),
})),
...posts.map((p) => ({
type: "image" as const,
aweme_id: p.aweme_id,
created_at: p.created_at,
desc: p.desc,
cover_url: getFileUrl(p.images?.[0]?.url ?? null),
width: p.images?.[0]?.width ?? null,
height: p.images?.[0]?.height ?? null,
author: {
nickname: p.author.nickname,
avatar_url: getFileUrl(p.author.avatar_url ?? ""),
sec_uid: p.author.sec_uid,
},
likes: Number(p.digg_count),
})),
]
.sort((a, b) => +new Date(b.created_at) - +new Date(a.created_at))
.slice(0, limit);
const initialCursor =
initialItems.length > 0
? new Date(
initialItems[initialItems.length - 1].created_at as any,
).toISOString()
: null;
return (
<main className="min-h-screen bg-white dark:bg-black text-black dark:text-white">
<div className="sticky top-0 z-10 p-4 bg-white/80 dark:bg-black/80 backdrop-blur-md border-b border-gray-200 dark:border-gray-800 flex items-center gap-4">
<BackButton />
<h1 className="text-lg font-bold truncate">{author.nickname}</h1>
</div>
<div className="max-w-7xl mx-auto px-4 py-8">
{/* Author Profile Header */}
<div className="flex flex-col md:flex-row items-center md:items-start gap-6 mb-12">
<div className="relative w-24 h-24 md:w-32 md:h-32 shrink-0">
<Image
src={getFileUrl(author.avatar_url || "default-avatar.png")}
alt={author.nickname}
fill
className="rounded-full object-cover border-2 border-gray-200 dark:border-gray-800"
/>
</div>
<div className="flex-1 text-center md:text-left space-y-4">
<div>
<h2 className="text-2xl font-bold">{author.nickname}</h2>
<p className="text-sm text-gray-500 dark:text-gray-400 mt-1">
抖音号:{author.unique_id || author.short_id || "未知"}
</p>
<a
href={`https://www.douyin.com/user/${encodeURIComponent(secUid)}`}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-1.5 mt-3 text-sm text-gray-600 hover:text-black dark:text-gray-400 dark:hover:text-white underline underline-offset-4"
>
打开抖音主页
<ExternalLink size={14} aria-hidden="true" />
</a>
</div>
{author.signature && (
<p className="text-gray-700 dark:text-gray-300 whitespace-pre-wrap max-w-2xl">
{author.signature}
</p>
)}
<div className="flex items-center justify-center md:justify-start gap-6 text-sm">
<div className="flex items-center gap-1">
<span className="font-bold text-lg">
{Number(author.total_favorited).toLocaleString()}
</span>
<span className="text-gray-500">获赞</span>
</div>
<div className="flex items-center gap-1">
<span className="font-bold text-lg">
{Number(author.follower_count).toLocaleString()}
</span>
<span className="text-gray-500">粉丝</span>
</div>
</div>
</div>
</div>
<div className="border-t border-gray-200 dark:border-gray-800 pt-8">
<h3 className="text-lg font-semibold mb-6">作品</h3>
<FeedMasonry
initialItems={initialItems}
initialCursor={initialCursor}
fetchUrl={`/api/author/${secUid}/feed`}
linkQuery={playbackContextQuery({ kind: "author", secUid })}
/>
</div>
</div>
</main>
);
}