diff --git a/services/our/src/plugins/vods.ts b/services/our/src/plugins/vods.ts index d434c65..9aa3761 100644 --- a/services/our/src/plugins/vods.ts +++ b/services/our/src/plugins/vods.ts @@ -29,55 +29,51 @@ export default async function vodsRoutes( fastify: FastifyInstance, ): Promise { fastify.get('/vods', async function (request, reply) { - const userId = request.session.get('userId') - let user = await prisma.user.findFirstOrThrow({ - where: { - id: userId - }, - include: { - roles: true - } - }) + const userId = request.session.get('userId'); + + + let user = null + if (userId !== undefined) { + user = await prisma.user.findUnique({ + where: { id: userId }, + include: { roles: true } + }) + } + const { cursor: cursorRaw, search = '' } = request.query as { - cursor?: string; // query strings are strings + cursor?: string; search?: string; }; const cursor = cursorRaw ? parseInt(cursorRaw, 10) : undefined; - // if (!cursor) throw new Error('cursor missing'); // is this necessary? + if (cursorRaw && isNaN(cursor)) { return reply.status(400).send({ error: 'Invalid cursor value' }); } const vods = await prisma.vod.findMany({ - where: search ? { - status: 'processed', - name: { - contains: search, - mode: 'insensitive', - }, - } : { + where: { status: { - in: [ - 'approved', 'processed', 'processing' - ] - } + in: ['approved', 'processed', 'processing'], + }, }, orderBy: { createdAt: 'desc' }, include: { vtubers: true, - stream: true - } + stream: true, + }, }); return reply.viewAsync('vods.hbs', { user, vods, - site: constants.site + site: constants.site, }); }); + + fastify.get('/vods/:id', async function (request, reply) { const { id } = request.params as { id: string }; diff --git a/services/our/src/plugins/vtubers.ts b/services/our/src/plugins/vtubers.ts index 8b9226d..129aaaa 100644 --- a/services/our/src/plugins/vtubers.ts +++ b/services/our/src/plugins/vtubers.ts @@ -18,23 +18,19 @@ export default async function vtubersRoutes( fastify.get('/vtubers', async function (request, reply) { const userId = request.session.get('userId') - let user = await prisma.user.findFirstOrThrow({ - where: { - id: userId - }, - include: { - roles: true - } - }) - + console.log(`userId=${userId}`) + let user = null + if (userId !== undefined) { + user = await prisma.user.findUnique({ + where: { id: userId }, + include: { roles: true } + }) + } const vtubers = await prisma.vtuber.findMany({ orderBy: { createdAt: 'desc' }, - include: { - vods: true, - // streams: true - } + include: { vods: true } }); return reply.viewAsync('vtubers/list.hbs', { @@ -44,6 +40,7 @@ export default async function vtubersRoutes( }); }); + fastify.get('/vtubers/new', async function (request, reply) { const userId = request.session.get('userId');