mirror of
https://github.com/Foltik/Shimapan
synced 2024-12-02 10:40:14 -05:00
Route formatting
This commit is contained in:
parent
3c92ef4640
commit
b54054b588
@ -125,4 +125,6 @@ router.get('/whoami', authenticate(), (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
module.exports = router;
|
@ -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;
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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…
Reference in New Issue
Block a user