fix linting errors that are fixable with --fix in server side code
This commit is contained in:
parent
449e103fc6
commit
af3cb60ce1
13 changed files with 91 additions and 92 deletions
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -14,7 +14,7 @@ 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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -33,6 +33,6 @@ export function getSession(req, res) {
|
|||
|
||||
export function destroySession(req, res) {
|
||||
req.logout();
|
||||
res.json({success: true});
|
||||
res.json({ success: true });
|
||||
}
|
||||
|
||||
|
|
|
@ -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,18 +69,18 @@ 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);
|
||||
});
|
||||
|
@ -88,12 +88,12 @@ export function resetPasswordInitiate(req, res) {
|
|||
(token, done) => {
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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,12 +37,12 @@ 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(){
|
||||
fileSchema.virtual('id').get(function () {
|
||||
return this._id.toHexString();
|
||||
});
|
||||
|
||||
|
@ -53,11 +53,11 @@ fileSchema.set('toJSON', {
|
|||
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(){
|
||||
projectSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
});
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ userSchema.pre('save', function checkPassword(next) { // eslint-disable-line con
|
|||
});
|
||||
});
|
||||
|
||||
userSchema.virtual('id').get(function(){
|
||||
userSchema.virtual('id').get(function () {
|
||||
return this._id.toHexString();
|
||||
});
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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('.')) {
|
||||
|
@ -73,7 +73,7 @@ export function resolveScripts(sketchDoc, files, projectId) {
|
|||
script.innerHTML = resolveLinksInString(script.innerHTML, files, projectId);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function resolveStyles(sketchDoc, files, projectId) {
|
||||
const inlineCSSInHTML = sketchDoc.getElementsByTagName('style');
|
||||
|
@ -93,10 +93,10 @@ export function resolveStyles(sketchDoc, files, projectId) {
|
|||
} else {
|
||||
const style = sketchDoc.createElement('style');
|
||||
style.innerHTML = `\n${resolvedFile.content}`;
|
||||
sketchDoc.getElementsByTagName("head")[0].appendChild(style);
|
||||
sketchDoc.getElementsByTagName('head')[0].appendChild(style);
|
||||
css.parentNode.removeChild(css);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue