feat: add path navigation and shared settings transitions
This commit is contained in:
1 parent
caad17d195
commit
84c9e97451
25 files changed
+689
-151
No files matched your search
@@ -0,0 +1,13 @@
|
||||
import { cookies } from 'next/headers';
|
||||
import HomeClient from './HomeClient';
|
||||
|
||||
export default async function ForumPage() {
|
||||
let cachedName = '';
|
||||
try {
|
||||
const cookieStore = await cookies();
|
||||
cachedName = decodeURIComponent(cookieStore.get('forumlify-name')?.value || '');
|
||||
} catch {
|
||||
cachedName = '';
|
||||
}
|
||||
return <HomeClient cachedName={cachedName} />;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import ForumPage from '../ForumPage';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export default function NamedPage() {
|
||||
return <ForumPage />;
|
||||
}
|
||||
@@ -5,6 +5,9 @@ import { getUser, requireAdmin } from '@/lib/auth';
|
||||
// 避免 GET 被静态优化导致写方法 405(动态接口,不能缓存)
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
const RESERVED_PAGE_NAMES = new Set([
|
||||
'api', 'post', 'user', 'settings', 'messages', 'admin', 'new', 'uploads',
|
||||
]);
|
||||
|
||||
export async function GET(req) {
|
||||
const user = getUser(req);
|
||||
@@ -33,6 +36,9 @@ export async function POST(req) {
|
||||
if (!/^[a-zA-Z0-9\-_]+$/.test(name)) {
|
||||
return Response.json({ error: '页面名称只允许字母、数字、短横线和下划线' }, { status: 400 });
|
||||
}
|
||||
if (RESERVED_PAGE_NAMES.has(name.toLowerCase())) {
|
||||
return Response.json({ error: '该页面名称为系统保留路径' }, { status: 400 });
|
||||
}
|
||||
try {
|
||||
const r = await pool.query(
|
||||
`INSERT INTO custom_pages (name, title, content)
|
||||
|
||||
@@ -2,29 +2,27 @@
|
||||
import pool from '@/lib/db';
|
||||
import { getUser, requireAdmin } from '@/lib/auth';
|
||||
import { createNotification } from '@/lib/notify';
|
||||
|
||||
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||
import { resolvePostReference } from '@/lib/post-reference';
|
||||
|
||||
export async function PUT(req, { params }) {
|
||||
const user = getUser(req);
|
||||
if (!user) return Response.json({ error: '请先登录' }, { status: 401 });
|
||||
const forbidden = await requireAdmin(user);
|
||||
if (forbidden) return forbidden;
|
||||
if (!UUID_RE.test((await params).id)) {
|
||||
return Response.json({ error: '帖子不存在' }, { status: 404 });
|
||||
}
|
||||
|
||||
try {
|
||||
const post = await pool.query('SELECT id, user_id FROM posts WHERE id = $1', [(await params).id]);
|
||||
if (post.rows.length === 0) {
|
||||
const reference = await resolvePostReference((await params).id);
|
||||
if (!reference) {
|
||||
return Response.json({ error: '帖子不存在' }, { status: 404 });
|
||||
}
|
||||
const check = await pool.query('SELECT is_pinned FROM posts WHERE id = $1', [(await params).id]);
|
||||
const isPinned = check.rows[0].is_pinned;
|
||||
const post = await pool.query(
|
||||
'SELECT id, user_id, post_number, is_pinned FROM posts WHERE id = $1',
|
||||
[reference.id]
|
||||
);
|
||||
const isPinned = post.rows[0].is_pinned;
|
||||
|
||||
const r = await pool.query(
|
||||
`UPDATE posts SET is_pinned = $1, pinned_at = $2 WHERE id = $3 RETURNING *`,
|
||||
[!isPinned, !isPinned ? new Date().toISOString() : null, (await params).id]
|
||||
[!isPinned, !isPinned ? new Date().toISOString() : null, reference.id]
|
||||
);
|
||||
|
||||
await createNotification(
|
||||
@@ -32,7 +30,7 @@ export async function PUT(req, { params }) {
|
||||
'system',
|
||||
isPinned ? '你的帖子已被取消置顶' : '你的帖子已被置顶',
|
||||
isPinned ? '管理员取消了你的帖子置顶' : '管理员把你的帖子置顶了',
|
||||
'/?post=' + (await params).id
|
||||
'/post/' + post.rows[0].post_number
|
||||
);
|
||||
|
||||
return Response.json(r.rows[0]);
|
||||
|
||||
@@ -5,6 +5,7 @@ import { jsonWithEtag } from '@/lib/http-cache';
|
||||
import { verifyCaptcha } from '@/lib/captcha';
|
||||
import { logAudit } from '@/lib/audit';
|
||||
import { getReplySchemaCapabilities } from '@/lib/reply-schema';
|
||||
import { resolvePostReference } from '@/lib/post-reference';
|
||||
|
||||
function repliesSelectSql(capabilities) {
|
||||
if (capabilities.replyToId) {
|
||||
@@ -42,8 +43,10 @@ function repliesSelectSql(capabilities) {
|
||||
|
||||
export async function GET(req, { params }) {
|
||||
try {
|
||||
const reference = await resolvePostReference((await params).id);
|
||||
if (!reference) return Response.json({ error: '帖子不存在' }, { status: 404 });
|
||||
const capabilities = await getReplySchemaCapabilities();
|
||||
const r = await pool.query(repliesSelectSql(capabilities), [(await params).id]);
|
||||
const r = await pool.query(repliesSelectSql(capabilities), [reference.id]);
|
||||
return jsonWithEtag(req, r.rows);
|
||||
} catch (error) {
|
||||
console.error('[replies] list failed:', error?.code || error?.message);
|
||||
@@ -65,7 +68,9 @@ export async function POST(req, { params }) {
|
||||
return Response.json({ error: '验证码错误,请重新计算' }, { status: 400 });
|
||||
}
|
||||
try {
|
||||
const postId = (await params).id;
|
||||
const reference = await resolvePostReference((await params).id);
|
||||
if (!reference) return Response.json({ error: '帖子不存在' }, { status: 404 });
|
||||
const postId = reference.id;
|
||||
const capabilities = await getReplySchemaCapabilities();
|
||||
let replyTargetUsername = null;
|
||||
|
||||
|
||||
+12
-10
@@ -2,22 +2,22 @@
|
||||
import pool from '@/lib/db';
|
||||
import { getUser } from '@/lib/auth';
|
||||
import { jsonWithEtag } from '@/lib/http-cache';
|
||||
|
||||
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||
import { resolvePostReference } from '@/lib/post-reference';
|
||||
|
||||
function invalidId() {
|
||||
return Response.json({ error: '帖子不存在' }, { status: 404 });
|
||||
}
|
||||
|
||||
export async function GET(req, { params }) {
|
||||
if (!UUID_RE.test((await params).id)) return invalidId();
|
||||
try {
|
||||
const reference = await resolvePostReference((await params).id);
|
||||
if (!reference) return invalidId();
|
||||
const r = await pool.query(
|
||||
`SELECT p.*, u.username, u.avatar_url, u.signature
|
||||
FROM posts p
|
||||
JOIN users u ON p.user_id = u.id
|
||||
WHERE p.id = $1`,
|
||||
[(await params).id]
|
||||
[reference.id]
|
||||
);
|
||||
if (r.rows.length === 0) {
|
||||
return invalidId();
|
||||
@@ -29,7 +29,6 @@ export async function GET(req, { params }) {
|
||||
}
|
||||
|
||||
export async function PUT(req, { params }) {
|
||||
if (!UUID_RE.test((await params).id)) return invalidId();
|
||||
const user = getUser(req);
|
||||
if (!user) {
|
||||
return Response.json({ error: '请先登录' }, { status: 401 });
|
||||
@@ -39,7 +38,9 @@ export async function PUT(req, { params }) {
|
||||
return Response.json({ error: '请填写内容' }, { status: 400 });
|
||||
}
|
||||
try {
|
||||
const post = await pool.query('SELECT user_id, images FROM posts WHERE id = $1', [(await params).id]);
|
||||
const reference = await resolvePostReference((await params).id);
|
||||
if (!reference) return invalidId();
|
||||
const post = await pool.query('SELECT user_id, images FROM posts WHERE id = $1', [reference.id]);
|
||||
if (post.rows.length === 0) return invalidId();
|
||||
if (post.rows[0].user_id !== user.id) {
|
||||
return Response.json({ error: '无权限编辑此帖子' }, { status: 403 });
|
||||
@@ -47,7 +48,7 @@ export async function PUT(req, { params }) {
|
||||
// images: 可选,传入完整图片 URL 数组(编辑时替换全部图片);不传则保留原图
|
||||
const r = await pool.query(
|
||||
`UPDATE posts SET title = $1, content = $2, images = $3, edited_at = NOW() WHERE id = $4 RETURNING *`,
|
||||
[title || '无标题', content, Array.isArray(images) ? images : post.rows[0].images || [], (await params).id]
|
||||
[title || '无标题', content, Array.isArray(images) ? images : post.rows[0].images || [], reference.id]
|
||||
);
|
||||
return Response.json(r.rows[0]);
|
||||
} catch {
|
||||
@@ -56,13 +57,14 @@ export async function PUT(req, { params }) {
|
||||
}
|
||||
|
||||
export async function DELETE(req, { params }) {
|
||||
if (!UUID_RE.test((await params).id)) return invalidId();
|
||||
const user = getUser(req);
|
||||
if (!user) {
|
||||
return Response.json({ error: '请先登录' }, { status: 401 });
|
||||
}
|
||||
try {
|
||||
const post = await pool.query('SELECT user_id FROM posts WHERE id = $1', [(await params).id]);
|
||||
const reference = await resolvePostReference((await params).id);
|
||||
if (!reference) return invalidId();
|
||||
const post = await pool.query('SELECT user_id FROM posts WHERE id = $1', [reference.id]);
|
||||
if (post.rows.length === 0) {
|
||||
return invalidId();
|
||||
}
|
||||
@@ -70,7 +72,7 @@ export async function DELETE(req, { params }) {
|
||||
if (post.rows[0].user_id !== user.id && u.rows[0]?.role !== 'admin') {
|
||||
return Response.json({ error: '无权限删除此帖子' }, { status: 403 });
|
||||
}
|
||||
await pool.query('DELETE FROM posts WHERE id = $1', [(await params).id]);
|
||||
await pool.query('DELETE FROM posts WHERE id = $1', [reference.id]);
|
||||
return Response.json({ success: true });
|
||||
} catch {
|
||||
return Response.json({ error: '删除失败,请稍后重试' }, { status: 500 });
|
||||
|
||||
@@ -4,6 +4,7 @@ import { getUser } from '@/lib/auth';
|
||||
import { jsonWithEtag } from '@/lib/http-cache';
|
||||
import { verifyCaptcha } from '@/lib/captcha';
|
||||
import { logAudit } from '@/lib/audit';
|
||||
import { ensurePostNumberSchema } from '@/lib/post-reference';
|
||||
|
||||
// 避免 GET 被静态优化导致写方法 405(动态接口,不能缓存)
|
||||
export const dynamic = 'force-dynamic';
|
||||
@@ -21,6 +22,7 @@ export async function GET(req) {
|
||||
const offset = (safePage - 1) * limit;
|
||||
|
||||
try {
|
||||
await ensurePostNumberSchema();
|
||||
const params = [];
|
||||
let where = '';
|
||||
if (userId) {
|
||||
@@ -68,6 +70,7 @@ export async function POST(req) {
|
||||
return Response.json({ error: '验证码错误,请重新计算' }, { status: 400 });
|
||||
}
|
||||
try {
|
||||
await ensurePostNumberSchema();
|
||||
const r = await pool.query(
|
||||
`INSERT INTO posts (user_id, title, content, images)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// GET /api/reports, POST /api/reports
|
||||
import pool from '@/lib/db';
|
||||
import { getUser, requireAdmin } from '@/lib/auth';
|
||||
import { resolvePostReference } from '@/lib/post-reference';
|
||||
|
||||
// 避免 GET 被静态优化导致写方法 405(动态接口,不能缓存)
|
||||
export const dynamic = 'force-dynamic';
|
||||
@@ -40,9 +41,11 @@ export async function POST(req) {
|
||||
return Response.json({ error: '请填写完整信息' }, { status: 400 });
|
||||
}
|
||||
try {
|
||||
const post = await resolvePostReference(post_id);
|
||||
if (!post) return Response.json({ error: '帖子不存在' }, { status: 404 });
|
||||
const existing = await pool.query(
|
||||
'SELECT id FROM reports WHERE post_id = $1 AND reporter_id = $2 AND status = $3',
|
||||
[post_id, user.id, 'pending']
|
||||
[post.id, user.id, 'pending']
|
||||
);
|
||||
if (existing.rows.length > 0) {
|
||||
return Response.json({ error: '你已经举报过此帖子,请等待处理' }, { status: 400 });
|
||||
@@ -50,7 +53,7 @@ export async function POST(req) {
|
||||
await pool.query(
|
||||
`INSERT INTO reports (post_id, reporter_id, reason)
|
||||
VALUES ($1, $2, $3)`,
|
||||
[post_id, user.id, reason]
|
||||
[post.id, user.id, reason]
|
||||
);
|
||||
return Response.json({ success: true });
|
||||
} catch {
|
||||
|
||||
+169
-16
@@ -898,14 +898,13 @@ svg {
|
||||
overflow-y: auto;
|
||||
transition: background 0.3s ease;
|
||||
}
|
||||
.page-slide.active {
|
||||
.page-slide.active:not(#pagePost):not(#pageUser):not(#pageSettings) {
|
||||
display: block;
|
||||
animation: slideIn 0.35s cubic-bezier(0.22, 1, 0.36, 1);
|
||||
}
|
||||
|
||||
#pagePost.page-slide.active,
|
||||
#pageUser.page-slide.active {
|
||||
animation: none;
|
||||
.page-slide.active:is(#pagePost, #pageUser, #pageSettings) {
|
||||
display: block;
|
||||
}
|
||||
|
||||
#pageUser {
|
||||
@@ -1043,6 +1042,136 @@ html.user-transition-settled #pageUser .user-profile-posts {
|
||||
animation: userPageContentReveal 0.28s ease-out both;
|
||||
}
|
||||
|
||||
/* ===== 设置页共享元素过渡 ===== */
|
||||
html.settings-view-transition #navbar {
|
||||
view-transition-name: persistent-navbar;
|
||||
}
|
||||
|
||||
html.settings-view-transition #pageSettings {
|
||||
animation: none;
|
||||
}
|
||||
|
||||
html.settings-view-transition #pageSettings .settings-profile-avatar {
|
||||
view-transition-name: settings-avatar;
|
||||
}
|
||||
|
||||
html.settings-view-transition #pageSettings .settings-profile-name {
|
||||
view-transition-name: settings-user-name;
|
||||
}
|
||||
|
||||
.settings-profile-name {
|
||||
display: block;
|
||||
width: fit-content;
|
||||
max-width: 100%;
|
||||
margin-left: auto !important;
|
||||
margin-right: auto !important;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
html.settings-view-transition::view-transition {
|
||||
background: linear-gradient(145deg, var(--bg-start) 0%, var(--bg-end) 100%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
html.settings-view-transition::view-transition-group(settings-avatar),
|
||||
html.settings-view-transition::view-transition-group(settings-user-name) {
|
||||
z-index: 20;
|
||||
animation-duration: 0.82s;
|
||||
animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
|
||||
}
|
||||
|
||||
html.settings-view-transition::view-transition-image-pair(settings-avatar),
|
||||
html.settings-view-transition::view-transition-old(settings-avatar),
|
||||
html.settings-view-transition::view-transition-new(settings-avatar) {
|
||||
border-radius: 50%;
|
||||
overflow: clip;
|
||||
mix-blend-mode: normal;
|
||||
}
|
||||
|
||||
html.settings-view-transition::view-transition-old(settings-avatar),
|
||||
html.settings-view-transition::view-transition-new(settings-avatar),
|
||||
html.settings-view-transition::view-transition-old(settings-user-name),
|
||||
html.settings-view-transition::view-transition-new(settings-user-name) {
|
||||
animation: none;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
mix-blend-mode: normal;
|
||||
}
|
||||
|
||||
html.settings-view-transition.settings-name-fade-only::view-transition-new(settings-user-name) {
|
||||
animation: settingsNameReveal 0.26s 0.56s ease-out both;
|
||||
}
|
||||
|
||||
html.settings-view-transition::view-transition-old(root) {
|
||||
animation: settingsSourceFadeOut 0.34s 0.16s ease-out both;
|
||||
}
|
||||
|
||||
html.settings-view-transition::view-transition-new(root) {
|
||||
animation: settingsShellReveal 0.3s 0.52s ease-out both;
|
||||
}
|
||||
|
||||
html.settings-view-transition.returning-settings-home::view-transition-old(root) {
|
||||
animation: settingsShellHide 0.3s 0.06s ease-in both;
|
||||
}
|
||||
|
||||
html.settings-view-transition.returning-settings-home::view-transition-new(root) {
|
||||
animation: settingsFeedReveal 0.34s 0.3s ease-out both;
|
||||
}
|
||||
|
||||
html.settings-view-transition.returning-settings-home.settings-name-return-fade-only::view-transition-old(settings-user-name) {
|
||||
animation: settingsNameReturnHide 0.26s 0.34s ease-in both;
|
||||
}
|
||||
|
||||
html.settings-view-transition::view-transition-group(persistent-navbar),
|
||||
html.settings-view-transition::view-transition-old(persistent-navbar),
|
||||
html.settings-view-transition::view-transition-new(persistent-navbar) {
|
||||
animation: none;
|
||||
mix-blend-mode: normal;
|
||||
}
|
||||
|
||||
html.settings-navbar-avatar-hidden #navbar #userDropdown .avatar {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
html.settings-navbar-avatar-reveal #navbar #userDropdown .avatar {
|
||||
animation: settingsNavbarAvatarReveal 0.32s ease-out both;
|
||||
}
|
||||
|
||||
@keyframes settingsSourceFadeOut {
|
||||
from { opacity: 1; }
|
||||
to { opacity: 0; }
|
||||
}
|
||||
|
||||
@keyframes settingsShellReveal {
|
||||
from { opacity: 0; }
|
||||
to { opacity: 1; }
|
||||
}
|
||||
|
||||
@keyframes settingsShellHide {
|
||||
from { opacity: 1; }
|
||||
to { opacity: 0; }
|
||||
}
|
||||
|
||||
@keyframes settingsFeedReveal {
|
||||
from { opacity: 0; }
|
||||
to { opacity: 1; }
|
||||
}
|
||||
|
||||
@keyframes settingsNameReveal {
|
||||
from { opacity: 0; transform: translateY(4px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
@keyframes settingsNameReturnHide {
|
||||
from { opacity: 1; transform: translateY(0); }
|
||||
to { opacity: 0; transform: translateY(4px); }
|
||||
}
|
||||
|
||||
@keyframes settingsNavbarAvatarReveal {
|
||||
from { opacity: 0; }
|
||||
to { opacity: 1; }
|
||||
}
|
||||
|
||||
@keyframes userAvatarSourceOut {
|
||||
from { opacity: 1; }
|
||||
to { opacity: 0; }
|
||||
@@ -1158,7 +1287,7 @@ html.home-view-transition.returning-home #pagePost .post-detail-card > .post-con
|
||||
|
||||
html.post-view-transition #pagePost .post-detail-card > .post-images,
|
||||
html.home-view-transition.returning-home #pagePost .post-detail-card > .post-images {
|
||||
view-transition-name: post-detail-media;
|
||||
view-transition-name: post-media;
|
||||
}
|
||||
|
||||
html.post-view-transition #pagePost .post-detail-card .post-pin-state,
|
||||
@@ -1273,6 +1402,31 @@ html.home-view-transition.returning-home::view-transition-image-pair(post-body)
|
||||
overflow: clip;
|
||||
}
|
||||
|
||||
html.post-view-transition::view-transition-group(post-media),
|
||||
html.home-view-transition.returning-home::view-transition-group(post-media) {
|
||||
z-index: 12;
|
||||
animation-duration: 0.96s;
|
||||
animation-timing-function: cubic-bezier(0.42, 0, 0.58, 1);
|
||||
}
|
||||
|
||||
html.home-view-transition.returning-home::view-transition-group(post-media) {
|
||||
animation-duration: 1.1s;
|
||||
}
|
||||
|
||||
html.post-view-transition::view-transition-image-pair(post-media),
|
||||
html.home-view-transition.returning-home::view-transition-image-pair(post-media) {
|
||||
overflow: clip;
|
||||
}
|
||||
|
||||
html.post-view-transition::view-transition-old(post-media),
|
||||
html.post-view-transition::view-transition-new(post-media),
|
||||
html.home-view-transition.returning-home::view-transition-old(post-media),
|
||||
html.home-view-transition.returning-home::view-transition-new(post-media) {
|
||||
animation: none;
|
||||
opacity: 1;
|
||||
mix-blend-mode: normal;
|
||||
}
|
||||
|
||||
html.post-view-transition::view-transition-group(post-time) {
|
||||
animation-duration: 0.8s;
|
||||
animation-timing-function: cubic-bezier(0.42, 0, 0.58, 1);
|
||||
@@ -1377,14 +1531,8 @@ html.post-view-transition::view-transition-new(post-body) {
|
||||
object-position: left top;
|
||||
}
|
||||
|
||||
html.post-view-transition::view-transition-old(post-feed-media) {
|
||||
animation: none;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
html.post-view-transition::view-transition-new(post-detail-controls),
|
||||
html.post-view-transition::view-transition-new(post-detail-signature),
|
||||
html.post-view-transition::view-transition-new(post-detail-media) {
|
||||
html.post-view-transition::view-transition-new(post-detail-signature) {
|
||||
animation: detailOnlyPartIn 0.22s 0.62s ease-out both;
|
||||
}
|
||||
|
||||
@@ -1504,8 +1652,7 @@ html.home-view-transition.returning-home::view-transition-new(post-edited-label)
|
||||
}
|
||||
|
||||
html.home-view-transition.returning-home::view-transition-old(post-detail-controls),
|
||||
html.home-view-transition.returning-home::view-transition-old(post-detail-signature),
|
||||
html.home-view-transition.returning-home::view-transition-old(post-detail-media) {
|
||||
html.home-view-transition.returning-home::view-transition-old(post-detail-signature) {
|
||||
animation: returnDetailOnlyPartOut 0.22s 0.12s ease-out both;
|
||||
}
|
||||
|
||||
@@ -1576,8 +1723,7 @@ html.home-view-transition.returning-home::view-transition-old(reply-loading-retu
|
||||
}
|
||||
}
|
||||
|
||||
html.home-view-transition.returning-home::view-transition-new(post-feed-actions),
|
||||
html.home-view-transition.returning-home::view-transition-new(post-feed-media) {
|
||||
html.home-view-transition.returning-home::view-transition-new(post-feed-actions) {
|
||||
animation: returnFeedOnlyPartIn 0.28s 0.44s ease-out both;
|
||||
}
|
||||
|
||||
@@ -1603,6 +1749,13 @@ html.home-view-transition.returning-home::view-transition-new(post-body) {
|
||||
to { opacity: 1; }
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.page-slide.active,
|
||||
html.settings-navbar-avatar-reveal #navbar #userDropdown .avatar {
|
||||
animation: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes returnSharedPartOut {
|
||||
from { opacity: 1; }
|
||||
to { opacity: 0; }
|
||||
|
||||
+4
-14
@@ -1,19 +1,9 @@
|
||||
// 主页:Server Component —— 从 cookie 读取缓存论坛名(SSR 首帧即输出),
|
||||
// 其余逻辑在客户端 HomeClient 中
|
||||
import { cookies } from 'next/headers';
|
||||
import HomeClient from './HomeClient';
|
||||
// 主页:Server Component,路径页面共用同一个客户端应用外壳。
|
||||
import ForumPage from './ForumPage';
|
||||
|
||||
// cookies() 是动态 API:禁止静态优化,每次请求 SSR
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export default async function Home() {
|
||||
let cachedName = '';
|
||||
try {
|
||||
// Next 15+:cookies() 返回 Promise,必须 await
|
||||
const cookieStore = await cookies();
|
||||
cachedName = decodeURIComponent(cookieStore.get('forumlify-name')?.value || '');
|
||||
} catch (e) {
|
||||
cachedName = '';
|
||||
}
|
||||
return <HomeClient cachedName={cachedName} />;
|
||||
export default function Home() {
|
||||
return <ForumPage />;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import ForumPage from '../../ForumPage';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export default function PostPage() {
|
||||
return <ForumPage />;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import ForumPage from '../../ForumPage';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export default function UserPage() {
|
||||
return <ForumPage />;
|
||||
}
|
||||
Reference in new issue
Block a user