diff --git a/app.js b/app.js index e8d5b5f..e4f0ca8 100644 --- a/app.js +++ b/app.js @@ -1,5 +1,5 @@ -const koa = require('koa'); -const app = new koa(); +const Koa = require('koa'); +const app = new Koa(); const config = require('config'); const path = require('path'); const router = require('./router'); diff --git a/controllers/pastes.js b/controllers/pastes.js index 9290929..f8f92cb 100644 --- a/controllers/pastes.js +++ b/controllers/pastes.js @@ -32,11 +32,12 @@ module.exports = { } else { ctx.body = paste.paste; } - } catch (ex) { + } catch { ctx.throw(404, 'Paste Not Found'); } }, + /* eslint-disable-next-line complexity */ async create(ctx) { ctx.set('Cache-Control', 'no-cache'); @@ -60,10 +61,10 @@ module.exports = { try { await fs.unlink(path); - } catch (ex) { + } catch { // Ignore } - } catch (ex) { + } catch { ctx.throw(400, 'Bad Paste Body'); } } @@ -71,9 +72,9 @@ module.exports = { // Expiry multiplier try { if (ctx.request.body.expire && ctx.request.body.multiplier) { - ctx.request.body.expire = ctx.request.body.expire * ctx.request.body.multiplier; + ctx.request.body.expire *= ctx.request.body.multiplier; } - } catch (ex) { + } catch { ctx.throw(400, 'Bad Paste Expiry'); } @@ -100,7 +101,7 @@ module.exports = { const paste = new Paste({ paste: ctx.request.body.paste, - expiresAt: new Date(Date.now() + ctx.request.body.expire * 1000) + expiresAt: new Date(Date.now() + (ctx.request.body.expire * 1000)) }); try { @@ -116,7 +117,7 @@ module.exports = { // /?xxx if (!ctx.request.body.highlight && !ctx.query.highlight && ctx.query) { - ctx.request.body.highlight = Object.keys(ctx.query).filter(k => k != 'redirect' && k != 'expire')[0]; + ctx.request.body.highlight = Object.keys(ctx.query).filter((k) => k !== 'redirect' && k !== 'expire')[0]; } let highlight = ''; diff --git a/docker-compose.yml b/docker-compose.yml index 67b7ad9..4178292 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,25 +3,25 @@ version: "3" services: app: image: node:latest - command: "npm start" + command: npm start restart: unless-stopped working_dir: /app depends_on: - - db + - db environment: - NODE_ENV=production - NODE_CONFIG_ENV=docker volumes: - - .:/app:Z + - .:/app:Z ports: - - "80:80" + - "80:80" db: image: mongo:latest restart: unless-stopped volumes: - - ./db:/data/db:Z + - ./db:/data/db:Z expose: - - 27017 + - 27017 ports: - - "27017:27017" + - "27017:27017" diff --git a/package.json b/package.json index 1a43d15..d5ca0a3 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,8 @@ }, "keywords": [ "pastebin", + "text upload", + "text paste", "paste", "koa", "mongodb" @@ -42,7 +44,7 @@ "devDependencies": { "eclint": "^2.8.1", "nodemon": "^2.0.4", - "pug-lint": "^2.6.0" + "pug-lint": "^2.6.0", "xo": "^0.32.1" } } diff --git a/prism-langs.js b/prism-langs.js index ff60e5a..df2e9a6 100644 --- a/prism-langs.js +++ b/prism-langs.js @@ -3,11 +3,11 @@ const https = require('https'); // Match version number to included copy -https.get('https://raw.githubusercontent.com/PrismJS/prism/v1.20.0/components.json', res => { +https.get('https://raw.githubusercontent.com/PrismJS/prism/v1.20.0/components.json', (res) => { res.setEncoding('utf8'); let body = ''; - res.on('data', data => { + res.on('data', (data) => { body += data; }); @@ -17,15 +17,17 @@ https.get('https://raw.githubusercontent.com/PrismJS/prism/v1.20.0/components.js const highlights = {}; // Split markup - for (let id in components.languages.markup.aliasTitles) { + for (const id in components.languages.markup.aliasTitles) { + if (!Object.prototype.hasOwnProperty.call(components.languages.markup.aliasTitles, id)) continue; + components.languages[id] = { title: components.languages.markup.aliasTitles[id] }; } - for (let id in components.languages) { - if (id == 'meta') continue; - if (id == 'markup') continue; + for (const id in components.languages) { + if (id === 'meta') continue; + if (id === 'markup') continue; const lang = components.languages[id]; const name = lang.title || lang; @@ -41,10 +43,10 @@ https.get('https://raw.githubusercontent.com/PrismJS/prism/v1.20.0/components.js } highlights[id] = { - name: name + name }; - if (contents.length) { + if (contents.length > 0) { highlights[id].alias = contents; } } @@ -68,8 +70,6 @@ https.get('https://raw.githubusercontent.com/PrismJS/prism/v1.20.0/components.js highlights.json.alias = ['javascript object notation']; highlights.json5.alias = ['javascript object notation']; highlights.jsonp.alias = ['javascript object notation']; - // highlights.jsstacktrace.name = 'JavaScript stack trace'; - // highlights.jsstacktrace.alias.push('javascript']; highlights.nasm.alias = ['assembly']; highlights.protobuf.alias = ['protobuf']; highlights.pug.alias = ['jade']; @@ -83,7 +83,7 @@ https.get('https://raw.githubusercontent.com/PrismJS/prism/v1.20.0/components.js // Sort const ordered = {}; - Object.keys(highlights).sort().forEach(function(key) { + Object.keys(highlights).sort().forEach((key) => { ordered[key] = highlights[key]; }); diff --git a/public/main.js b/public/main.js index 2a3f9de..3e9a8cc 100644 --- a/public/main.js +++ b/public/main.js @@ -1,9 +1,6 @@ -/* eslint-env browser */ -/* global $ autosize */ - -$(function() { - if (localStorage.getItem('expire-value') != null) $('input#expire').val(localStorage.getItem('expire-value')); - if (localStorage.getItem('expire-multiplier') != null) $('#multiplier').val(localStorage.getItem('expire-multiplier')); +$(() => { + if (localStorage.getItem('expire-value') !== null) $('input#expire').val(localStorage.getItem('expire-value')); + if (localStorage.getItem('expire-multiplier') !== null) $('#multiplier').val(localStorage.getItem('expire-multiplier')); $.fn.selectpicker.Constructor.BootstrapVersion = '4'; @@ -22,25 +19,23 @@ $(function() { }); $('textarea').on('keydown', function(e) { - if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey && $(this).val()) { + if ((e.keyCode === 10 || e.keyCode === 13) && e.ctrlKey && $(this).val()) { $(this).closest('form').submit(); } }); - $('input#expire').on('change', function(e) { + $('input#expire').on('change', (e) => { var value = $(e.target).val(); - $('#multiplier option').text(function(_, t) { - var plural = t.substring(t.length - 1) == 's'; + $('#multiplier option').text((_, t) => { + var plural = t.slice(Math.max(0, t.length - 1)) === 's'; if (value > 1) { if (!plural) { return t + 's'; } - } else { - if (plural) { - return t.slice(0, -1); - } + } else if (plural) { + return t.slice(0, -1); } return t; @@ -49,22 +44,22 @@ $(function() { localStorage.setItem('expire-value', value); }); - $('#multiplier').on('change', function(e) { + $('#multiplier').on('change', (e) => { localStorage.setItem('expire-multiplier', $(e.target).val()); }); $('select#highlight').on('change', function() { - if ($(this).val() == '') { + if ($(this).val() === '') { history.pushState({}, '', '/'); } else { location.hash = $(this).val(); } }); - $(window).on('hashchange', function() { + $(window).on('hashchange', () => { var value = location.hash.slice(1); - if (value && $('select#highlight option[value=' + value + ']').length) { + if (value && $('select#highlight option[value=' + value + ']').length > 0) { $('select#highlight').selectpicker('val', value); } else { $('select#highlight').selectpicker('val', '');