diff --git a/package.json b/package.json index 0ba596ba..5ee7c1bd 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "postinstall": "gulp build-prism", "start": "node build/dev-server.js", "build": "node build/build.js", - "lint": "eslint --ext .js,.vue src", + "lint": "eslint --ext .js,.vue src server", "preversion": "npm run lint", "postversion": "git push origin master --tags && npm publish", "patch": "npm version patch -m \"Tag v%s\"", diff --git a/server/index.js b/server/index.js index 2b31e4bb..1c867908 100644 --- a/server/index.js +++ b/server/index.js @@ -1,31 +1,35 @@ -var compression = require('compression'); -var serveStatic = require('serve-static'); -var path = require('path'); +const compression = require('compression'); +const serveStatic = require('serve-static'); +const path = require('path'); +const github = require('./github'); -module.exports = function (app, serveV4) { +module.exports = (app, serveV4) => { // Use gzip compression if (process.env.NODE_ENV === 'production') { - app.all('*', function(req, res, next) { + app.all('*', (req, res, next) => { // Force HTTPS on stackedit.io if (req.headers.host === 'stackedit.io' && !req.secure && req.headers['x-forwarded-proto'] !== 'https') { - return res.redirect('https://stackedit.io' + req.url); + res.redirect(`https://stackedit.io${req.url}`); + return; } // Enable CORS for fonts if (/\.(eot|ttf|woff|svg)$/.test(req.url)) { res.header('Access-Control-Allow-Origin', '*'); - } + }; next(); }); app.use(compression()); } - app.get('/oauth2/githubToken', require('./github').githubToken); + app.get('/oauth2/githubToken', github.githubToken); if (serveV4) { + /* eslint-disable global-require, import/no-unresolved */ app.post('/pdfExport', require('../stackedit_v4/app/pdf').export); app.post('/sshPublish', require('../stackedit_v4/app/ssh').publish); app.post('/picasaImportImg', require('../stackedit_v4/app/picasa').importImg); app.get('/downloadImport', require('../stackedit_v4/app/download').importPublic); + /* eslint-enable global-require, import/no-unresolved */ } // Serve callback.html in /app @@ -37,23 +41,15 @@ module.exports = function (app, serveV4) { if (process.env.NODE_ENV === 'production') { if (serveV4) { // Serve landing.html in / - app.get('/', function(req, res) { - res.sendFile(require.resolve('../stackedit_v4/views/landing.html')); - }); + app.get('/', (req, res) => res.sendFile(require.resolve('../stackedit_v4/views/landing.html'))); // Serve editor.html in /viewer - app.get('/editor', function(req, res) { - res.sendFile(require.resolve('../stackedit_v4/views/editor.html')); - }); + app.get('/editor', (req, res) => res.sendFile(require.resolve('../stackedit_v4/views/editor.html'))); // Serve viewer.html in /viewer - app.get('/viewer', function(req, res) { - res.sendFile(require.resolve('../stackedit_v4/views/viewer.html')); - }); + app.get('/viewer', (req, res) => res.sendFile(require.resolve('../stackedit_v4/views/viewer.html'))); } // Serve index.html in /app - app.get('/app', function(req, res) { - res.sendFile(path.join(__dirname, '../dist/index.html')); - }); + app.get('/app', (req, res) => res.sendFile(path.join(__dirname, '../dist/index.html'))); app.use(serveStatic(path.join(__dirname, '../dist'))); @@ -61,9 +57,7 @@ module.exports = function (app, serveV4) { app.use(serveStatic(path.dirname(require.resolve('../stackedit_v4/public/cache.manifest')))); // Error 404 - app.use(function(req, res) { - res.status(404).sendFile(require.resolve('../stackedit_v4/views/error_404.html')); - }); + app.use((req, res) => res.status(404).sendFile(require.resolve('../stackedit_v4/views/error_404.html'))); } } }; diff --git a/server/pdf.js b/server/pdf.js deleted file mode 100644 index 80bd61e4..00000000 --- a/server/pdf.js +++ /dev/null @@ -1,145 +0,0 @@ -/* global window,MathJax */ -var spawn = require('child_process').spawn; -var fs = require('fs'); -var path = require('path'); -var os = require('os'); -var request = require('request'); - -function waitForJavaScript() { - if(window.MathJax) { - // Amazon EC2: fix TeX font detection - MathJax.Hub.Register.StartupHook("HTML-CSS Jax Startup",function () { - var HTMLCSS = MathJax.OutputJax["HTML-CSS"]; - HTMLCSS.Font.checkWebFont = function (check,font,callback) { - if (check.time(callback)) { - return; - } - if (check.total === 0) { - HTMLCSS.Font.testFont(font); - setTimeout(check,200); - } else { - callback(check.STATUS.OK); - } - }; - }); - MathJax.Hub.Queue(function () { - window.status = 'done'; - }); - } - else { - setTimeout(function() { - window.status = 'done'; - }, 2000); - } -} - -var authorizedPageSizes = [ - 'A3', - 'A4', - 'Legal', - 'Letter' -]; - -exports.export = function(req, res, next) { - function onError(err) { - next(err); - } - function onUnknownError() { - res.statusCode = 400; - res.end('Unknown error'); - } - function onUnauthorizedError() { - res.statusCode = 401; - res.end('Unauthorized'); - } - function onTimeout() { - res.statusCode = 408; - res.end('Request timeout'); - } - request({ - uri: 'https://monetizejs.com/api/payments', - qs: { - access_token: req.query.token - }, - json: true - }, function (err, paymentsRes, payments) { - var authorized = payments && payments.app == 'ESTHdCYOi18iLhhO' && ( - (payments.chargeOption && payments.chargeOption.alias == 'once') || - (payments.subscriptionOption && payments.subscriptionOption.alias == 'yearly')); - if(err || paymentsRes.statusCode != 200 || !authorized) { - return onUnauthorizedError(); - } - var options, params = []; - try { - options = JSON.parse(req.query.options); - } - catch(e) { - options = {}; - } - - // Margins - var marginTop = parseInt(options.marginTop); - params.push('-T', isNaN(marginTop) ? 25 : marginTop); - var marginRight = parseInt(options.marginRight); - params.push('-R', isNaN(marginRight) ? 25 : marginRight); - var marginBottom = parseInt(options.marginBottom); - params.push('-B', isNaN(marginBottom) ? 25 : marginBottom); - var marginLeft = parseInt(options.marginLeft); - params.push('-L', isNaN(marginLeft) ? 25 : marginLeft); - - // Header - options.headerCenter && params.push('--header-center', options.headerCenter); - options.headerLeft && params.push('--header-left', options.headerLeft); - options.headerRight && params.push('--header-right', options.headerRight); - options.headerFontName && params.push('--header-font-name', options.headerFontName); - options.headerFontSize && params.push('--header-font-size', options.headerFontSize); - - // Footer - options.footerCenter && params.push('--footer-center', options.footerCenter); - options.footerLeft && params.push('--footer-left', options.footerLeft); - options.footerRight && params.push('--footer-right', options.footerRight); - options.footerFontName && params.push('--footer-font-name', options.footerFontName); - options.footerFontSize && params.push('--footer-font-size', options.footerFontSize); - - // Page size - params.push('--page-size', authorizedPageSizes.indexOf(options.pageSize) === -1 ? 'A4' : options.pageSize); - - // Use a temp file as wkhtmltopdf can't access /dev/stdout on Amazon EC2 for some reason - var filePath = path.join(os.tmpDir(), Date.now() + '.pdf'); - var binPath = process.env.WKHTMLTOPDF_PATH || 'wkhtmltopdf'; - params.push('--run-script', waitForJavaScript.toString() + 'waitForJavaScript()'); - params.push('--window-status', 'done'); - var wkhtmltopdf = spawn(binPath, params.concat('-', filePath), { - stdio: [ - 'pipe', - 'ignore', - 'ignore' - ] - }); - var timeoutId = setTimeout(function() { - timeoutId = undefined; - wkhtmltopdf.kill(); - }, 30000); - wkhtmltopdf.on('error', onError); - wkhtmltopdf.stdin.on('error', onError); - wkhtmltopdf.on('close', function(code) { - if(!timeoutId) { - return onTimeout(); - } - clearTimeout(timeoutId); - if(code) { - return onUnknownError(); - } - var readStream = fs.createReadStream(filePath); - readStream.on('open', function() { - readStream.pipe(res); - }); - readStream.on('close', function() { - fs.unlink(filePath, function() { - }); - }); - readStream.on('error', onUnknownError); - }); - req.pipe(wkhtmltopdf.stdin); - }); -}; diff --git a/src/components/Modal.vue b/src/components/Modal.vue index 1ed60e0d..4c558ebf 100644 --- a/src/components/Modal.vue +++ b/src/components/Modal.vue @@ -160,7 +160,7 @@ export default { position: absolute; width: 100%; height: 100%; - background-color: rgba(180, 180, 180, 0.75); + background-color: rgba(128, 128, 128, 0.5); overflow: auto; } diff --git a/src/components/NavigationBar.vue b/src/components/NavigationBar.vue index 3b0f3c66..416504e8 100644 --- a/src/components/NavigationBar.vue +++ b/src/components/NavigationBar.vue @@ -34,6 +34,13 @@