diff --git a/server/controllers/aws.controller.js b/server/controllers/aws.controller.js index 2b23e21f..2faf8938 100644 --- a/server/controllers/aws.controller.js +++ b/server/controllers/aws.controller.js @@ -118,11 +118,9 @@ export function listObjectsInS3ForUser(req, res) { } }; let assets = []; - const list = client.listObjects(params) + client.listObjects(params) .on('data', (data) => { - assets = assets.concat(data["Contents"].map((object) => { - return { key: object["Key"], size: object["Size"] }; - })); + assets = assets.concat(data.Contents.map(object => ({ key: object.Key, size: object.Size }))); }) .on('end', () => { const projectAssets = []; @@ -131,7 +129,7 @@ export function listObjectsInS3ForUser(req, res) { project.files.forEach((file) => { if (!file.url) return; - const foundAsset = assets.find((asset) => file.url.includes(asset.key)); + const foundAsset = assets.find(asset => file.url.includes(asset.key)); if (!foundAsset) return; projectAssets.push({ name: file.name, @@ -143,7 +141,7 @@ export function listObjectsInS3ForUser(req, res) { }); }); }); - res.json({assets: projectAssets}); + res.json({ assets: projectAssets }); }); }); }); diff --git a/server/controllers/project.controller.js b/server/controllers/project.controller.js index 0b7d84b4..978207a0 100644 --- a/server/controllers/project.controller.js +++ b/server/controllers/project.controller.js @@ -139,33 +139,35 @@ export function getProjectsForUserId(userId) { export function getProjectAsset(req, res) { Project.findById(req.params.project_id) .populate('user', 'username') - .exec((err, project) => { + .exec((err, project) => { // eslint-disable-line if (err) { return res.status(404).send({ message: 'Project with that id does not exist' }); } - var assetURL = null; - var seekPath = req.params[0]; // req.params.asset_path; - var seekPathSplit = seekPath.split('/'); - var seekFilename = seekPathSplit[seekPathSplit.length-1]; + let assetURL = null; + const seekPath = req.params[0]; // req.params.asset_path; + const seekPathSplit = seekPath.split('/'); + const seekFilename = seekPathSplit[seekPathSplit.length - 1]; project.files.forEach((file) => { - if(file.name === seekFilename) { + if (file.name === seekFilename) { assetURL = file.url; } }); - if(!assetURL) { + if (!assetURL) { return res.status(404).send({ message: 'Asset does not exist' }); - } else { - request({ method: 'GET', url: assetURL, encoding: null }, (err, response, body) => { - res.send(body); - }); } + request({ method: 'GET', url: assetURL, encoding: null }, (innerErr, response, body) => { + if (innerErr) { + return res.status(404).send({ message: 'Asset does not exist' }); + } + return res.send(body); + }); }); } export function getProjectsForUserName(username) { - + } export function getProjects(req, res) { @@ -199,7 +201,6 @@ export function getProjectsForUser(req, res) { } function bundleExternalLibs(project, zip, callback) { - const rootFile = project.files.find(file => file.name === 'root'); const indexHtml = project.files.find(file => file.name === 'index.html'); let numScriptsResolved = 0; let numScriptTags = 0; diff --git a/server/routes/server.routes.js b/server/routes/server.routes.js index 87cbf3b4..28c3128c 100644 --- a/server/routes/server.routes.js +++ b/server/routes/server.routes.js @@ -17,7 +17,7 @@ router.route('/signup').get((req, res) => { if (req.user) { return res.redirect('/'); } - res.send(renderIndex()); + return res.send(renderIndex()); }); router.route('/projects/:project_id').get((req, res) => { @@ -29,7 +29,7 @@ router.route('/:username/sketches/:project_id').get((req, res) => { }); router.route('/:username/sketches/:project_id/*').get((req, res) => { - getProjectAsset(req,res); + getProjectAsset(req, res); }); // router.route('/full/:project_id').get((req, res) => { @@ -40,7 +40,7 @@ router.route('/login').get((req, res) => { if (req.user) { return res.redirect('/'); } - res.send(renderIndex()); + return res.send(renderIndex()); }); router.route('/reset-password').get((req, res) => {