mirror of
https://github.com/Foltik/Shimapan
synced 2024-12-03 10:59:13 -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;
|
module.exports = router;
|
@ -8,6 +8,8 @@ const View = require(ModelPath + 'View.js');
|
|||||||
const verifyBody = require('../../util/verifyBody');
|
const verifyBody = require('../../util/verifyBody');
|
||||||
const authenticate = require('../../util/auth/authenticateRequest');
|
const authenticate = require('../../util/auth/authenticateRequest');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const uploadProps = [
|
const uploadProps = [
|
||||||
{name: 'after', type: 'date', optional: true},
|
{name: 'after', type: 'date', optional: true},
|
||||||
{name: 'before', 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 = [
|
const viewProps = [
|
||||||
{name: 'after', type: 'date', optional: true},
|
{name: 'after', type: 'date', optional: true},
|
||||||
{name: 'before', 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);
|
res.status(200).json(views);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
@ -8,6 +8,8 @@ const Upload = require(ModelPath + 'Upload.js');
|
|||||||
const uploadMultipart = require('../../util/upload/multipart');
|
const uploadMultipart = require('../../util/upload/multipart');
|
||||||
const updateStats = require('../../util/upload/stats');
|
const updateStats = require('../../util/upload/stats');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
router.post('/', uploadMultipart, async (req, res) => {
|
router.post('/', uploadMultipart, async (req, res) => {
|
||||||
const upload = {
|
const upload = {
|
||||||
uid: req.file.name,
|
uid: req.file.name,
|
||||||
@ -29,4 +31,6 @@ router.post('/', uploadMultipart, async (req, res) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
@ -7,9 +7,12 @@ const User = require(ModelPath + 'User.js');
|
|||||||
const verifyBody = require('../../util/verifyBody');
|
const verifyBody = require('../../util/verifyBody');
|
||||||
const authenticate = require('../../util/auth/authenticateRequest');
|
const authenticate = require('../../util/auth/authenticateRequest');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const getParams = [
|
const getParams = [
|
||||||
{name: 'username', type: 'string', optional: true},
|
{name: 'username', type: 'string', optional: true},
|
||||||
{name: 'displayname', type: 'string', optional: true}];
|
{name: 'displayname', type: 'string', optional: true}];
|
||||||
|
|
||||||
router.get('/get', authenticate('user.get'), verifyBody(getParams), async (req, res) => {
|
router.get('/get', authenticate('user.get'), verifyBody(getParams), async (req, res) => {
|
||||||
let query = {};
|
let query = {};
|
||||||
|
|
||||||
@ -25,7 +28,10 @@ router.get('/get', authenticate('user.get'), verifyBody(getParams), async (req,
|
|||||||
res.status(200).json(users);
|
res.status(200).json(users);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const banParams = [{name: 'username', type: 'string'}];
|
const banParams = [{name: 'username', type: 'string'}];
|
||||||
|
|
||||||
router.post('/ban', authenticate('user.ban'), verifyBody(banParams), async (req, res) => {
|
router.post('/ban', authenticate('user.ban'), verifyBody(banParams), async (req, res) => {
|
||||||
const user = await User.findOne({username: req.body.username});
|
const user = await User.findOne({username: req.body.username});
|
||||||
if (!user)
|
if (!user)
|
||||||
@ -40,7 +46,10 @@ router.post('/ban', authenticate('user.ban'), verifyBody(banParams), async (req,
|
|||||||
res.status(200).json({message: 'User banned.'});
|
res.status(200).json({message: 'User banned.'});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const unbanParams = [{name: 'username', type: 'string'}];
|
const unbanParams = [{name: 'username', type: 'string'}];
|
||||||
|
|
||||||
router.post('/unban', authenticate('user.unban'), verifyBody(unbanParams), async (req, res) => {
|
router.post('/unban', authenticate('user.unban'), verifyBody(unbanParams), async (req, res) => {
|
||||||
const user = await User.findOne({username: req.body.username});
|
const user = await User.findOne({username: req.body.username});
|
||||||
if (!user)
|
if (!user)
|
||||||
|
@ -7,6 +7,8 @@ const ModelPath = '../../models/';
|
|||||||
const Upload = require(ModelPath + 'Upload.js');
|
const Upload = require(ModelPath + 'Upload.js');
|
||||||
const View = require(ModelPath + 'View.js');
|
const View = require(ModelPath + 'View.js');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const insertView = async (req, upload) =>
|
const insertView = async (req, upload) =>
|
||||||
Promise.all([
|
Promise.all([
|
||||||
View.create({
|
View.create({
|
||||||
@ -18,6 +20,8 @@ const insertView = async (req, upload) =>
|
|||||||
Upload.updateOne({uid: upload.uid}, {$inc: {views: 1}})
|
Upload.updateOne({uid: upload.uid}, {$inc: {views: 1}})
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
router.get('/:uid', async (req, res) => {
|
router.get('/:uid', async (req, res) => {
|
||||||
const upload = await Upload.findOne({uid: req.params.uid});
|
const upload = await Upload.findOne({uid: req.params.uid});
|
||||||
if (!upload)
|
if (!upload)
|
||||||
@ -43,4 +47,6 @@ router.get('/:uid', async (req, res) => {
|
|||||||
.pipe(res);
|
.pipe(res);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
Loading…
Reference in New Issue
Block a user