feat: 增加收藏、下载种子数据功能

This commit is contained in:
R524809
2026-05-11 12:38:10 +08:00
parent debecd67c6
commit 39b8e01c23
11 changed files with 521 additions and 21 deletions
+18 -11
View File
@@ -15,6 +15,13 @@ function ageBand(min, max) {
return `${min}-${max}`;
}
function mergeSeedStats(items) {
for (const item of items) {
item.likes = (item.likes || 0) + (item.likes_seed || 0);
item.downloads = (item.downloads || 0) + (item.downloads_seed || 0);
}
}
function toHomeDisplayItem(ws) {
return {
id: ws._id,
@@ -87,21 +94,21 @@ exports.main = async () => {
return { success: true, message: '定时任务已暂停,跳过执行' };
}
// Query top 5 by downloads
const { data: topDownloads } = await db
const { data: allActive } = await db
.collection('worksheets')
.where({ status: 'active' })
.orderBy('downloads', 'desc')
.limit(5)
.limit(100)
.get();
// Query top 5 by likes
const { data: topLikes } = await db
.collection('worksheets')
.where({ status: 'active' })
.orderBy('likes', 'desc')
.limit(5)
.get();
mergeSeedStats(allActive);
const topDownloads = [...allActive]
.sort((a, b) => (b.downloads || 0) - (a.downloads || 0))
.slice(0, 5);
const topLikes = [...allActive]
.sort((a, b) => (b.likes || 0) - (a.likes || 0))
.slice(0, 5);
const featured = topDownloads.map(toHomeDisplayItem);
const hot = topLikes.map(toHomeDisplayItem);