数据结构优化

This commit is contained in:
李琦
2026-01-20 15:43:17 +08:00
parent 1ec015217e
commit 8460820f58
7 changed files with 327 additions and 65 deletions

View File

@@ -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`, {