fix: urls handle empty strings

This commit is contained in:
diced 2023-01-06 15:06:34 -08:00
parent a481c0ee5e
commit dbac6e8918
No known key found for this signature in database
GPG key ID: 370BD1BA142842D1

View file

@ -20,6 +20,8 @@ async function handler(req: NextApiReq, res: NextApiRes) {
if (!req.body) return res.badRequest('no body');
if (!req.body.url) return res.badRequest('no url');
if (req.body.vanity && req.body.vanity.trim().length === 0) return res.badRequest('vanity is empty');
const maxUrlViews = req.headers['max-views'] ? Number(req.headers['max-views']) : null;
if (isNaN(maxUrlViews)) return res.badRequest('invalid max views (invalid number)');
if (maxUrlViews < 0) return res.badRequest('invalid max views (max views < 0)');