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,
|
filename = uuid.v4() + fileExtension,
|
||||||
acl = 'public-read',
|
acl = 'public-read',
|
||||||
p = policy({
|
p = policy({
|
||||||
acl: acl,
|
acl,
|
||||||
secret: process.env.AWS_SECRET_KEY,
|
secret: process.env.AWS_SECRET_KEY,
|
||||||
length: 5000000, // in bytes?
|
length: 5000000, // in bytes?
|
||||||
bucket: process.env.S3_BUCKET,
|
bucket: process.env.S3_BUCKET,
|
||||||
|
@ -25,4 +25,4 @@ export function signS3(req, res) {
|
||||||
'signature': p.signature
|
'signature': p.signature
|
||||||
};
|
};
|
||||||
return res.json(result);
|
return res.json(result);
|
||||||
};
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import jsdom, { serializeDocument } from 'jsdom';
|
||||||
export function serveProject(req, res) {
|
export function serveProject(req, res) {
|
||||||
Project.findById(req.params.project_id)
|
Project.findById(req.params.project_id)
|
||||||
.exec((err, project) => {
|
.exec((err, project) => {
|
||||||
//TODO this does not parse html
|
// TODO this does not parse html
|
||||||
const files = project.files;
|
const files = project.files;
|
||||||
let htmlFile = files.find(file => file.name.match(/\.html$/i)).content;
|
let htmlFile = files.find(file => file.name.match(/\.html$/i)).content;
|
||||||
const filesToInject = files.filter(file => file.name.match(/\.(js|css)$/i));
|
const filesToInject = files.filter(file => file.name.match(/\.(js|css)$/i));
|
||||||
|
|
|
@ -47,7 +47,7 @@ function deleteChild(files, parentId, id) {
|
||||||
files = files.map((file) => {
|
files = files.map((file) => {
|
||||||
if (file.id === parentId) {
|
if (file.id === parentId) {
|
||||||
file.children = file.children.filter(child => child !== id);
|
file.children = file.children.filter(child => child !== id);
|
||||||
return file
|
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.files.id(req.query.parentId).children = childrenArray.filter(id => id !== req.params.file_id);
|
||||||
project.save(innerErr => {
|
project.save(innerErr => {
|
||||||
res.json(project.files);
|
res.json(project.files);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFileContent(req, res) {
|
export function getFileContent(req, res) {
|
||||||
Project.findById(req.params.project_id, (err, project) => {
|
Project.findById(req.params.project_id, (err, project) => {
|
||||||
if (err) {
|
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 filePath = req.params[0];
|
||||||
const resolvedFile = resolvePathToFile(filePath, project.files);
|
const resolvedFile = resolvePathToFile(filePath, project.files);
|
||||||
if (!resolvedFile) {
|
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);
|
res.send(resolvedFile.content);
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,7 +14,7 @@ export function createProject(req, res) {
|
||||||
Project.create(projectValues, (err, newProject) => {
|
Project.create(projectValues, (err, newProject) => {
|
||||||
if (err) { return res.json({ success: false }); }
|
if (err) { return res.json({ success: false }); }
|
||||||
Project.populate(newProject,
|
Project.populate(newProject,
|
||||||
{path: 'user', select: 'username'},
|
{ path: 'user', select: 'username' },
|
||||||
(innerErr, newProjectWithUser) => {
|
(innerErr, newProjectWithUser) => {
|
||||||
if (innerErr) { return res.json({ success: false }); }
|
if (innerErr) { return res.json({ success: false }); }
|
||||||
return res.json(newProjectWithUser);
|
return res.json(newProjectWithUser);
|
||||||
|
@ -64,7 +64,7 @@ export function getProject(req, res) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteProject(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) {
|
if (err) {
|
||||||
return res.status(404).send({ message: 'Project with that id does not exist' });
|
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) {
|
export function getProjects(req, res) {
|
||||||
if (req.user) {
|
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')
|
.sort('-createdAt')
|
||||||
.select('name files id createdAt updatedAt')
|
.select('name files id createdAt updatedAt')
|
||||||
.exec((err, projects) => {
|
.exec((err, projects) => {
|
||||||
|
@ -84,13 +84,12 @@ export function getProjects(req, res) {
|
||||||
// could just move this to client side
|
// could just move this to client side
|
||||||
return res.json([]);
|
return res.json([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getProjectsForUser(req, res) {
|
export function getProjectsForUser(req, res) {
|
||||||
if (req.params.username) {
|
if (req.params.username) {
|
||||||
User.findOne({ username: req.params.username }, (err, user) => {
|
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')
|
.sort('-createdAt')
|
||||||
.select('name files id createdAt updatedAt')
|
.select('name files id createdAt updatedAt')
|
||||||
.exec((err, projects) => {
|
.exec((err, projects) => {
|
||||||
|
@ -111,8 +110,8 @@ function buildZip(project, req, res) {
|
||||||
const projectName = project.name;
|
const projectName = project.name;
|
||||||
let numCompletedFiles = 0;
|
let numCompletedFiles = 0;
|
||||||
|
|
||||||
zip.on('error', function(err) {
|
zip.on('error', function (err) {
|
||||||
res.status(500).send({error: err.message});
|
res.status(500).send({ error: err.message });
|
||||||
});
|
});
|
||||||
|
|
||||||
res.attachment(`${project.name}.zip`);
|
res.attachment(`${project.name}.zip`);
|
||||||
|
@ -150,7 +149,7 @@ function buildZip(project, req, res) {
|
||||||
|
|
||||||
export function downloadProjectAsZip(req, res) {
|
export function downloadProjectAsZip(req, res) {
|
||||||
Project.findById(req.params.project_id, (err, project) => {
|
Project.findById(req.params.project_id, (err, project) => {
|
||||||
//save project to some path
|
// save project to some path
|
||||||
buildZip(project, req, res);
|
buildZip(project, req, res);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,6 @@ export function getSession(req, res) {
|
||||||
|
|
||||||
export function destroySession(req, res) {
|
export function destroySession(req, res) {
|
||||||
req.logout();
|
req.logout();
|
||||||
res.json({success: true});
|
res.json({ success: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,10 +58,10 @@ export function duplicateUserCheck(req, res) {
|
||||||
export function updatePreferences(req, res) {
|
export function updatePreferences(req, res) {
|
||||||
User.findById(req.user.id, (err, user) => {
|
User.findById(req.user.id, (err, user) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return res.status(500).json({error: err});
|
return res.status(500).json({ error: err });
|
||||||
}
|
}
|
||||||
if (!user){
|
if (!user) {
|
||||||
return res.status(404).json({error: 'Document not found'});
|
return res.status(404).json({ error: 'Document not found' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const preferences = Object.assign({}, user.preferences, req.body.preferences);
|
const preferences = Object.assign({}, user.preferences, req.body.preferences);
|
||||||
|
@ -69,18 +69,18 @@ export function updatePreferences(req, res) {
|
||||||
|
|
||||||
user.save((err) => {
|
user.save((err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return res.status(500).json({error: err});
|
return res.status(500).json({ error: err });
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.json(user.preferences);
|
return res.json(user.preferences);
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resetPasswordInitiate(req, res) {
|
export function resetPasswordInitiate(req, res) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
(done) => {
|
(done) => {
|
||||||
crypto.randomBytes(20, function(err, buf) {
|
crypto.randomBytes(20, function (err, buf) {
|
||||||
var token = buf.toString('hex');
|
var token = buf.toString('hex');
|
||||||
done(err, token);
|
done(err, token);
|
||||||
});
|
});
|
||||||
|
@ -88,12 +88,12 @@ export function resetPasswordInitiate(req, res) {
|
||||||
(token, done) => {
|
(token, done) => {
|
||||||
User.findOne({ email: req.body.email }, (err, user) => {
|
User.findOne({ email: req.body.email }, (err, user) => {
|
||||||
if (!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.resetPasswordToken = token;
|
||||||
user.resetPasswordExpires = Date.now() + 3600000; // 1 hour
|
user.resetPasswordExpires = Date.now() + 3600000; // 1 hour
|
||||||
|
|
||||||
user.save(function(err) {
|
user.save(function (err) {
|
||||||
done(err, token, user);
|
done(err, token, user);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -124,34 +124,34 @@ export function resetPasswordInitiate(req, res) {
|
||||||
], (err) => {
|
], (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return res.json({success: false});
|
return res.json({ success: false });
|
||||||
}
|
}
|
||||||
//send email here
|
// send email here
|
||||||
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.' });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validateResetPasswordToken(req, res) {
|
export function validateResetPasswordToken(req, res) {
|
||||||
User.findOne({ resetPasswordToken: req.params.token, resetPasswordExpires: { $gt: Date.now() } }, (err, user) => {
|
User.findOne({ resetPasswordToken: req.params.token, resetPasswordExpires: { $gt: Date.now() } }, (err, user) => {
|
||||||
if (!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 });
|
res.json({ success: true });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updatePassword(req, res) {
|
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) {
|
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.password = req.body.password;
|
||||||
user.resetPasswordToken = undefined;
|
user.resetPasswordToken = undefined;
|
||||||
user.resetPasswordExpires = undefined;
|
user.resetPasswordExpires = undefined;
|
||||||
|
|
||||||
user.save(function(err) {
|
user.save(function (err) {
|
||||||
req.logIn(user, function(err) {
|
req.logIn(user, function (err) {
|
||||||
return res.json({
|
return res.json({
|
||||||
email: req.user.email,
|
email: req.user.email,
|
||||||
username: req.user.username,
|
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() {
|
function draw() {
|
||||||
background(220);
|
background(220);
|
||||||
}`
|
}`;
|
||||||
|
|
||||||
const defaultHTML =
|
const defaultHTML =
|
||||||
`<!DOCTYPE html>
|
`<!DOCTYPE html>
|
||||||
|
@ -24,7 +24,7 @@ const defaultHTML =
|
||||||
<script src="sketch.js"></script>
|
<script src="sketch.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
`
|
`;
|
||||||
const defaultCSS =
|
const defaultCSS =
|
||||||
`html, body {
|
`html, body {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
@ -37,12 +37,12 @@ const fileSchema = new Schema({
|
||||||
name: { type: String, default: 'sketch.js' },
|
name: { type: String, default: 'sketch.js' },
|
||||||
content: { type: String, default: '' },
|
content: { type: String, default: '' },
|
||||||
url: { type: String },
|
url: { type: String },
|
||||||
children: { type: [ String ], default: [] },
|
children: { type: [String], default: [] },
|
||||||
fileType: { type: String, default: 'file' },
|
fileType: { type: String, default: 'file' },
|
||||||
isSelectedFile: { type: Boolean }
|
isSelectedFile: { type: Boolean }
|
||||||
}, { timestamps: true, _id: true });
|
}, { timestamps: true, _id: true });
|
||||||
|
|
||||||
fileSchema.virtual('id').get(function(){
|
fileSchema.virtual('id').get(function () {
|
||||||
return this._id.toHexString();
|
return this._id.toHexString();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -53,11 +53,11 @@ fileSchema.set('toJSON', {
|
||||||
const projectSchema = new Schema({
|
const projectSchema = new Schema({
|
||||||
name: { type: String, default: "Hello p5.js, it's the server" },
|
name: { type: String, default: "Hello p5.js, it's the server" },
|
||||||
user: { type: Schema.Types.ObjectId, ref: 'User' },
|
user: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||||
files: { type: [ fileSchema ] },
|
files: { type: [fileSchema] },
|
||||||
_id: { type: String, default: shortid.generate }
|
_id: { type: String, default: shortid.generate }
|
||||||
}, { timestamps: true });
|
}, { timestamps: true });
|
||||||
|
|
||||||
projectSchema.virtual('id').get(function(){
|
projectSchema.virtual('id').get(function () {
|
||||||
return this._id;
|
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();
|
return this._id.toHexString();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { renderIndex } from '../views/index'
|
import { renderIndex } from '../views/index';
|
||||||
|
|
||||||
// this is intended to be a temporary file
|
// this is intended to be a temporary file
|
||||||
// until i figure out isomorphic rendering
|
// until i figure out isomorphic rendering
|
||||||
|
|
|
@ -13,13 +13,13 @@ function resolveLinksInString(content, files, projectId) {
|
||||||
const fileStringRegex = /^('|")(?!(http:\/\/|https:\/\/)).*('|")$/i;
|
const fileStringRegex = /^('|")(?!(http:\/\/|https:\/\/)).*('|")$/i;
|
||||||
fileStrings = fileStrings || [];
|
fileStrings = fileStrings || [];
|
||||||
fileStrings.forEach(fileString => {
|
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)) {
|
if (fileString.match(fileStringRegex)) {
|
||||||
const filePath = fileString.substr(1, fileString.length - 2);
|
const filePath = fileString.substr(1, fileString.length - 2);
|
||||||
const resolvedFile = resolvePathToFile(filePath, files);
|
const resolvedFile = resolvePathToFile(filePath, files);
|
||||||
if (resolvedFile) {
|
if (resolvedFile) {
|
||||||
if (resolvedFile.url) {
|
if (resolvedFile.url) {
|
||||||
newContent = newContent.replace(filePath,resolvedFile.url);
|
newContent = newContent.replace(filePath, resolvedFile.url);
|
||||||
} else if (resolvedFile.name.match(/(.+\.json$|.+\.txt$|.+\.csv$)/i)) {
|
} else if (resolvedFile.name.match(/(.+\.json$|.+\.txt$|.+\.csv$)/i)) {
|
||||||
let resolvedFilePath = filePath;
|
let resolvedFilePath = filePath;
|
||||||
if (resolvedFilePath.startsWith('.')) {
|
if (resolvedFilePath.startsWith('.')) {
|
||||||
|
@ -73,7 +73,7 @@ export function resolveScripts(sketchDoc, files, projectId) {
|
||||||
script.innerHTML = resolveLinksInString(script.innerHTML, files, projectId);
|
script.innerHTML = resolveLinksInString(script.innerHTML, files, projectId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveStyles(sketchDoc, files, projectId) {
|
export function resolveStyles(sketchDoc, files, projectId) {
|
||||||
const inlineCSSInHTML = sketchDoc.getElementsByTagName('style');
|
const inlineCSSInHTML = sketchDoc.getElementsByTagName('style');
|
||||||
|
@ -93,10 +93,10 @@ export function resolveStyles(sketchDoc, files, projectId) {
|
||||||
} else {
|
} else {
|
||||||
const style = sketchDoc.createElement('style');
|
const style = sketchDoc.createElement('style');
|
||||||
style.innerHTML = `\n${resolvedFile.content}`;
|
style.innerHTML = `\n${resolvedFile.content}`;
|
||||||
sketchDoc.getElementsByTagName("head")[0].appendChild(style);
|
sketchDoc.getElementsByTagName('head')[0].appendChild(style);
|
||||||
css.parentNode.removeChild(css);
|
css.parentNode.removeChild(css);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue