Fix linting

This commit is contained in:
Jonathan Cremin 2018-06-02 18:07:00 +00:00
parent 553ba9db9a
commit bb5189c9ed
35 changed files with 157 additions and 866 deletions

View file

@ -1,12 +1,14 @@
import Router from 'koa-router';
import stats from '../lib/koa-statsd';
import cors from 'kcors';
import StatsD from 'statsy';
import debugname from 'debug';
import stats from '../lib/koa-statsd';
import auth from './lib/auth';
import * as user from './routes/user';
import * as file from './routes/file';
import * as pro from './routes/pro';
import debugname from 'debug';
const debug = debugname('hostr-api');
const router = new Router();
@ -45,17 +47,15 @@ router.use(async (ctx, next) => {
code: 604,
},
};
} else {
if (!err.status) {
debug(err);
if (ctx.raven) {
ctx.raven.captureError(err);
}
throw err;
} else {
ctx.status = err.status;
ctx.body = err.message;
} else if (!err.status) {
debug(err);
if (ctx.raven) {
ctx.raven.captureError(err);
}
throw err;
} else {
ctx.status = err.status;
ctx.body = err.message;
}
}
ctx.type = 'application/json';

View file

@ -1,7 +1,9 @@
import passwords from 'passwords';
import auth from 'basic-auth';
import models from '../../models';
import debugname from 'debug';
import models from '../../models';
const debug = debugname('hostr-api:auth');
const badLoginMsg = '{"error": {"message": "Incorrect login details.", "code": 607}}';
@ -36,8 +38,10 @@ export default async (ctx, next) => {
},
});
ctx.assert(count < 25, 401,
'{"error": {"message": "Too many incorrect logins.", "code": 608}}');
ctx.assert(
count < 25, 401,
'{"error": {"message": "Too many incorrect logins.", "code": 608}}',
);
user = await models.user.findOne({
where: {
@ -56,8 +60,10 @@ export default async (ctx, next) => {
ctx.assert(user, 401, badLoginMsg);
debug('Checking user is activated');
debug(user.activated);
ctx.assert(user.activated === true, 401,
'{"error": {"message": "Account has not been activated.", "code": 603}}');
ctx.assert(
user.activated === true, 401,
'{"error": {"message": "Account has not been activated.", "code": 603}}',
);
login.successful = true;
await login.save();
@ -85,9 +91,11 @@ export default async (ctx, next) => {
plan: user.plan,
uploads_today: uploadedToday,
};
ctx.response.set('Daily-Uploads-Remaining',
user.type === 'Pro' ? 'unlimited' : 15 - uploadedToday);
ctx.response.set(
'Daily-Uploads-Remaining',
user.type === 'Pro' ? 'unlimited' : 15 - uploadedToday,
);
ctx.user = normalisedUser;
debug('Authenticated user: ', ctx.user.email);
await next();
}
};

View file

@ -47,8 +47,8 @@ export async function list(ctx) {
processed: true,
},
order: [
['createdAt', 'DESC'],
],
['createdAt', 'DESC'],
],
offset,
limit,
});

View file

@ -1,18 +1,19 @@
import path from 'path';
import views from 'co-views';
const render = views(path.join(__dirname, '/../views'), { default: 'ejs' });
import Stripe from 'stripe';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
import sendgridInit from 'sendgrid';
const sendgrid = sendgridInit(process.env.SENDGRID_KEY);
import models from '../../models';
const render = views(path.join(__dirname, '/../views'), { default: 'ejs' });
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
const sendgrid = sendgridInit(process.env.SENDGRID_KEY);
const from = process.env.EMAIL_FROM;
const fromname = process.env.EMAIL_NAME;
export async function create(ctx) {
const stripeToken = ctx.request.body.stripeToken;
const { stripeToken } = ctx.request.body;
const ip = ctx.request.headers['x-forwarded-for'] || ctx.req.connection.remoteAddress;
@ -74,7 +75,7 @@ export async function cancel(ctx) {
await stripe.customers.cancelSubscription(
transaction.data.id,
transaction.data.subscription.id,
{ at_period_end: false }
{ at_period_end: false },
);
user.plan = 'Free';

View file

@ -2,9 +2,10 @@ import uuid from 'node-uuid';
import redis from 'redis';
import co from 'co';
import passwords from 'passwords';
import debugname from 'debug';
import models from '../../models';
import debugname from 'debug';
const debug = debugname('hostr-api:user');
const redisUrl = process.env.REDIS_URL;
@ -26,31 +27,37 @@ export async function transaction(ctx) {
},
});
ctx.body = transactions.map((item) => {
return {
id: item.id,
amount: item.amount / 100,
date: item.date,
description: item.description,
type: 'direct',
};
});
ctx.body = transactions.map(item => ({
id: item.id,
amount: item.amount / 100,
date: item.date,
description: item.description,
type: 'direct',
}));
}
export async function settings(ctx) {
ctx.assert(ctx.request.body, 400,
'{"error": {"message": "Current Password required to update account.", "code": 612}}');
ctx.assert(ctx.request.body.current_password, 400,
'{"error": {"message": "Current Password required to update account.", "code": 612}}');
ctx.assert(
ctx.request.body, 400,
'{"error": {"message": "Current Password required to update account.", "code": 612}}',
);
ctx.assert(
ctx.request.body.current_password, 400,
'{"error": {"message": "Current Password required to update account.", "code": 612}}',
);
const user = await models.user.findById(ctx.user.id);
ctx.assert(await passwords.match(ctx.request.body.current_password, user.password), 400,
'{"error": {"message": "Incorrect password", "code": 606}}');
ctx.assert(
await passwords.match(ctx.request.body.current_password, user.password), 400,
'{"error": {"message": "Incorrect password", "code": 606}}',
);
if (ctx.request.body.email && ctx.request.body.email !== user.email) {
user.email = ctx.request.body.email;
}
if (ctx.request.body.new_password) {
ctx.assert(ctx.request.body.new_password.length >= 7, 400,
'{"error": {"message": "Password must be 7 or more characters long.", "code": 606}}');
ctx.assert(
ctx.request.body.new_password.length >= 7, 400,
'{"error": {"message": "Password must be 7 or more characters long.", "code": 606}}',
);
user.password = await passwords.hash(ctx.request.body.new_password);
}
await user.save();