feat: 放宽 MongoDB 超时(Atlas) + 热搜 3D 词云(Top10) + i18n 补充

This commit is contained in:
ice-a
2026-10-16 19:06:03 +08:00
parent d6999104bf
commit e1572e1327
6 changed files with 202 additions and 7 deletions
+21
View File
@@ -0,0 +1,21 @@
import { searchesCol, tryMongo } from '../utils/mongo'
/** 热搜关键词:按搜索次数降序,返回前 N 个 */
export default defineEventHandler(async (event) => {
const limit = Math.min(Number(getQuery(event).limit) || 10, 50)
const data = await tryMongo(async () => {
const col = await searchesCol()
const hot = await col
.aggregate<{ _id: string; count: number; last: Date }>([
{ $group: { _id: '$keyword', count: { $sum: 1 }, last: { $max: '$createdAt' } } },
{ $sort: { count: -1, last: -1 } },
{ $limit: limit }
])
.toArray()
return hot.map((h) => ({ keyword: h._id, count: h.count, last: h.last }))
})
if (!data) return { keywords: [], offline: true }
return { keywords: data, offline: false }
})