1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-12-03 10:59:13 -05:00

Remove last of wrap

This commit is contained in:
Jack Foltz 2019-01-02 14:27:20 -05:00
parent 00d14df372
commit 03b8c53885
Signed by: foltik
GPG Key ID: D1F0331758D1F29A
5 changed files with 8 additions and 17 deletions

View File

@ -5,7 +5,6 @@ const ModelPath = '../models/';
const Key = require(ModelPath + 'Key.js');
const User = require(ModelPath + 'User.js');
const wrap = require('./wrap.js');
const verifyScope = require('./verifyScope.js');
const rateLimit = require('express-rate-limit');
@ -54,7 +53,7 @@ const apiLimiter = config.get('RateLimit.enable')
// otherwise throws an error code.
// If the user is banned, also throw an error.
const requireAuth = scope => (req, res, next) => {
apiLimiter(req, res, wrap(async () => {
apiLimiter(req, res, async () => {
const status = {
authenticated: false,
@ -78,7 +77,7 @@ const requireAuth = scope => (req, res, next) => {
return res.status(403).json({message: 'Forbidden.'});
next();
}));
});
};
module.exports.checkSession = checkSession;

View File

@ -2,12 +2,11 @@ const Busboy = require('busboy');
const is = require('type-is');
const config = require('config');
const wrap = require('../wrap');
const auth = require('../auth');
const disk = require('./disk');
const identifier = require('./id');
const uploadMultipart = wrap(async (req, res, next) => {
const uploadMultipart = async (req, res, next) => {
if (!is(req, ['multipart']))
return res.status(400).json({message: 'Bad request.'});
@ -108,6 +107,6 @@ const uploadMultipart = wrap(async (req, res, next) => {
busboy.on('finished', () => done(null, {file: file}));
req.pipe(busboy);
});
};
module.exports = uploadMultipart;

View File

@ -1,14 +1,13 @@
const verify = require('./verify.js');
const wrap = require('./wrap.js');
// Verifies the entire request body is well formed
const verifyBody = expected => wrap(async (req, res, next) => {
const verifyBody = expected => async (req, res, next) => {
try {
await Promise.all(expected.map(e => verify(req.body[e.name], e)));
next();
} catch(err) {
res.status(err.code).json({message: err.message});
}
});
};
module.exports = verifyBody;

View File

@ -1,14 +1,13 @@
const verify = require('./verify.js');
const wrap = require('./wrap.js');
// Verifies the entire request query is well formed
const verifyQuery = expected => wrap(async (req, res, next) => {
const verifyQuery = expected => async (req, res, next) => {
try {
await Promise.all(expected.map(e => verify(req.query[e.name], e)));
next();
} catch(err) {
res.status(err.code).json({message: err.message});
}
});
};
module.exports = verifyQuery;

View File

@ -1,5 +0,0 @@
// Wraps an async middleware function to catch promise rejection
const wrap = fn =>
(req, res, next) => Promise.resolve(fn(req, res, next)).catch(next);
module.exports = wrap;