Skip to content

Commit

Permalink
增加我喜欢的
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghao1993 committed Sep 10, 2024
1 parent 2ca7a0a commit 27d78cc
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
48 changes: 48 additions & 0 deletions app/api/blog/praise/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { BusinessCode, responseHandler } from "@/lib/fetch_utils";
import prisma from "@/lib/pg";
import { getServerSession } from "next-auth";
import { authOptions } from "@/lib/auth_options";
import { z } from "zod";
import { NextRequest, NextResponse } from "next/server";
import { getToken } from "next-auth/jwt";

export const dynamic = "force-dynamic";

const postDetailSchema = z.object({
blog_key: z.string(),
// 其他字段的验证规则,如果有的话
});

export async function GET(request: NextRequest) {
const key = new URL(request.url).searchParams.get("key");
if (!key) {
return responseHandler(
null,
BusinessCode.normal,
BusinessCode.abnormal,
"无 key"
);
}
try {
const res = await prisma.post.findUnique({
where: { blog_key: key },
});
if (!res) {
return responseHandler(
null,
BusinessCode.normal,
BusinessCode.abnormal,
"key 值错误"
);
}
return responseHandler(res);
} catch (error: any) {
console.error("GET 请求错误:", error);
return responseHandler(
null,
BusinessCode.normal,
BusinessCode.abnormal,
"未知异常"
);
}
}
9 changes: 9 additions & 0 deletions app/my/praise/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import MainLayout from "@/Layouts/MainLayout";
import ArticleList from "@/components/Article/ArticleList";
export default function MyPraise() {
return (
<MainLayout>
<ArticleList posts={[]}></ArticleList>
</MainLayout>
);
}
8 changes: 6 additions & 2 deletions lib/auth_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ export const authOptions: AuthOptions = {
maxAge: 2 * 24 * 60 * 60,
},
callbacks: {
session: async (data: { session: any }) => {
return data.session;
session: async ({ session, token, user }) => {
session.user.id = user?.id;
return session;
},
jwt(params) {
return params.token;
},
},

Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"@/content/*": [
"content/*"
],
"@/layouts/*": [
"components/layouts/*"
"@/Layouts/*": [
"components/Layouts/*"
],
"contentlayer/generated": [
"./.contentlayer/generated"
Expand Down

0 comments on commit 27d78cc

Please sign in to comment.