From b54054b5886820760073be707671aa28704b261e Mon Sep 17 00:00:00 2001 From: Jack Foltz Date: Wed, 2 Jan 2019 16:49:56 -0500 Subject: [PATCH] Route formatting --- app/routes/api/auth.js | 2 ++ app/routes/api/stats.js | 5 +++++ app/routes/api/upload.js | 4 ++++ app/routes/api/users.js | 9 +++++++++ app/routes/api/view.js | 6 ++++++ 5 files changed, 26 insertions(+) diff --git a/app/routes/api/auth.js b/app/routes/api/auth.js index 1ae9ab3..4415935 100644 --- a/app/routes/api/auth.js +++ b/app/routes/api/auth.js @@ -125,4 +125,6 @@ router.get('/whoami', authenticate(), (req, res) => { }); }); + + module.exports = router; \ No newline at end of file diff --git a/app/routes/api/stats.js b/app/routes/api/stats.js index b218d13..4e4b984 100644 --- a/app/routes/api/stats.js +++ b/app/routes/api/stats.js @@ -8,6 +8,8 @@ const View = require(ModelPath + 'View.js'); const verifyBody = require('../../util/verifyBody'); const authenticate = require('../../util/auth/authenticateRequest'); + + const uploadProps = [ {name: 'after', type: 'date', optional: true}, {name: 'before', type: 'date', optional: true}, @@ -49,6 +51,7 @@ router.get('/uploads', authenticate('stats.get'), verifyBody(uploadProps), async }); + const viewProps = [ {name: 'after', type: 'date', optional: true}, {name: 'before', type: 'date', optional: true}, @@ -85,4 +88,6 @@ router.get('/views', authenticate('stats.get'), verifyBody(viewProps), async (re res.status(200).json(views); }); + + module.exports = router; \ No newline at end of file diff --git a/app/routes/api/upload.js b/app/routes/api/upload.js index 72389b0..e9c6ccf 100644 --- a/app/routes/api/upload.js +++ b/app/routes/api/upload.js @@ -8,6 +8,8 @@ const Upload = require(ModelPath + 'Upload.js'); const uploadMultipart = require('../../util/upload/multipart'); const updateStats = require('../../util/upload/stats'); + + router.post('/', uploadMultipart, async (req, res) => { const upload = { uid: req.file.name, @@ -29,4 +31,6 @@ router.post('/', uploadMultipart, async (req, res) => { }); }); + + module.exports = router; diff --git a/app/routes/api/users.js b/app/routes/api/users.js index 687d1c6..c6d8a70 100644 --- a/app/routes/api/users.js +++ b/app/routes/api/users.js @@ -7,9 +7,12 @@ const User = require(ModelPath + 'User.js'); const verifyBody = require('../../util/verifyBody'); const authenticate = require('../../util/auth/authenticateRequest'); + + const getParams = [ {name: 'username', type: 'string', optional: true}, {name: 'displayname', type: 'string', optional: true}]; + router.get('/get', authenticate('user.get'), verifyBody(getParams), async (req, res) => { let query = {}; @@ -25,7 +28,10 @@ router.get('/get', authenticate('user.get'), verifyBody(getParams), async (req, res.status(200).json(users); }); + + const banParams = [{name: 'username', type: 'string'}]; + router.post('/ban', authenticate('user.ban'), verifyBody(banParams), async (req, res) => { const user = await User.findOne({username: req.body.username}); if (!user) @@ -40,7 +46,10 @@ router.post('/ban', authenticate('user.ban'), verifyBody(banParams), async (req, res.status(200).json({message: 'User banned.'}); }); + + const unbanParams = [{name: 'username', type: 'string'}]; + router.post('/unban', authenticate('user.unban'), verifyBody(unbanParams), async (req, res) => { const user = await User.findOne({username: req.body.username}); if (!user) diff --git a/app/routes/api/view.js b/app/routes/api/view.js index 2e6a624..5d3afec 100644 --- a/app/routes/api/view.js +++ b/app/routes/api/view.js @@ -7,6 +7,8 @@ const ModelPath = '../../models/'; const Upload = require(ModelPath + 'Upload.js'); const View = require(ModelPath + 'View.js'); + + const insertView = async (req, upload) => Promise.all([ View.create({ @@ -18,6 +20,8 @@ const insertView = async (req, upload) => Upload.updateOne({uid: upload.uid}, {$inc: {views: 1}}) ]); + + router.get('/:uid', async (req, res) => { const upload = await Upload.findOne({uid: req.params.uid}); if (!upload) @@ -43,4 +47,6 @@ router.get('/:uid', async (req, res) => { .pipe(res); }); + + module.exports = router; \ No newline at end of file