refactor: 重构并修复博客相关API

This commit is contained in:
2025-12-19 21:06:19 +08:00
parent b69d64f726
commit b0502d4d46
6 changed files with 72 additions and 48 deletions

View File

@@ -0,0 +1,25 @@
import { BlogComment } from "@/lib/types/blogComment";
import { clientFetch } from "../client";
export async function getBlog(id: string, password?: string) {
return clientFetch<{
id: string;
title: string;
createdAt: string;
content: string;
}>(`/api/blog/${id}` + (password ? `?p=${password}` : ''));
}
export async function getComments(id: string) {
return clientFetch<BlogComment[]>(`/api/blog/${id}/comments`);
}
export async function createComment(blogId: string, content: string, parentId?: string) {
return clientFetch<BlogComment>(`/api/blog/${blogId}/comment`, {
method: 'POST',
body: JSON.stringify({
content,
parentId: parentId || null,
}),
});
}