allow anon requests
This commit is contained in:
parent
330e38db75
commit
07deb092e8
@ -29,55 +29,51 @@ export default async function vodsRoutes(
|
|||||||
fastify: FastifyInstance,
|
fastify: FastifyInstance,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
fastify.get('/vods', async function (request, reply) {
|
fastify.get('/vods', async function (request, reply) {
|
||||||
const userId = request.session.get('userId')
|
const userId = request.session.get('userId');
|
||||||
let user = await prisma.user.findFirstOrThrow({
|
|
||||||
where: {
|
|
||||||
id: userId
|
let user = null
|
||||||
},
|
if (userId !== undefined) {
|
||||||
include: {
|
user = await prisma.user.findUnique({
|
||||||
roles: true
|
where: { id: userId },
|
||||||
}
|
include: { roles: true }
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const { cursor: cursorRaw, search = '' } = request.query as {
|
const { cursor: cursorRaw, search = '' } = request.query as {
|
||||||
cursor?: string; // query strings are strings
|
cursor?: string;
|
||||||
search?: string;
|
search?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const cursor = cursorRaw ? parseInt(cursorRaw, 10) : undefined;
|
const cursor = cursorRaw ? parseInt(cursorRaw, 10) : undefined;
|
||||||
// if (!cursor) throw new Error('cursor missing'); // is this necessary?
|
|
||||||
if (cursorRaw && isNaN(cursor)) {
|
if (cursorRaw && isNaN(cursor)) {
|
||||||
return reply.status(400).send({ error: 'Invalid cursor value' });
|
return reply.status(400).send({ error: 'Invalid cursor value' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const vods = await prisma.vod.findMany({
|
const vods = await prisma.vod.findMany({
|
||||||
where: search ? {
|
where: {
|
||||||
status: 'processed',
|
|
||||||
name: {
|
|
||||||
contains: search,
|
|
||||||
mode: 'insensitive',
|
|
||||||
},
|
|
||||||
} : {
|
|
||||||
status: {
|
status: {
|
||||||
in: [
|
in: ['approved', 'processed', 'processing'],
|
||||||
'approved', 'processed', 'processing'
|
},
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
orderBy: { createdAt: 'desc' },
|
orderBy: { createdAt: 'desc' },
|
||||||
include: {
|
include: {
|
||||||
vtubers: true,
|
vtubers: true,
|
||||||
stream: true
|
stream: true,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return reply.viewAsync('vods.hbs', {
|
return reply.viewAsync('vods.hbs', {
|
||||||
user,
|
user,
|
||||||
vods,
|
vods,
|
||||||
site: constants.site
|
site: constants.site,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fastify.get('/vods/:id', async function (request, reply) {
|
fastify.get('/vods/:id', async function (request, reply) {
|
||||||
const { id } = request.params as { id: string };
|
const { id } = request.params as { id: string };
|
||||||
|
|
||||||
|
@ -18,23 +18,19 @@ export default async function vtubersRoutes(
|
|||||||
|
|
||||||
fastify.get('/vtubers', async function (request, reply) {
|
fastify.get('/vtubers', async function (request, reply) {
|
||||||
const userId = request.session.get('userId')
|
const userId = request.session.get('userId')
|
||||||
let user = await prisma.user.findFirstOrThrow({
|
console.log(`userId=${userId}`)
|
||||||
where: {
|
|
||||||
id: userId
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
roles: true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
let user = null
|
||||||
|
if (userId !== undefined) {
|
||||||
|
user = await prisma.user.findUnique({
|
||||||
|
where: { id: userId },
|
||||||
|
include: { roles: true }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const vtubers = await prisma.vtuber.findMany({
|
const vtubers = await prisma.vtuber.findMany({
|
||||||
orderBy: { createdAt: 'desc' },
|
orderBy: { createdAt: 'desc' },
|
||||||
include: {
|
include: { vods: true }
|
||||||
vods: true,
|
|
||||||
// streams: true
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return reply.viewAsync('vtubers/list.hbs', {
|
return reply.viewAsync('vtubers/list.hbs', {
|
||||||
@ -44,6 +40,7 @@ export default async function vtubersRoutes(
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
fastify.get('/vtubers/new', async function (request, reply) {
|
fastify.get('/vtubers/new', async function (request, reply) {
|
||||||
const userId = request.session.get('userId');
|
const userId = request.session.get('userId');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user