chore: 清理冗余代码并补全私信/搜索/故事/通知功能
- 删除未使用的空组件目录、死代码导出(clearAuth/calcDistance/COLORS/ AVATAR_GRADIENTS/Message/TabBarItem/deletePost/uploadImage/getFileURL/ _initLogin),确保程序仍可正常运行 - 新增 8 个云函数并补全对应页面逻辑:getMessages/sendMessage(私信聊天)、 getHotTopics/searchPosts/searchUsers(搜索)、getStory(故事,复用 posts 集合)、getNotifications/markAllRead(基于点赞评论聚合的通知系统) - 在 cloudbaserc.json 中注册全部新云函数,并通过 --deployMode zip 完成部署 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
32
cloudfunctions/getHotTopics/index.js
Normal file
32
cloudfunctions/getHotTopics/index.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const cloud = require('wx-server-sdk')
|
||||
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })
|
||||
const db = cloud.database()
|
||||
const SCAN_LIMIT = 200
|
||||
const TOP_N = 10
|
||||
|
||||
exports.main = async (event, context) => {
|
||||
try {
|
||||
const res = await db.collection('posts')
|
||||
.orderBy('createdAt', 'desc')
|
||||
.limit(SCAN_LIMIT)
|
||||
.field({ hashtags: true })
|
||||
.get()
|
||||
|
||||
const counts = {}
|
||||
res.data.forEach(p => {
|
||||
;(p.hashtags || []).forEach(tag => {
|
||||
if (!tag) return
|
||||
counts[tag] = (counts[tag] || 0) + 1
|
||||
})
|
||||
})
|
||||
|
||||
const topics = Object.keys(counts)
|
||||
.map(tag => ({ tag, count: counts[tag] }))
|
||||
.sort((a, b) => b.count - a.count)
|
||||
.slice(0, TOP_N)
|
||||
|
||||
return { code: 0, data: topics }
|
||||
} catch (e) {
|
||||
return { code: -1, message: e.message }
|
||||
}
|
||||
}
|
||||
1
cloudfunctions/getHotTopics/package.json
Normal file
1
cloudfunctions/getHotTopics/package.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "name": "getHotTopics", "version": "1.0.0", "main": "index.js", "dependencies": { "wx-server-sdk": "~2.1.2" } }
|
||||
Reference in New Issue
Block a user