Cleanup lint

master
Joe Biellik 4 years ago
parent 9561daced2
commit 1f10854d60

@ -1,5 +1,5 @@
const koa = require('koa'); const Koa = require('koa');
const app = new koa(); const app = new Koa();
const config = require('config'); const config = require('config');
const path = require('path'); const path = require('path');
const router = require('./router'); const router = require('./router');

@ -32,11 +32,12 @@ module.exports = {
} else { } else {
ctx.body = paste.paste; ctx.body = paste.paste;
} }
} catch (ex) { } catch {
ctx.throw(404, 'Paste Not Found'); ctx.throw(404, 'Paste Not Found');
} }
}, },
/* eslint-disable-next-line complexity */
async create(ctx) { async create(ctx) {
ctx.set('Cache-Control', 'no-cache'); ctx.set('Cache-Control', 'no-cache');
@ -60,10 +61,10 @@ module.exports = {
try { try {
await fs.unlink(path); await fs.unlink(path);
} catch (ex) { } catch {
// Ignore // Ignore
} }
} catch (ex) { } catch {
ctx.throw(400, 'Bad Paste Body'); ctx.throw(400, 'Bad Paste Body');
} }
} }
@ -71,9 +72,9 @@ module.exports = {
// Expiry multiplier // Expiry multiplier
try { try {
if (ctx.request.body.expire && ctx.request.body.multiplier) { 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'); ctx.throw(400, 'Bad Paste Expiry');
} }
@ -100,7 +101,7 @@ module.exports = {
const paste = new Paste({ const paste = new Paste({
paste: ctx.request.body.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 { try {
@ -116,7 +117,7 @@ module.exports = {
// /?xxx // /?xxx
if (!ctx.request.body.highlight && !ctx.query.highlight && ctx.query) { 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 = ''; let highlight = '';

@ -3,25 +3,25 @@ version: "3"
services: services:
app: app:
image: node:latest image: node:latest
command: "npm start" command: npm start
restart: unless-stopped restart: unless-stopped
working_dir: /app working_dir: /app
depends_on: depends_on:
- db - db
environment: environment:
- NODE_ENV=production - NODE_ENV=production
- NODE_CONFIG_ENV=docker - NODE_CONFIG_ENV=docker
volumes: volumes:
- .:/app:Z - .:/app:Z
ports: ports:
- "80:80" - "80:80"
db: db:
image: mongo:latest image: mongo:latest
restart: unless-stopped restart: unless-stopped
volumes: volumes:
- ./db:/data/db:Z - ./db:/data/db:Z
expose: expose:
- 27017 - 27017
ports: ports:
- "27017:27017" - "27017:27017"

@ -12,6 +12,8 @@
}, },
"keywords": [ "keywords": [
"pastebin", "pastebin",
"text upload",
"text paste",
"paste", "paste",
"koa", "koa",
"mongodb" "mongodb"
@ -42,7 +44,7 @@
"devDependencies": { "devDependencies": {
"eclint": "^2.8.1", "eclint": "^2.8.1",
"nodemon": "^2.0.4", "nodemon": "^2.0.4",
"pug-lint": "^2.6.0" "pug-lint": "^2.6.0",
"xo": "^0.32.1" "xo": "^0.32.1"
} }
} }

@ -3,11 +3,11 @@
const https = require('https'); const https = require('https');
// Match version number to included copy // 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'); res.setEncoding('utf8');
let body = ''; let body = '';
res.on('data', data => { res.on('data', (data) => {
body += data; body += data;
}); });
@ -17,15 +17,17 @@ https.get('https://raw.githubusercontent.com/PrismJS/prism/v1.20.0/components.js
const highlights = {}; const highlights = {};
// Split markup // 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] = { components.languages[id] = {
title: components.languages.markup.aliasTitles[id] title: components.languages.markup.aliasTitles[id]
}; };
} }
for (let id in components.languages) { for (const id in components.languages) {
if (id == 'meta') continue; if (id === 'meta') continue;
if (id == 'markup') continue; if (id === 'markup') continue;
const lang = components.languages[id]; const lang = components.languages[id];
const name = lang.title || lang; const name = lang.title || lang;
@ -41,10 +43,10 @@ https.get('https://raw.githubusercontent.com/PrismJS/prism/v1.20.0/components.js
} }
highlights[id] = { highlights[id] = {
name: name name
}; };
if (contents.length) { if (contents.length > 0) {
highlights[id].alias = contents; 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.json.alias = ['javascript object notation'];
highlights.json5.alias = ['javascript object notation']; highlights.json5.alias = ['javascript object notation'];
highlights.jsonp.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.nasm.alias = ['assembly'];
highlights.protobuf.alias = ['protobuf']; highlights.protobuf.alias = ['protobuf'];
highlights.pug.alias = ['jade']; highlights.pug.alias = ['jade'];
@ -83,7 +83,7 @@ https.get('https://raw.githubusercontent.com/PrismJS/prism/v1.20.0/components.js
// Sort // Sort
const ordered = {}; const ordered = {};
Object.keys(highlights).sort().forEach(function(key) { Object.keys(highlights).sort().forEach((key) => {
ordered[key] = highlights[key]; ordered[key] = highlights[key];
}); });

@ -1,9 +1,6 @@
/* eslint-env browser */ $(() => {
/* global $ autosize */ 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'));
$(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'));
$.fn.selectpicker.Constructor.BootstrapVersion = '4'; $.fn.selectpicker.Constructor.BootstrapVersion = '4';
@ -22,25 +19,23 @@ $(function() {
}); });
$('textarea').on('keydown', function(e) { $('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(); $(this).closest('form').submit();
} }
}); });
$('input#expire').on('change', function(e) { $('input#expire').on('change', (e) => {
var value = $(e.target).val(); var value = $(e.target).val();
$('#multiplier option').text(function(_, t) { $('#multiplier option').text((_, t) => {
var plural = t.substring(t.length - 1) == 's'; var plural = t.slice(Math.max(0, t.length - 1)) === 's';
if (value > 1) { if (value > 1) {
if (!plural) { if (!plural) {
return t + 's'; return t + 's';
} }
} else { } else if (plural) {
if (plural) { return t.slice(0, -1);
return t.slice(0, -1);
}
} }
return t; return t;
@ -49,22 +44,22 @@ $(function() {
localStorage.setItem('expire-value', value); localStorage.setItem('expire-value', value);
}); });
$('#multiplier').on('change', function(e) { $('#multiplier').on('change', (e) => {
localStorage.setItem('expire-multiplier', $(e.target).val()); localStorage.setItem('expire-multiplier', $(e.target).val());
}); });
$('select#highlight').on('change', function() { $('select#highlight').on('change', function() {
if ($(this).val() == '') { if ($(this).val() === '') {
history.pushState({}, '', '/'); history.pushState({}, '', '/');
} else { } else {
location.hash = $(this).val(); location.hash = $(this).val();
} }
}); });
$(window).on('hashchange', function() { $(window).on('hashchange', () => {
var value = location.hash.slice(1); 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); $('select#highlight').selectpicker('val', value);
} else { } else {
$('select#highlight').selectpicker('val', ''); $('select#highlight').selectpicker('val', '');

Loading…
Cancel
Save