Skip to content

Commit 086b05a

Browse files
authored
Merge pull request #681 from Pchelolo/syntax_to_es6
Syntax to es6
2 parents 3f433b1 + e232620 commit 086b05a

26 files changed

+2810
-2990
lines changed

.eslintrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extends: 'eslint-config-node-services'

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
language: node_js
22
node_js:
3-
- "0.10"
4-
- "0.12"
53
- "4"
64
- "6"
75

lib/access_check_filter.js

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,49 @@
11
'use strict';
22

3-
var mwUtil = require('./mwUtil');
4-
var P = require('bluebird');
5-
var URI = require('hyperswitch').URI;
3+
const mwUtil = require('./mwUtil');
4+
const P = require('bluebird');
5+
const URI = require('hyperswitch').URI;
66

7-
module.exports = function(hyper, req, next, options, specInfo) {
8-
var rp = req.params;
9-
var titleParamName = options.title ? options.title : 'title';
10-
var checkURIParts = [rp.domain, 'sys', 'page_revisions', 'restrictions', rp.title];
7+
module.exports = (hyper, req, next, options, specInfo) => {
8+
const rp = req.params;
9+
const titleParamName = options.title || 'title';
10+
const checkURIParts = [rp.domain, 'sys', 'page_revisions', 'restrictions', rp.title];
1111
if (rp.revision) {
12-
checkURIParts.push(rp.revision + '');
12+
checkURIParts.push(`${rp.revision}`);
1313
}
1414

1515
return P.join(
1616
next(hyper, req),
1717
hyper.get({ uri: new URI(checkURIParts) })
18-
.catch({ status: 404 }, function() {
19-
return null;
20-
})
18+
.catch({ status: 404 }, () => null)
2119
)
22-
.spread(function(content, restriction) {
20+
.spread((content, restriction) => {
2321
if (restriction || content.headers.location) {
2422
if (restriction && restriction.body) {
25-
var revInfo = mwUtil.parseETag(content.headers.etag);
23+
const revInfo = mwUtil.parseETag(content.headers.etag);
2624
mwUtil.applyAccessChecks(restriction.body, revInfo.rev);
2725
}
2826

2927
// Use redirect target from restrictions table or content response.
30-
var redirectTarget = restriction && restriction.body
28+
const redirectTarget = restriction && restriction.body
3129
&& restriction.body.redirect || content.headers.location;
3230
if (redirectTarget
3331
&& req.query.redirect !== false
3432
&& !mwUtil.isNoCacheRequest(req)) {
35-
var newParams = Object.assign({}, rp);
33+
const newParams = Object.assign({}, rp);
3634
newParams[titleParamName] = redirectTarget;
37-
var location = mwUtil.createRelativeTitleRedirect(specInfo.path,
35+
let location = mwUtil.createRelativeTitleRedirect(specInfo.path,
3836
req, {
3937
newReqParams: newParams,
40-
titleParamName: titleParamName,
38+
titleParamName,
4139
dropPathAfterTitle: true,
4240
});
4341

4442
if (mwUtil.isSelfRedirect(req, location)) {
4543
location = mwUtil.addQueryString(location, { redirect: false });
4644
}
4745

48-
var contentPromise;
46+
let contentPromise;
4947
if (options.attach_body_to_redirect) {
5048
contentPromise = P.resolve(content);
5149
} else {
@@ -55,19 +53,16 @@ module.exports = function(hyper, req, next, options, specInfo) {
5553
}
5654
});
5755
}
58-
return contentPromise.then(function(content) {
59-
return {
60-
status: 302,
61-
headers: Object.assign(content.headers, {
62-
location: location,
63-
'cache-control': options.redirect_cache_control || 'no-cache'
64-
}),
65-
body: content.body
66-
};
67-
});
56+
return contentPromise.then((theContent) => ({
57+
status: 302,
58+
headers: Object.assign(theContent.headers, {
59+
location,
60+
'cache-control': options.redirect_cache_control || 'no-cache'
61+
}),
62+
body: theContent.body
63+
}));
6864
}
6965
}
70-
7166
return content;
7267
});
7368
};

lib/ensure_content_type.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22

3-
var cType = require('content-type');
4-
var mwUtil = require('./mwUtil');
3+
const cType = require('content-type');
4+
const mwUtil = require('./mwUtil');
55

66
// Utility function to split path & version suffix from a profile parameter.
77
function splitProfile(profile) {
8-
var match = /^(.*)\/([0-9\.]+)$/.exec(profile);
8+
const match = /^(.*)\/([0-9\.]+)$/.exec(profile);
99
return {
1010
path: match[1],
1111
version: match[2],
@@ -23,7 +23,7 @@ function splitProfile(profile) {
2323

2424
function checkContentType(hyper, req, next, expectedContentType, responsePromise) {
2525
return responsePromise
26-
.then(function(res) {
26+
.then((res) => {
2727
// Do not check or re-render if the response was only rendered within
2828
// the last two minutes.
2929
if (res.headers && res.headers.etag
@@ -45,16 +45,16 @@ function checkContentType(hyper, req, next, expectedContentType, responsePromise
4545

4646
if (res.headers && res.headers['content-type'] !== expectedContentType) {
4747
// Parse the expected & response content type, and compare profiles.
48-
var expectedProfile = cType.parse(expectedContentType).parameters.profile;
49-
var actualProfile = cType.parse(res.headers['content-type']).parameters.profile;
48+
const expectedProfile = cType.parse(expectedContentType).parameters.profile;
49+
const actualProfile = cType.parse(res.headers['content-type']).parameters.profile;
5050

5151
if (actualProfile && actualProfile !== expectedProfile) {
5252
if (!expectedProfile) {
5353
return updateSpecWarning();
5454
}
5555
// Check if actual content type is newer than the spec
56-
var actualProfileParts = splitProfile(actualProfile);
57-
var expectedProfileParts = splitProfile(expectedProfile);
56+
const actualProfileParts = splitProfile(actualProfile);
57+
const expectedProfileParts = splitProfile(expectedProfile);
5858
if (actualProfileParts.path === expectedProfileParts.path
5959
&& actualProfileParts.version > expectedProfileParts.version) {
6060
return updateSpecWarning();
@@ -64,8 +64,7 @@ function checkContentType(hyper, req, next, expectedContentType, responsePromise
6464
// Re-try request with no-cache header
6565
if (!mwUtil.isNoCacheRequest(req)) {
6666
req.headers['cache-control'] = 'no-cache';
67-
return checkContentType(hyper, req, next,
68-
expectedContentType, next(hyper, req));
67+
return checkContentType(hyper, req, next, expectedContentType, next(hyper, req));
6968
} else {
7069
// Log issue
7170
hyper.log('warn/content-type/upgrade_failed', {
@@ -77,18 +76,16 @@ function checkContentType(hyper, req, next, expectedContentType, responsePromise
7776
res.headers['cache-control'] = 'max-age=10, s-maxage=10';
7877
}
7978
}
80-
8179
// Default: Just return.
8280
return res;
8381
});
8482
}
8583

8684

87-
module.exports = function(hyper, req, next, options, specInfo) {
88-
var rp = req.params;
89-
var produces = specInfo.spec.produces;
90-
var expectedContentType = Array.isArray(produces) && produces[0];
91-
var responsePromise = next(hyper, req);
85+
module.exports = (hyper, req, next, options, specInfo) => {
86+
const produces = specInfo.spec.produces;
87+
const expectedContentType = Array.isArray(produces) && produces[0];
88+
const responsePromise = next(hyper, req);
9289
if (expectedContentType) {
9390
// Found a content type. Ensure that we return the latest profile.
9491
return checkContentType(hyper, req, next, expectedContentType, responsePromise);

lib/mediawiki_auth_filter.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
"use strict";
22

3-
var HyperSwitch = require('hyperswitch');
4-
var HTTPError = HyperSwitch.HTTPError;
5-
var URI = HyperSwitch.URI;
6-
var P = require('bluebird');
3+
const HyperSwitch = require('hyperswitch');
4+
const HTTPError = HyperSwitch.HTTPError;
5+
const URI = HyperSwitch.URI;
76

87
function copyForwardedHeaders(req, rootReq, headersLins) {
98
if (rootReq.headers) {
109
req.headers = req.headers || {};
11-
headersLins.forEach(function(header) {
10+
headersLins.forEach((header) => {
1211
if (!req.headers[header] && rootReq.headers[header]) {
1312
req.headers[header] = rootReq.headers[header];
1413
}
@@ -26,17 +25,17 @@ function checkPermissions(hyper, req, permissions) {
2625
uiprop: 'rights'
2726
}
2827
})
29-
.then(function(userInfo) {
28+
.then((userInfo) => {
3029
userInfo = userInfo.body;
3130
if (userInfo && userInfo.rights && Array.isArray(userInfo.rights)) {
32-
permissions.forEach(function(perm) {
31+
permissions.forEach((perm) => {
3332
if (userInfo.rights.indexOf(perm) < 0) {
3433
throw new HTTPError({
3534
status: 401,
3635
body: {
3736
type: 'unauthorized',
3837
title: 'Not authorized to access the resource',
39-
description: 'Need permission ' + perm
38+
description: `Need permission ${perm}`
4039
}
4140
});
4241
}
@@ -53,7 +52,7 @@ function checkPermissions(hyper, req, permissions) {
5352
});
5453
}
5554

56-
module.exports = function(hyper, req, next, options) {
55+
module.exports = (hyper, req, next, options) => {
5756
if (hyper._isSysRequest(req)) {
5857
return next(hyper, req);
5958
}
@@ -66,13 +65,11 @@ module.exports = function(hyper, req, next, options) {
6665
}
6766

6867
return checkPermissions(hyper, req, options.permissions)
69-
.then(function() {
70-
return next(hyper, req);
71-
})
72-
.then(function(res) {
68+
.then(() => next(hyper, req))
69+
.then((res) => {
7370
if (res.headers) {
7471
res.headers['cache-control'] = 'no-cache';
7572
}
7673
return res;
7774
});
78-
};
75+
};

0 commit comments

Comments
 (0)