From 255a5992b53562f70b1aa00db36a5e5f5b32c93b Mon Sep 17 00:00:00 2001 From: Bobby Wibowo Date: Mon, 1 Jun 2020 08:51:17 +0700 Subject: [PATCH] Simplified error pages for /a/ route Send 404 error page when identifier is missing or album is not public. --- routes/album.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/routes/album.js b/routes/album.js index 6e078cb..d9dcf8a 100644 --- a/routes/album.js +++ b/routes/album.js @@ -8,10 +8,7 @@ const db = require('knex')(config.database) routes.get('/a/:identifier', async (req, res, next) => { const identifier = req.params.identifier if (identifier === undefined) - return res.status(401).json({ - success: false, - description: 'No identifier provided.' - }) + res.status(404).sendFile(path.join(paths.errorRoot, config.errorPages[404])) const album = await db.table('albums') .where({ @@ -21,13 +18,8 @@ routes.get('/a/:identifier', async (req, res, next) => { .select('id', 'name', 'identifier', 'editedAt', 'download', 'public', 'description') .first() - if (!album) + if (!album || album.public === 0) return res.status(404).sendFile(path.join(paths.errorRoot, config.errorPages[404])) - else if (album.public === 0) - return res.status(403).json({ - success: false, - description: 'This album is not available for public.' - }) const nojs = req.query.nojs !== undefined