Browse Source

Route formatting

production
Jack Foltz 5 years ago
parent
commit
b54054b588
Signed by: foltik <jack@foltz.io> GPG Key ID: D1F0331758D1F29A
5 changed files with 26 additions and 0 deletions
  1. +2
    -0
      app/routes/api/auth.js
  2. +5
    -0
      app/routes/api/stats.js
  3. +4
    -0
      app/routes/api/upload.js
  4. +9
    -0
      app/routes/api/users.js
  5. +6
    -0
      app/routes/api/view.js

+ 2
- 0
app/routes/api/auth.js View File

@@ -125,4 +125,6 @@ router.get('/whoami', authenticate(), (req, res) => {
});
});



module.exports = router;

+ 5
- 0
app/routes/api/stats.js View File

@@ -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;

+ 4
- 0
app/routes/api/upload.js View File

@@ -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;

+ 9
- 0
app/routes/api/users.js View File

@@ -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)


+ 6
- 0
app/routes/api/view.js View File

@@ -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;

Loading…
Cancel
Save