feat: DSL 磁力聚合 — 搜索/解析/预览/投递 + cilisousuo 源 + 中英双语 + Docker 部署
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { searchesCol, torrentsCol, tryMongo } from '../utils/mongo'
|
||||
|
||||
/** 搜索历史 + 高频关键词 */
|
||||
export default defineEventHandler(async (event) => {
|
||||
const limit = Math.min(Number(getQuery(event).limit) || 50, 200)
|
||||
|
||||
const data = await tryMongo(async () => {
|
||||
const col = await searchesCol()
|
||||
const items = await col.find({}).sort({ createdAt: -1 }).limit(limit).toArray()
|
||||
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: 12 }
|
||||
])
|
||||
.toArray()
|
||||
const total = await col.estimatedDocumentCount()
|
||||
const torrentTotal = await (await torrentsCol()).estimatedDocumentCount()
|
||||
return {
|
||||
items: items.map((it) => ({ ...it, _id: String(it._id) })),
|
||||
hot: hot.map((h) => ({ keyword: h._id, count: h.count, last: h.last })),
|
||||
total,
|
||||
torrentTotal
|
||||
}
|
||||
})
|
||||
|
||||
if (!data) {
|
||||
return { items: [], hot: [], total: 0, torrentTotal: 0, offline: true }
|
||||
}
|
||||
return { ...data, offline: false }
|
||||
})
|
||||
Reference in New Issue
Block a user