backend/controller/latest.js

35 lines
909 B
JavaScript
Raw Normal View History

2023-03-03 16:44:40 +00:00
const { PrismaClient } = require('@prisma/client')
2024-02-15 15:13:12 +00:00
const redis = require('../utils/redis.js')
2023-03-03 16:44:40 +00:00
const prisma = new PrismaClient()
exports.getLatest = async (req, res) => {
2024-02-15 15:13:12 +00:00
let json
const cached = await redis.get('latest')
if (cached) {
json = JSON.parse(cached)
} else {
json = await prisma.videos.findMany({
take: 90,
orderBy: [
{
archived: 'desc'
}
],
select: {
id: true,
title: true,
thumbnail: true,
published: true,
archived: true,
channel: true,
channelId: true,
channelAvatar: true,
channelVerified: true
2023-03-03 16:44:40 +00:00
}
2024-02-15 15:13:12 +00:00
})
await redis.set('latest', JSON.stringify(json), 'EX', 3600)
}
res.json(json)
2023-03-03 16:44:40 +00:00
}