数据结构优化
This commit is contained in:
@@ -560,6 +560,19 @@ export const fetchPost = async (id: number | string): Promise<Post> => {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取推荐文章(基于IP的协同过滤)
|
||||
export const getRecommendedPosts = async (postId: number | string, limit: number = 3): Promise<Post[]> => {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/posts/${postId}/recommendations?limit=${limit}`)
|
||||
if (!response.ok) throw new Error('Failed to fetch recommended posts')
|
||||
const data = await response.json()
|
||||
return data.result || []
|
||||
} catch (error) {
|
||||
console.error(`Error fetching recommended posts for ${postId}:`, error)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
export const createPost = async (postData: Omit<Post, 'id'>): Promise<void> => {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/admin/posts`, {
|
||||
|
||||
Reference in New Issue
Block a user