2024-04-25 20:24:29 +00:00

20 lines
554 B
JavaScript

import { FeaturedWallpaper } from "@db_models"
export default async (req) => {
let { limit = 10, offset = 0, random = false } = req.query
if (random) {
const items = await FeaturedWallpaper.countDocuments({ active: true })
offset = Math.floor(Math.random() * items)
const wallapers = await FeaturedWallpaper.find({ active: true }).skip(offset).limit(1)
return wallapers[0]
}
const wallapers = await FeaturedWallpaper.find({
active: true
}).skip(offset).limit(limit)
return wallapers
}