From 6d2d071293ca0d32376e012f53b0cb716e7b1631 Mon Sep 17 00:00:00 2001 From: diced Date: Fri, 2 Dec 2022 08:37:13 -0800 Subject: [PATCH] fix: max call stack error --- src/lib/config/readConfig.ts | 1 - src/lib/config/validateConfig.ts | 2 +- src/pages/api/auth/image.ts | 10 +++++----- src/pages/api/auth/invite.ts | 3 +++ 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/lib/config/readConfig.ts b/src/lib/config/readConfig.ts index 18f7d04..9b72abd 100644 --- a/src/lib/config/readConfig.ts +++ b/src/lib/config/readConfig.ts @@ -3,7 +3,6 @@ import { expand } from 'dotenv-expand'; import { existsSync, readFileSync } from 'fs'; import Logger from '../logger'; import { humanToBytes } from '../utils/bytes'; -import { parseExpiry } from '../utils/client'; export type ValueType = 'string' | 'number' | 'boolean' | 'array' | 'json-array' | 'human-to-byte'; diff --git a/src/lib/config/validateConfig.ts b/src/lib/config/validateConfig.ts index b7f319d..fe7b522 100644 --- a/src/lib/config/validateConfig.ts +++ b/src/lib/config/validateConfig.ts @@ -1,5 +1,5 @@ import { s } from '@sapphire/shapeshift'; -import { Config } from 'lib/config/Config'; +import type { Config } from './Config'; import { inspect } from 'util'; import Logger from '../logger'; import { humanToBytes } from '../utils/bytes'; diff --git a/src/pages/api/auth/image.ts b/src/pages/api/auth/image.ts index 5129e52..9531ff1 100644 --- a/src/pages/api/auth/image.ts +++ b/src/pages/api/auth/image.ts @@ -14,14 +14,14 @@ async function handler(req: NextApiReq, res: NextApiRes) { }, }); - if (!image) return res.status(404).end(JSON.stringify({ error: 'Image not found' })); - if (!password) return res.badRequest('No password provided'); + if (!image) return res.notFound('image not found'); + if (!password) return res.badRequest('no password provided'); const valid = await checkPassword(password as string, image.password); - if (!valid) return res.badRequest('Wrong password'); + if (!valid) return res.badRequest('wrong password'); const data = await datasource.get(image.file); - if (!data) return res.notFound('Image not found'); + if (!data) return res.notFound('image not found'); const size = await datasource.size(image.file); @@ -30,7 +30,7 @@ async function handler(req: NextApiReq, res: NextApiRes) { res.setHeader('Content-Length', size); data.pipe(res); - data.on('error', () => res.error('Image not found')); + data.on('error', () => res.notFound('image not found')); data.on('end', () => res.end()); } diff --git a/src/pages/api/auth/invite.ts b/src/pages/api/auth/invite.ts index 4868faa..c3496db 100644 --- a/src/pages/api/auth/invite.ts +++ b/src/pages/api/auth/invite.ts @@ -60,6 +60,7 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) { } } else if (req.method === 'DELETE') { const { code } = req.query as { code: string }; + if (!code) return res.badRequest('no code'); const invite = await prisma.invite.delete({ where: { @@ -67,6 +68,8 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) { }, }); + if (!invite) return res.notFound('invite not found'); + logger.debug(`deleted invite ${JSON.stringify(invite)}`); logger.info(`${user.username} (${user.id}) deleted invite ${invite.code}`);