feat(wiki): add tag-based wiki recommendations API
This commit is contained in:
parent
3797ff7925
commit
d3a5c1a3a7
3 changed files with 217 additions and 0 deletions
32
server/api/wiki/recommended.get.js
Normal file
32
server/api/wiki/recommended.get.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import WikiArticle from '../../models/wikiArticle.js'
|
||||
import { connectDB } from '../../utils/mongoose.js'
|
||||
import { requireAuth } from '../../utils/auth.js'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const member = await requireAuth(event)
|
||||
|
||||
// Combine craft tags and cooperative ecology tags
|
||||
const craftTags = member.craftTags || []
|
||||
const ecologyTags = (member.communityEcology?.topics || []).map(t => t.tagSlug)
|
||||
const memberTags = [...new Set([...craftTags, ...ecologyTags].filter(Boolean))]
|
||||
|
||||
if (!memberTags.length) {
|
||||
return []
|
||||
}
|
||||
|
||||
await connectDB()
|
||||
|
||||
const query = getQuery(event)
|
||||
const limit = Math.min(Math.max(parseInt(query.limit) || 10, 1), 25)
|
||||
|
||||
const articles = await WikiArticle.find({
|
||||
tags: { $in: memberTags },
|
||||
publishedAt: { $ne: null }
|
||||
})
|
||||
.sort({ publishedAt: -1 })
|
||||
.limit(limit)
|
||||
.select('title url summary tags collection publishedAt')
|
||||
.lean()
|
||||
|
||||
return articles
|
||||
})
|
||||
20
server/models/wikiArticle.js
Normal file
20
server/models/wikiArticle.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import mongoose from 'mongoose'
|
||||
|
||||
const wikiArticleSchema = new mongoose.Schema(
|
||||
{
|
||||
outlineId: { type: String, unique: true, required: true },
|
||||
title: { type: String, required: true },
|
||||
collection: String,
|
||||
url: { type: String, required: true },
|
||||
summary: String,
|
||||
tags: [{ type: String }],
|
||||
publishedAt: Date,
|
||||
permission: String,
|
||||
lastSyncedAt: Date,
|
||||
outlineUpdatedAt: Date
|
||||
},
|
||||
{ timestamps: true }
|
||||
)
|
||||
|
||||
export default mongoose.models.WikiArticle ||
|
||||
mongoose.model('WikiArticle', wikiArticleSchema)
|
||||
Loading…
Add table
Add a link
Reference in a new issue