Initial commit

This commit is contained in:
2026-06-05 17:46:51 +08:00
commit c04c890186
96 changed files with 6477 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
const cloud = require('wx-server-sdk')
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })
const db = cloud.database()
exports.main = async (event, context) => {
const { OPENID } = cloud.getWXContext()
const { postId } = event
if (!postId) return { code: -1, message: '缺少 postId' }
try {
const post = await db.collection('posts').doc(postId).get()
if (!post.data) return { code: -1, message: '帖子不存在' }
const authorRes = await db.collection('users')
.where({ openid: post.data.authorId })
.field({ nickName: true, avatarUrl: true, openid: true, pets: true })
.get()
const likeRes = await db.collection('likes')
.where({ userId: OPENID, postId })
.count()
return {
code: 0,
data: {
...post.data,
author: authorRes.data[0] || null,
isLiked: likeRes.total > 0,
},
}
} catch (e) {
return { code: -1, message: e.message }
}
}