1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-11-14 00:46:38 -05:00

Route formatting

This commit is contained in:
Jack Foltz 2019-01-02 16:49:56 -05:00
parent 3c92ef4640
commit b54054b588
Signed by: foltik
GPG Key ID: D1F0331758D1F29A
5 changed files with 26 additions and 0 deletions

View File

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

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;

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;

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)

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;