fix linting errors that are fixable with --fix in server side code

This commit is contained in:
Cassie Tarakajian 2016-11-17 11:15:35 -05:00
parent 449e103fc6
commit af3cb60ce1
13 changed files with 91 additions and 92 deletions

View file

@ -11,7 +11,7 @@ export function signS3(req, res) {
filename = uuid.v4() + fileExtension,
acl = 'public-read',
p = policy({
acl: acl,
acl,
secret: process.env.AWS_SECRET_KEY,
length: 5000000, // in bytes?
bucket: process.env.S3_BUCKET,
@ -25,4 +25,4 @@ export function signS3(req, res) {
'signature': p.signature
};
return res.json(result);
};
}

View file

@ -12,7 +12,7 @@ import jsdom, { serializeDocument } from 'jsdom';
export function serveProject(req, res) {
Project.findById(req.params.project_id)
.exec((err, project) => {
//TODO this does not parse html
// TODO this does not parse html
const files = project.files;
let htmlFile = files.find(file => file.name.match(/\.html$/i)).content;
const filesToInject = files.filter(file => file.name.match(/\.(js|css)$/i));
@ -28,4 +28,4 @@ export function serveProject(req, res) {
res.send(serializeDocument(sketchDoc));
});
});
}
}

View file

@ -47,7 +47,7 @@ function deleteChild(files, parentId, id) {
files = files.map((file) => {
if (file.id === parentId) {
file.children = file.children.filter(child => child !== id);
return file
return file;
}
return file;
});
@ -63,19 +63,19 @@ export function deleteFile(req, res) {
// project.files.id(req.query.parentId).children = childrenArray.filter(id => id !== req.params.file_id);
project.save(innerErr => {
res.json(project.files);
})
});
});
}
export function getFileContent(req, res) {
Project.findById(req.params.project_id, (err, project) => {
if (err) {
return res.status(404).send({success: false, message: 'Project with that id does not exist.'});
return res.status(404).send({ success: false, message: 'Project with that id does not exist.' });
}
const filePath = req.params[0];
const resolvedFile = resolvePathToFile(filePath, project.files);
if (!resolvedFile) {
return res.status(404).send({success: false, message: 'File with that name and path does not exist.'});
return res.status(404).send({ success: false, message: 'File with that name and path does not exist.' });
}
res.send(resolvedFile.content);
});

View file

@ -14,11 +14,11 @@ export function createProject(req, res) {
Project.create(projectValues, (err, newProject) => {
if (err) { return res.json({ success: false }); }
Project.populate(newProject,
{path: 'user', select: 'username'},
{ path: 'user', select: 'username' },
(innerErr, newProjectWithUser) => {
if (innerErr) { return res.json({ success: false }); }
return res.json(newProjectWithUser);
});
});
});
}
@ -64,7 +64,7 @@ export function getProject(req, res) {
}
export function deleteProject(req, res) {
Project.remove({_id: req.params.project_id}, (err) => {
Project.remove({ _id: req.params.project_id }, (err) => {
if (err) {
return res.status(404).send({ message: 'Project with that id does not exist' });
}
@ -74,7 +74,7 @@ export function deleteProject(req, res) {
export function getProjects(req, res) {
if (req.user) {
Project.find({user: req.user._id}) // eslint-disable-line no-underscore-dangle
Project.find({ user: req.user._id }) // eslint-disable-line no-underscore-dangle
.sort('-createdAt')
.select('name files id createdAt updatedAt')
.exec((err, projects) => {
@ -84,13 +84,12 @@ export function getProjects(req, res) {
// could just move this to client side
return res.json([]);
}
}
export function getProjectsForUser(req, res) {
if (req.params.username) {
User.findOne({ username: req.params.username }, (err, user) => {
Project.find({user: user._id}) // eslint-disable-line no-underscore-dangle
Project.find({ user: user._id }) // eslint-disable-line no-underscore-dangle
.sort('-createdAt')
.select('name files id createdAt updatedAt')
.exec((err, projects) => {
@ -111,8 +110,8 @@ function buildZip(project, req, res) {
const projectName = project.name;
let numCompletedFiles = 0;
zip.on('error', function(err) {
res.status(500).send({error: err.message});
zip.on('error', function (err) {
res.status(500).send({ error: err.message });
});
res.attachment(`${project.name}.zip`);
@ -150,7 +149,7 @@ function buildZip(project, req, res) {
export function downloadProjectAsZip(req, res) {
Project.findById(req.params.project_id, (err, project) => {
//save project to some path
// save project to some path
buildZip(project, req, res);
});
}

View file

@ -33,6 +33,6 @@ export function getSession(req, res) {
export function destroySession(req, res) {
req.logout();
res.json({success: true});
res.json({ success: true });
}

View file

@ -58,10 +58,10 @@ export function duplicateUserCheck(req, res) {
export function updatePreferences(req, res) {
User.findById(req.user.id, (err, user) => {
if (err) {
return res.status(500).json({error: err});
return res.status(500).json({ error: err });
}
if (!user){
return res.status(404).json({error: 'Document not found'});
if (!user) {
return res.status(404).json({ error: 'Document not found' });
}
const preferences = Object.assign({}, user.preferences, req.body.preferences);
@ -69,31 +69,31 @@ export function updatePreferences(req, res) {
user.save((err) => {
if (err) {
return res.status(500).json({error: err});
return res.status(500).json({ error: err });
}
return res.json(user.preferences);
});
})
});
}
export function resetPasswordInitiate(req, res) {
async.waterfall([
(done) => {
crypto.randomBytes(20, function(err, buf) {
crypto.randomBytes(20, function (err, buf) {
var token = buf.toString('hex');
done(err, token);
});
},
(token, done) => {
User.findOne({ email: req.body.email }, (err, user) => {
User.findOne({ email: req.body.email }, (err, user) => {
if (!user) {
return res.json({success: true, message: 'If the email is registered with the editor, an email has been sent.'});
return res.json({ success: true, message: 'If the email is registered with the editor, an email has been sent.' });
}
user.resetPasswordToken = token;
user.resetPasswordExpires = Date.now() + 3600000; // 1 hour
user.save(function(err) {
user.save(function (err) {
done(err, token, user);
});
});
@ -124,34 +124,34 @@ export function resetPasswordInitiate(req, res) {
], (err) => {
if (err) {
console.log(err);
return res.json({success: false});
return res.json({ success: false });
}
//send email here
return res.json({success: true, message: 'If the email is registered with the editor, an email has been sent.'});
// send email here
return res.json({ success: true, message: 'If the email is registered with the editor, an email has been sent.' });
});
}
export function validateResetPasswordToken(req, res) {
User.findOne({ resetPasswordToken: req.params.token, resetPasswordExpires: { $gt: Date.now() } }, (err, user) => {
if (!user) {
return res.status(401).json({success: false, message: 'Password reset token is invalid or has expired.'});
return res.status(401).json({ success: false, message: 'Password reset token is invalid or has expired.' });
}
res.json({ success: true });
});
}
export function updatePassword(req, res) {
User.findOne({ resetPasswordToken: req.params.token, resetPasswordExpires: { $gt: Date.now() } }, function(err, user) {
User.findOne({ resetPasswordToken: req.params.token, resetPasswordExpires: { $gt: Date.now() } }, function (err, user) {
if (!user) {
return res.status(401).json({success: false, message: 'Password reset token is invalid or has expired.'});
return res.status(401).json({ success: false, message: 'Password reset token is invalid or has expired.' });
}
user.password = req.body.password;
user.resetPasswordToken = undefined;
user.resetPasswordExpires = undefined;
user.save(function(err) {
req.logIn(user, function(err) {
user.save(function (err) {
req.logIn(user, function (err) {
return res.json({
email: req.user.email,
username: req.user.username,
@ -162,5 +162,5 @@ export function updatePassword(req, res) {
});
});
//eventually send email that the password has been reset
// eventually send email that the password has been reset
}

View file

@ -9,7 +9,7 @@ const defaultSketch = `function setup() {
}
function draw() {
background(220);
}`
}`;
const defaultHTML =
`<!DOCTYPE html>
@ -24,7 +24,7 @@ const defaultHTML =
<script src="sketch.js"></script>
</body>
</html>
`
`;
const defaultCSS =
`html, body {
overflow: hidden;
@ -37,32 +37,32 @@ const fileSchema = new Schema({
name: { type: String, default: 'sketch.js' },
content: { type: String, default: '' },
url: { type: String },
children: { type: [ String ], default: [] },
children: { type: [String], default: [] },
fileType: { type: String, default: 'file' },
isSelectedFile: { type: Boolean }
}, { timestamps: true, _id: true });
fileSchema.virtual('id').get(function(){
return this._id.toHexString();
fileSchema.virtual('id').get(function () {
return this._id.toHexString();
});
fileSchema.set('toJSON', {
virtuals: true
virtuals: true
});
const projectSchema = new Schema({
name: { type: String, default: "Hello p5.js, it's the server" },
user: { type: Schema.Types.ObjectId, ref: 'User' },
files: { type: [ fileSchema ] },
files: { type: [fileSchema] },
_id: { type: String, default: shortid.generate }
}, { timestamps: true });
projectSchema.virtual('id').get(function(){
return this._id;
projectSchema.virtual('id').get(function () {
return this._id;
});
projectSchema.set('toJSON', {
virtuals: true
virtuals: true
});
// projectSchema.pre('save', function createSelectedFile(next) {

View file

@ -39,12 +39,12 @@ userSchema.pre('save', function checkPassword(next) { // eslint-disable-line con
});
});
userSchema.virtual('id').get(function(){
return this._id.toHexString();
userSchema.virtual('id').get(function () {
return this._id.toHexString();
});
userSchema.set('toJSON', {
virtuals: true
virtuals: true
});

View file

@ -7,4 +7,4 @@ router.route('/projects/:project_id/files').post(FileController.createFile);
router.route('/projects/:project_id/files/:file_id').delete(FileController.deleteFile);
router.route('/projects/:project_id/*?').get(FileController.getFileContent);
export default router;
export default router;

View file

@ -1,7 +1,7 @@
import { Router } from 'express';
const router = new Router();
import path from 'path';
import { renderIndex } from '../views/index'
import { renderIndex } from '../views/index';
// this is intended to be a temporary file
// until i figure out isomorphic rendering

View file

@ -134,4 +134,4 @@ User.find({})
console.log('user saved');
});
});
});
});

View file

@ -1,3 +1,3 @@
require('babel-register');
require('babel-polyfill');
require('./db_reformat');
require('./db_reformat');

View file

@ -13,13 +13,13 @@ function resolveLinksInString(content, files, projectId) {
const fileStringRegex = /^('|")(?!(http:\/\/|https:\/\/)).*('|")$/i;
fileStrings = fileStrings || [];
fileStrings.forEach(fileString => {
//if string does not begin with http or https
// if string does not begin with http or https
if (fileString.match(fileStringRegex)) {
const filePath = fileString.substr(1, fileString.length - 2);
const resolvedFile = resolvePathToFile(filePath, files);
if (resolvedFile) {
if (resolvedFile.url) {
newContent = newContent.replace(filePath,resolvedFile.url);
newContent = newContent.replace(filePath, resolvedFile.url);
} else if (resolvedFile.name.match(/(.+\.json$|.+\.txt$|.+\.csv$)/i)) {
let resolvedFilePath = filePath;
if (resolvedFilePath.startsWith('.')) {
@ -56,47 +56,47 @@ export function resolvePathsForElementsWithAttribute(attr, sketchDoc, files) {
}
export function resolveScripts(sketchDoc, files, projectId) {
const scriptsInHTML = sketchDoc.getElementsByTagName('script');
const scriptsInHTMLArray = Array.prototype.slice.call(scriptsInHTML);
scriptsInHTMLArray.forEach(script => {
if (script.getAttribute('src') && script.getAttribute('src').match(NOT_EXTERNAL_LINK_REGEX) !== null) {
const resolvedFile = resolvePathToFile(script.getAttribute('src'), files);
if (resolvedFile) {
if (resolvedFile.url) {
script.setAttribute('src', resolvedFile.url);
} else {
script.removeAttribute('src');
script.innerHTML = resolvedFile.content;
}
const scriptsInHTML = sketchDoc.getElementsByTagName('script');
const scriptsInHTMLArray = Array.prototype.slice.call(scriptsInHTML);
scriptsInHTMLArray.forEach(script => {
if (script.getAttribute('src') && script.getAttribute('src').match(NOT_EXTERNAL_LINK_REGEX) !== null) {
const resolvedFile = resolvePathToFile(script.getAttribute('src'), files);
if (resolvedFile) {
if (resolvedFile.url) {
script.setAttribute('src', resolvedFile.url);
} else {
script.removeAttribute('src');
script.innerHTML = resolvedFile.content;
}
} else if (!(script.getAttribute('src') && script.getAttribute('src').match(EXTERNAL_LINK_REGEX) !== null)) {
script.innerHTML = resolveLinksInString(script.innerHTML, files, projectId);
}
});
}
} else if (!(script.getAttribute('src') && script.getAttribute('src').match(EXTERNAL_LINK_REGEX) !== null)) {
script.innerHTML = resolveLinksInString(script.innerHTML, files, projectId);
}
});
}
export function resolveStyles(sketchDoc, files, projectId) {
const inlineCSSInHTML = sketchDoc.getElementsByTagName('style');
const inlineCSSInHTMLArray = Array.prototype.slice.call(inlineCSSInHTML);
inlineCSSInHTMLArray.forEach(style => {
style.innerHTML = resolveLinksInString(style.innerHTML, files, projectId);
});
const inlineCSSInHTML = sketchDoc.getElementsByTagName('style');
const inlineCSSInHTMLArray = Array.prototype.slice.call(inlineCSSInHTML);
inlineCSSInHTMLArray.forEach(style => {
style.innerHTML = resolveLinksInString(style.innerHTML, files, projectId);
});
const cssLinksInHTML = sketchDoc.querySelectorAll('link[rel="stylesheet"]');
const cssLinksInHTMLArray = Array.prototype.slice.call(cssLinksInHTML);
cssLinksInHTMLArray.forEach(css => {
if (css.getAttribute('href') && css.getAttribute('href').match(NOT_EXTERNAL_LINK_REGEX) !== null) {
const resolvedFile = resolvePathToFile(css.getAttribute('href'), files);
if (resolvedFile) {
if (resolvedFile.url) {
css.setAttribute('href', resolvedFile.url);
} else {
const style = sketchDoc.createElement('style');
style.innerHTML = `\n${resolvedFile.content}`;
sketchDoc.getElementsByTagName("head")[0].appendChild(style);
css.parentNode.removeChild(css);
}
const cssLinksInHTML = sketchDoc.querySelectorAll('link[rel="stylesheet"]');
const cssLinksInHTMLArray = Array.prototype.slice.call(cssLinksInHTML);
cssLinksInHTMLArray.forEach(css => {
if (css.getAttribute('href') && css.getAttribute('href').match(NOT_EXTERNAL_LINK_REGEX) !== null) {
const resolvedFile = resolvePathToFile(css.getAttribute('href'), files);
if (resolvedFile) {
if (resolvedFile.url) {
css.setAttribute('href', resolvedFile.url);
} else {
const style = sketchDoc.createElement('style');
style.innerHTML = `\n${resolvedFile.content}`;
sketchDoc.getElementsByTagName('head')[0].appendChild(style);
css.parentNode.removeChild(css);
}
}
});
}
}
});
}