Moved upload mw into api app

- Moved upload mw from shared to api as it is not shared (except within the API)
- This file is only used in one part of the app, this updates the code structure to reflect this
- This is one of many similar changes needed to make it easier to refactor to the existing setup
This commit is contained in:
Hannah Wolfe 2020-04-22 06:58:56 +01:00
parent 05cf4f495d
commit 36b42505ea
5 changed files with 12 additions and 21 deletions

View File

@ -5,9 +5,6 @@ const mw = require('./middleware');
const shared = require('../../../shared');
// Handling uploads & imports
const upload = shared.middlewares.upload;
module.exports = function apiRoutes() {
const router = express.Router();
@ -55,7 +52,7 @@ module.exports = function apiRoutes() {
router.get('/settings/routes/yaml', mw.authAdminApi, http(apiCanary.settings.download));
router.post('/settings/routes/yaml',
mw.authAdminApi,
upload.single('routes'),
apiMw.upload.single('routes'),
shared.middlewares.validation.upload({type: 'routes'}),
http(apiCanary.settings.upload)
);
@ -92,7 +89,7 @@ module.exports = function apiRoutes() {
router.post('/members/csv',
shared.middlewares.labs.members,
mw.authAdminApi,
upload.single('membersfile'),
apiMw.upload.single('membersfile'),
shared.middlewares.validation.upload({type: 'members'}),
http(apiCanary.members.importCSV)
);
@ -127,7 +124,7 @@ module.exports = function apiRoutes() {
router.post('/themes/upload',
mw.authAdminApi,
upload.single('file'),
apiMw.upload.single('file'),
shared.middlewares.validation.upload({type: 'themes'}),
http(apiCanary.themes.upload)
);
@ -151,7 +148,7 @@ module.exports = function apiRoutes() {
router.get('/db', mw.authAdminApi, http(apiCanary.db.exportContent));
router.post('/db',
mw.authAdminApi,
upload.single('importfile'),
apiMw.upload.single('importfile'),
shared.middlewares.validation.upload({type: 'db'}),
http(apiCanary.db.importContent)
);
@ -197,7 +194,7 @@ module.exports = function apiRoutes() {
// ## Images
router.post('/images/upload',
mw.authAdminApi,
upload.single('file'),
apiMw.upload.single('file'),
shared.middlewares.validation.upload({type: 'images'}),
shared.middlewares.image.normalize,
http(apiCanary.images.upload)
@ -213,7 +210,7 @@ module.exports = function apiRoutes() {
router.get('/redirects/json', mw.authAdminApi, http(apiCanary.redirects.download));
router.post('/redirects/json',
mw.authAdminApi,
upload.single('redirects'),
apiMw.upload.single('redirects'),
shared.middlewares.validation.upload({type: 'redirects'}),
http(apiCanary.redirects.upload)
);

View File

@ -1,5 +1,6 @@
module.exports = {
cors: require('./cors'),
updateUserLastSeen: require('./update-user-last-seen'),
upload: require('./upload'),
versionMatch: require('./version-match')
};

View File

@ -5,9 +5,6 @@ const apiMw = require('../../middleware');
const shared = require('../../../shared');
// Handling uploads & imports
const upload = shared.middlewares.upload;
module.exports = function apiRoutes() {
const router = express.Router();
@ -55,7 +52,7 @@ module.exports = function apiRoutes() {
router.get('/settings/routes/yaml', mw.authAdminApi, http(apiv2.settings.download));
router.post('/settings/routes/yaml',
mw.authAdminApi,
upload.single('routes'),
apiMw.upload.single('routes'),
shared.middlewares.validation.upload({type: 'routes'}),
http(apiv2.settings.upload)
);
@ -100,7 +97,7 @@ module.exports = function apiRoutes() {
router.post('/themes/upload',
mw.authAdminApi,
upload.single('file'),
apiMw.upload.single('file'),
shared.middlewares.validation.upload({type: 'themes'}),
http(apiv2.themes.upload)
);
@ -124,7 +121,7 @@ module.exports = function apiRoutes() {
router.get('/db', mw.authAdminApi, http(apiv2.db.exportContent));
router.post('/db',
mw.authAdminApi,
upload.single('importfile'),
apiMw.upload.single('importfile'),
shared.middlewares.validation.upload({type: 'db'}),
http(apiv2.db.importContent)
);
@ -167,7 +164,7 @@ module.exports = function apiRoutes() {
// ## Images
router.post('/images/upload',
mw.authAdminApi,
upload.single('file'),
apiMw.upload.single('file'),
shared.middlewares.validation.upload({type: 'images'}),
shared.middlewares.image.normalize,
http(apiv2.images.upload)
@ -183,7 +180,7 @@ module.exports = function apiRoutes() {
router.get('/redirects/json', mw.authAdminApi, http(apiv2.redirects.download));
router.post('/redirects/json',
mw.authAdminApi,
upload.single('redirects'),
apiMw.upload.single('redirects'),
shared.middlewares.validation.upload({type: 'redirects'}),
http(apiv2.redirects.upload)
);

View File

@ -15,10 +15,6 @@ module.exports = {
return require('./brute');
},
get upload() {
return require('./upload');
},
get cacheControl() {
return require('./cache-control');
},