Apply Javascript styleguide
This commit is contained in:
parent
752ce964c8
commit
6e0f351093
30 changed files with 364 additions and 375 deletions
|
@ -1,39 +1,35 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import mime from 'mime-types';
|
||||
import hostrFileStream from '../../lib/hostr-file-stream';
|
||||
import { formatFile } from '../../lib/format';
|
||||
|
||||
import debugname from 'debug';
|
||||
const debug = debugname('hostr-web:file');
|
||||
|
||||
const storePath = process.env.STORE_PATH || path.join(process.env.HOME, '.hostr', 'uploads');
|
||||
|
||||
const userAgentCheck = function(userAgent) {
|
||||
if (!userAgent){
|
||||
function userAgentCheck(userAgent) {
|
||||
if (!userAgent) {
|
||||
return false;
|
||||
}
|
||||
return userAgent.match(/^(wget|curl|vagrant)/i);
|
||||
};
|
||||
}
|
||||
|
||||
const hotlinkCheck = function(file, userAgent, referrer) {
|
||||
return !userAgentCheck(userAgent) && !file.width && (!referrer || !(referrer.match(/^https:\/\/hostr.co/) || referrer.match(/^http:\/\/localhost:4040/)))
|
||||
};
|
||||
function hotlinkCheck(file, userAgent, referrer) {
|
||||
return !userAgentCheck(userAgent) && !file.width && (!referrer || !(referrer.match(/^https:\/\/hostr.co/) || referrer.match(/^http:\/\/localhost:4040/)));
|
||||
}
|
||||
|
||||
export function* get() {
|
||||
const file = yield this.db.Files.findOne({_id: this.params.id, 'file_name': this.params.name, 'status': 'active'});
|
||||
this.assert(file, 404);
|
||||
|
||||
if (hotlinkCheck(file, this.headers['user-agent'], this.headers['referer'])) {
|
||||
if (hotlinkCheck(file, this.headers['user-agent'], this.headers.referer)) {
|
||||
return this.redirect('/' + file._id);
|
||||
}
|
||||
|
||||
if (!file.width && this.request.query.warning != 'on') {
|
||||
if (!file.width && this.request.query.warning !== 'on') {
|
||||
return this.redirect('/' + file._id);
|
||||
}
|
||||
|
||||
if (file.malware) {
|
||||
let alert = this.request.query.alert;
|
||||
const alert = this.request.query.alert;
|
||||
if (!alert || !alert.match(/i want to download malware/i)) {
|
||||
return this.redirect('/' + file._id);
|
||||
}
|
||||
|
@ -70,9 +66,9 @@ export function* get() {
|
|||
|
||||
if (!this.params.size || (this.params.size && this.params.size > 150)) {
|
||||
this.db.Files.updateOne(
|
||||
{_id: file._id},
|
||||
{'$set': {'last_accessed': Math.ceil(Date.now()/1000)}, '$inc': {downloads: 1}},
|
||||
{w:0}
|
||||
{'_id': file._id},
|
||||
{'$set': {'last_accessed': Math.ceil(Date.now() / 1000)}, '$inc': {downloads: 1}},
|
||||
{'w': 0}
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -86,7 +82,7 @@ export function* resized() {
|
|||
export function* landing() {
|
||||
const file = yield this.db.Files.findOne({_id: this.params.id, status: 'active'});
|
||||
this.assert(file, 404);
|
||||
if(userAgentCheck(this.headers['user-agent'])) {
|
||||
if (userAgentCheck(this.headers['user-agent'])) {
|
||||
this.params.name = file.file_name;
|
||||
return yield get.call(this);
|
||||
}
|
||||
|
|
|
@ -32,24 +32,24 @@ export function* staticPage(next) {
|
|||
this.session.user.token = token;
|
||||
yield this.render('index', {user: this.session.user});
|
||||
} else {
|
||||
switch(this.originalUrl) {
|
||||
case '/terms':
|
||||
yield this.render('terms');
|
||||
break;
|
||||
case '/privacy':
|
||||
yield this.render('privacy');
|
||||
break;
|
||||
case '/pricing':
|
||||
yield this.render('pricing');
|
||||
break;
|
||||
case '/apps':
|
||||
yield this.render('apps');
|
||||
break;
|
||||
case '/stats':
|
||||
yield this.render('index', {user: {}});
|
||||
break;
|
||||
default:
|
||||
yield next;
|
||||
switch (this.originalUrl) {
|
||||
case '/terms':
|
||||
yield this.render('terms');
|
||||
break;
|
||||
case '/privacy':
|
||||
yield this.render('privacy');
|
||||
break;
|
||||
case '/pricing':
|
||||
yield this.render('pricing');
|
||||
break;
|
||||
case '/apps':
|
||||
yield this.render('apps');
|
||||
break;
|
||||
case '/stats':
|
||||
yield this.render('index', {user: {}});
|
||||
break;
|
||||
default:
|
||||
yield next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ export function* create() {
|
|||
const createCustomer = {
|
||||
card: stripeToken.id,
|
||||
plan: 'usd_monthly',
|
||||
email: this.session.email
|
||||
email: this.session.email,
|
||||
};
|
||||
|
||||
const customer = yield stripe.customers.create(createCustomer);
|
||||
|
@ -32,7 +32,7 @@ export function* create() {
|
|||
'user_id': this.session.user.id,
|
||||
amount: customer.subscription.plan.amount,
|
||||
desc: customer.subscription.plan.name,
|
||||
date: new Date(customer.subscription.plan.created * 1000)
|
||||
date: new Date(customer.subscription.plan.created * 1000),
|
||||
};
|
||||
|
||||
yield Transactions.insertOne(transaction);
|
||||
|
@ -40,8 +40,8 @@ export function* create() {
|
|||
this.session.user.plan = 'Pro';
|
||||
this.body = {status: 'active'};
|
||||
|
||||
let html = yield render('email/inlined/pro');
|
||||
let text = `Hey, thanks for upgrading to Hostr Pro!
|
||||
const html = yield render('email/inlined/pro');
|
||||
const text = `Hey, thanks for upgrading to Hostr Pro!
|
||||
|
||||
You've signed up for Hostr Pro Monthly at $6/Month.
|
||||
|
||||
|
@ -56,11 +56,11 @@ export function* create() {
|
|||
'from_name': fromName,
|
||||
to: [{
|
||||
email: this.session.user.email,
|
||||
type: 'to'
|
||||
type: 'to',
|
||||
}],
|
||||
'tags': [
|
||||
'pro-upgrade'
|
||||
]
|
||||
'pro-upgrade',
|
||||
],
|
||||
}});
|
||||
}
|
||||
|
||||
|
|
|
@ -10,16 +10,15 @@ export function* signin() {
|
|||
this.statsd.incr('auth.attempt', 1);
|
||||
this.assertCSRF(this.request.body);
|
||||
const user = yield authenticate.call(this, this.request.body.email, this.request.body.password);
|
||||
if(!user) {
|
||||
if (!user) {
|
||||
this.statsd.incr('auth.failure', 1);
|
||||
return yield this.render('signin', {error: 'Invalid login details', csrf: this.csrf});
|
||||
} else if (user.activationCode) {
|
||||
return yield this.render('signin', {error: 'Your account hasn\'t been activated yet. Check your for an activation email.', csrf: this.csrf});
|
||||
} else {
|
||||
this.statsd.incr('auth.success', 1);
|
||||
yield setupSession.call(this, user);
|
||||
this.redirect('/');
|
||||
}
|
||||
this.statsd.incr('auth.success', 1);
|
||||
yield setupSession.call(this, user);
|
||||
this.redirect('/');
|
||||
}
|
||||
|
||||
|
||||
|
@ -60,7 +59,7 @@ export function* forgot() {
|
|||
}
|
||||
this.assertCSRF(this.request.body);
|
||||
const tokenUser = yield validateResetToken.call(this, token);
|
||||
var userId = tokenUser._id;
|
||||
const userId = tokenUser._id;
|
||||
yield updatePassword.call(this, userId, this.request.body.password);
|
||||
yield Reset.deleteOne({_id: userId});
|
||||
const user = yield Users.findOne({_id: userId});
|
||||
|
@ -72,13 +71,12 @@ export function* forgot() {
|
|||
if (!tokenUser) {
|
||||
this.statsd.incr('auth.reset.fail', 1);
|
||||
return yield this.render('forgot', {error: 'Invalid password reset token. It might be expired, or has already been used.', token: null, csrf: this.csrf});
|
||||
} else {
|
||||
return yield this.render('forgot', {token: token, csrf: this.csrf});
|
||||
}
|
||||
return yield this.render('forgot', {token: token, csrf: this.csrf});
|
||||
} else if (this.request.body.email) {
|
||||
this.assertCSRF(this.request.body);
|
||||
try {
|
||||
var email = this.request.body.email;
|
||||
const email = this.request.body.email;
|
||||
yield sendResetToken.call(this, email);
|
||||
this.statsd.incr('auth.reset.request', 1);
|
||||
return yield this.render('forgot', {message: 'We\'ve sent an email with a link to reset your password. Be sure to check your spam folder if you it doesn\'t appear within a few minutes', token: null, csrf: this.csrf});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue