|
|
|
@ -132,7 +132,7 @@ app.post('/api/eggbar/posts', async (req, res) => { |
|
|
|
console.log('===== 收到帖子创建请求 ====='); |
|
|
|
console.log('1. 收到请求体:', JSON.stringify(req.body, null, 2)); |
|
|
|
|
|
|
|
const { user_id, content, images, topic, phone } = req.body; |
|
|
|
const { user_id, content, images, topic, phone, avatar_url } = req.body; |
|
|
|
|
|
|
|
// 数据验证
|
|
|
|
if (!user_id) { |
|
|
|
@ -153,6 +153,7 @@ app.post('/api/eggbar/posts', async (req, res) => { |
|
|
|
const newPost = await EggbarPost.create({ |
|
|
|
user_id: user_id, |
|
|
|
phone: phone || null, |
|
|
|
avatar_url: avatar_url || null, |
|
|
|
content: content || null, |
|
|
|
images: imagesData, |
|
|
|
topic: topic || null |
|
|
|
@ -260,6 +261,7 @@ app.get('/api/eggbar/posts', async (req, res) => { |
|
|
|
id: post.id, |
|
|
|
user_id: post.user_id, |
|
|
|
phone: post.phone, |
|
|
|
avatar_url: post.avatar_url, |
|
|
|
content: post.content, |
|
|
|
images: images, |
|
|
|
topic: post.topic, |
|
|
|
@ -272,8 +274,29 @@ app.get('/api/eggbar/posts', async (req, res) => { |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
// 检查用户是否已点赞
|
|
|
|
// 获取当前用户信息
|
|
|
|
const phone = req.query.phone || req.headers['x-phone']; |
|
|
|
const userId = req.query.userId || req.headers['x-user-id']; |
|
|
|
|
|
|
|
// 根据status字段和用户信息过滤动态
|
|
|
|
formattedPosts = formattedPosts.filter(post => { |
|
|
|
// 获取帖子状态,默认为0
|
|
|
|
const postStatus = post.status || 0; |
|
|
|
|
|
|
|
// status=1:审核通过,所有用户都可见
|
|
|
|
if (postStatus === 1) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
// status=0(待审核)或2(拒绝):只有发布者可见
|
|
|
|
// 检查是否是发布者(通过phone或userId)
|
|
|
|
const isPublisherByPhone = phone && post.phone === phone; |
|
|
|
const isPublisherByUserId = userId && post.user_id === userId; |
|
|
|
|
|
|
|
return isPublisherByPhone || isPublisherByUserId; |
|
|
|
}); |
|
|
|
|
|
|
|
// 检查用户是否已点赞
|
|
|
|
if (phone) { |
|
|
|
try { |
|
|
|
// 批量检查点赞状态
|
|
|
|
@ -1743,6 +1766,11 @@ EggbarPost.init({ |
|
|
|
allowNull: true, |
|
|
|
comment: '用户电话号码' |
|
|
|
}, |
|
|
|
avatar_url: { |
|
|
|
type: DataTypes.TEXT, |
|
|
|
allowNull: true, |
|
|
|
comment: '用户头像URL' |
|
|
|
}, |
|
|
|
content: { |
|
|
|
type: DataTypes.TEXT, |
|
|
|
allowNull: true, |
|
|
|
|