From fc8318c2970c502d5bd5d20b27b4e43a1d2566f3 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Wed, 11 Jan 2017 15:50:36 -0500 Subject: [PATCH] fix some linting errors --- server/controllers/aws.controller.js | 34 ++++++++++---------- server/controllers/embed.controller.js | 9 ++---- server/controllers/file.controller.js | 2 +- server/controllers/user.controller.js | 8 ++--- server/models/project.js | 44 -------------------------- server/routes/server.routes.js | 1 - server/utils/previewGeneration.js | 4 +-- 7 files changed, 26 insertions(+), 76 deletions(-) diff --git a/server/controllers/aws.controller.js b/server/controllers/aws.controller.js index 2cce85d1..9ced0bf2 100644 --- a/server/controllers/aws.controller.js +++ b/server/controllers/aws.controller.js @@ -7,22 +7,22 @@ function getExtension(filename) { } export function signS3(req, res) { - const fileExtension = getExtension(req.body.name), - filename = uuid.v4() + fileExtension, - acl = 'public-read', - p = policy({ - acl, - secret: process.env.AWS_SECRET_KEY, - length: 5000000, // in bytes? - bucket: process.env.S3_BUCKET, - key: filename, - expires: new Date(Date.now() + 60000), - }), - result = { - 'AWSAccessKeyId': process.env.AWS_ACCESS_KEY, - 'key': filename, - 'policy': p.policy, - 'signature': p.signature - }; + const fileExtension = getExtension(req.body.name); + const filename = uuid.v4() + fileExtension; + const acl = 'public-read'; + const p = policy({ + acl, + secret: process.env.AWS_SECRET_KEY, + length: 5000000, // in bytes? + bucket: process.env.S3_BUCKET, + key: filename, + expires: new Date(Date.now() + 60000), + }); + const result = { + AWSAccessKeyId: process.env.AWS_ACCESS_KEY, + key: filename, + policy: p.policy, + signature: p.signature + }; return res.json(result); } diff --git a/server/controllers/embed.controller.js b/server/controllers/embed.controller.js index 5d73b71f..8e8db4ad 100644 --- a/server/controllers/embed.controller.js +++ b/server/controllers/embed.controller.js @@ -1,7 +1,4 @@ import Project from '../models/project'; -import escapeStringRegexp from 'escape-string-regexp'; -const startTag = '@fs-'; -import { resolvePathToFile } from '../utils/filePath'; import { injectMediaUrls, resolvePathsForElementsWithAttribute, @@ -14,15 +11,15 @@ export function serveProject(req, res) { .exec((err, project) => { // TODO this does not parse html const files = project.files; - let htmlFile = files.find(file => file.name.match(/\.html$/i)).content; + const htmlFile = files.find(file => file.name.match(/\.html$/i)).content; const filesToInject = files.filter(file => file.name.match(/\.(js|css)$/i)); injectMediaUrls(filesToInject, files, req.params.project_id); - jsdom.env(htmlFile, (err, window) => { + jsdom.env(htmlFile, (innerErr, window) => { const sketchDoc = window.document; const base = sketchDoc.createElement('base'); - const fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl; + const fullUrl = `${req.protocol}://${req.get('host')}${req.originalUrl}`; base.href = `${fullUrl}/`; sketchDoc.head.appendChild(base); diff --git a/server/controllers/file.controller.js b/server/controllers/file.controller.js index ebe2643e..dab443c8 100644 --- a/server/controllers/file.controller.js +++ b/server/controllers/file.controller.js @@ -8,7 +8,7 @@ export function createFile(req, res) { Project.findByIdAndUpdate(req.params.project_id, { $push: { - 'files': req.body + files: req.body } }, { diff --git a/server/controllers/user.controller.js b/server/controllers/user.controller.js index be4940b0..648fd870 100644 --- a/server/controllers/user.controller.js +++ b/server/controllers/user.controller.js @@ -80,8 +80,8 @@ export function updatePreferences(req, res) { export function resetPasswordInitiate(req, res) { async.waterfall([ (done) => { - crypto.randomBytes(20, function (err, buf) { - var token = buf.toString('hex'); + crypto.randomBytes(20, (err, buf) => { + const token = buf.toString('hex'); done(err, token); }); }, @@ -93,7 +93,7 @@ export function resetPasswordInitiate(req, res) { user.resetPasswordToken = token; user.resetPasswordExpires = Date.now() + 3600000; // 1 hour - user.save(function (err) { + user.save((err) => { done(err, token, user); }); }); @@ -117,7 +117,7 @@ export function resetPasswordInitiate(req, res) { \n\nIf you did not request this, please ignore this email and your password will remain unchanged. \n\nThanks for using the p5.js Web Editor!\n` }; - transporter.sendMail(message, (error, info) => { + transporter.sendMail(message, (error) => { done(error); }); } diff --git a/server/models/project.js b/server/models/project.js index 54d0917d..0ec09122 100644 --- a/server/models/project.js +++ b/server/models/project.js @@ -1,37 +1,7 @@ import mongoose from 'mongoose'; const Schema = mongoose.Schema; -const ObjectIdSchema = Schema.ObjectId; -const ObjectId = mongoose.Types.ObjectId; import shortid from 'shortid'; -const defaultSketch = `function setup() { - createCanvas(400, 400); -} -function draw() { - background(220); -}`; - -const defaultHTML = -` - - - - - - - - - - - -`; -const defaultCSS = -`html, body { - margin: 0; - padding: 0; -} -`; - const fileSchema = new Schema({ name: { type: String, default: 'sketch.js' }, content: { type: String, default: '' }, @@ -64,18 +34,4 @@ projectSchema.set('toJSON', { virtuals: true }); -// projectSchema.pre('save', function createSelectedFile(next) { -// const project = this; -// if (project.isNew && project.files.length === 0) { -// let a = new ObjectId(); -// let b = new ObjectId(); -// let c = new ObjectId(); -// project.files = [{ name: 'sketch.js', content: defaultSketch, _id: a, isSelectedFile: true }, -// { name: 'index.html', content: defaultHTML, _id: b }, -// { name: 'style.css', content: defaultCSS, _id: c }, -// { name: 'root', _id: new ObjectId(), children: [a, b, c] }]; -// } -// return next(); -// }); - export default mongoose.model('Project', projectSchema); diff --git a/server/routes/server.routes.js b/server/routes/server.routes.js index dc373c59..0bc73f5a 100644 --- a/server/routes/server.routes.js +++ b/server/routes/server.routes.js @@ -1,6 +1,5 @@ import { Router } from 'express'; const router = new Router(); -import path from 'path'; import { renderIndex } from '../views/index'; import { get404Sketch } from '../views/404Page'; import { userExists } from '../controllers/user.controller.js'; diff --git a/server/utils/previewGeneration.js b/server/utils/previewGeneration.js index 18c23635..f11ce185 100644 --- a/server/utils/previewGeneration.js +++ b/server/utils/previewGeneration.js @@ -1,9 +1,7 @@ import { resolvePathToFile } from '../utils/filePath'; -const MEDIA_FILE_REGEX = /^('|")(?!(http:\/\/|https:\/\/)).*\.(png|jpg|jpeg|gif|bmp|mp3|wav|aiff|ogg|json|txt|csv|svg|obj|mp4|ogg|webm|mov|otf|ttf)('|")$/i; const MEDIA_FILE_REGEX_NO_QUOTES = /^(?!(http:\/\/|https:\/\/)).*\.(png|jpg|jpeg|gif|bmp|mp3|wav|aiff|ogg|json|txt|csv|svg|obj|mp4|ogg|webm|mov|otf|ttf)$/i; const STRING_REGEX = /(['"])((\\\1|.)*?)\1/gm; -const TEXT_FILE_REGEX = /(.+\.json$|.+\.txt$|.+\.csv$)/i; const EXTERNAL_LINK_REGEX = /^(http:\/\/|https:\/\/)/; const NOT_EXTERNAL_LINK_REGEX = /^(?!(http:\/\/|https:\/\/))/; @@ -37,7 +35,7 @@ function resolveLinksInString(content, files, projectId) { } export function injectMediaUrls(filesToInject, allFiles, projectId) { - filesToInject.forEach((file, index) => { + filesToInject.forEach(file => { file.content = resolveLinksInString(file.content, allFiles, projectId); }); }