初始化
This commit is contained in:
@@ -56,7 +56,7 @@ export interface Work {
|
||||
|
||||
// 文章相关类型
|
||||
export interface Post {
|
||||
id: string
|
||||
id: number
|
||||
title: string
|
||||
category: string
|
||||
date: string
|
||||
@@ -67,7 +67,7 @@ export interface Post {
|
||||
|
||||
export interface PostHistory {
|
||||
id: number
|
||||
postId: string
|
||||
postId: number
|
||||
version: number
|
||||
title: string
|
||||
category: string
|
||||
@@ -425,9 +425,13 @@ export const getAdminPosts = async (): Promise<Post[]> => {
|
||||
}
|
||||
}
|
||||
|
||||
export const fetchPosts = async (): Promise<Post[]> => {
|
||||
export const fetchPosts = async (query?: string): Promise<Post[]> => {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/posts`)
|
||||
let url = `${API_BASE}/posts`
|
||||
if (query) {
|
||||
url += `?q=${encodeURIComponent(query)}`
|
||||
}
|
||||
const response = await fetch(url)
|
||||
if (!response.ok) throw new Error('Failed to fetch posts')
|
||||
return await response.json()
|
||||
} catch (error) {
|
||||
@@ -436,7 +440,7 @@ export const fetchPosts = async (): Promise<Post[]> => {
|
||||
}
|
||||
}
|
||||
|
||||
export const fetchPost = async (id: string): Promise<Post> => {
|
||||
export const fetchPost = async (id: number | string): Promise<Post> => {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/posts/${id}`)
|
||||
if (!response.ok) throw new Error('Failed to fetch post')
|
||||
@@ -444,7 +448,7 @@ export const fetchPost = async (id: string): Promise<Post> => {
|
||||
} catch (error) {
|
||||
console.error(`Error fetching post ${id}:`, error)
|
||||
return {
|
||||
id: id,
|
||||
id: Number(id),
|
||||
title: '默认文章',
|
||||
category: '默认分类',
|
||||
date: '2024-01-01'
|
||||
@@ -469,7 +473,7 @@ export const createPost = async (postData: Omit<Post, 'id'>): Promise<void> => {
|
||||
}
|
||||
}
|
||||
|
||||
export const updatePost = async (id: string, postData: Omit<Post, 'id'>): Promise<void> => {
|
||||
export const updatePost = async (id: number | string, postData: Omit<Post, 'id'>): Promise<void> => {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/admin/posts/${id}`, {
|
||||
method: 'PUT',
|
||||
@@ -486,7 +490,7 @@ export const updatePost = async (id: string, postData: Omit<Post, 'id'>): Promis
|
||||
}
|
||||
}
|
||||
|
||||
export const deletePost = async (id: string): Promise<void> => {
|
||||
export const deletePost = async (id: number | string): Promise<void> => {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/admin/posts/${id}`, {
|
||||
method: 'DELETE',
|
||||
@@ -503,7 +507,7 @@ export const deletePost = async (id: string): Promise<void> => {
|
||||
}
|
||||
|
||||
// 文章历史记录API
|
||||
export const getPostHistory = async (postId: string): Promise<PostHistory[]> => {
|
||||
export const getPostHistory = async (postId: number | string): Promise<PostHistory[]> => {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/admin/posts/${postId}/history`, {
|
||||
headers: getAuthHeaders()
|
||||
@@ -519,7 +523,7 @@ export const getPostHistory = async (postId: string): Promise<PostHistory[]> =>
|
||||
}
|
||||
}
|
||||
|
||||
export const getPostHistoryByVersion = async (postId: string, version: number): Promise<PostHistory> => {
|
||||
export const getPostHistoryByVersion = async (postId: number | string, version: number): Promise<PostHistory> => {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/admin/posts/${postId}/history/${version}`, {
|
||||
headers: getAuthHeaders()
|
||||
|
||||
Reference in New Issue
Block a user