fix some linting errors
This commit is contained in:
parent
1d6e59ada3
commit
fc8318c297
7 changed files with 26 additions and 76 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ export function createFile(req, res) {
|
|||
Project.findByIdAndUpdate(req.params.project_id,
|
||||
{
|
||||
$push: {
|
||||
'files': req.body
|
||||
files: req.body
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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 =
|
||||
`<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.5/p5.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.5/addons/p5.dom.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.5/addons/p5.sound.min.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<script src="sketch.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
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);
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue