From cc9d6fd08b29436e134de89d3bf4487479c7ce32 Mon Sep 17 00:00:00 2001
From: Peter Jaszkowiak
Date: Thu, 4 Feb 2021 02:07:29 -0700
Subject: [PATCH] chore: eslint max-len
---
.eslintrc | 3 +-
public/src/admin/manage/users.js | 4 +-
public/src/ajaxify.js | 9 ++-
public/src/client/account/edit.js | 4 +-
public/src/client/account/header.js | 4 +-
public/src/client/groups/details.js | 12 +++-
public/src/client/topic.js | 14 ++++-
public/src/client/topic/events.js | 6 +-
public/src/client/topic/posts.js | 17 ++++--
public/src/modules/handleBack.js | 7 ++-
public/src/modules/hooks.js | 4 +-
public/src/modules/pictureCropper.js | 4 +-
public/src/modules/settings/key.js | 18 +++++-
public/src/modules/settings/object.js | 12 +++-
public/src/modules/topicList.js | 40 ++++++++++---
public/src/modules/translator.js | 3 +-
public/src/utils.js | 12 +++-
src/analytics.js | 9 ++-
src/categories/index.js | 4 +-
src/cli/upgrade.js | 3 +-
src/controllers/accounts/helpers.js | 5 +-
src/controllers/accounts/profile.js | 9 ++-
src/controllers/accounts/settings.js | 4 +-
src/controllers/admin/plugins.js | 11 ++--
src/controllers/api.js | 4 +-
src/controllers/authentication.js | 6 +-
src/controllers/helpers.js | 10 +++-
src/controllers/index.js | 4 +-
src/controllers/mods.js | 5 +-
src/controllers/topics.js | 11 +++-
src/controllers/uploads.js | 5 +-
src/controllers/write/topics.js | 3 +-
src/database/mongo/sorted.js | 4 +-
src/database/mongo/sorted/add.js | 5 +-
src/groups/posts.js | 7 ++-
src/install.js | 11 +++-
src/messaging/data.js | 4 +-
src/middleware/expose.js | 5 +-
src/notifications.js | 6 +-
src/posts/parse.js | 9 ++-
src/posts/summary.js | 3 +-
src/privileges/posts.js | 20 +++++--
src/privileges/topics.js | 10 +++-
src/routes/feeds.js | 4 +-
src/routes/helpers.js | 9 ++-
src/routes/write/files.js | 12 +++-
src/socket.io/admin.js | 4 +-
src/socket.io/admin/analytics.js | 3 +-
src/socket.io/index.js | 4 +-
src/socket.io/topics/infinitescroll.js | 10 +++-
src/topics/events.js | 3 +-
src/topics/sorted.js | 7 ++-
src/topics/teaser.js | 3 +-
src/upgrades/1.10.2/upgrade_bans_to_hashes.js | 7 ++-
src/user/auth.js | 8 ++-
src/user/jobs/export-profile.js | 14 ++++-
src/user/posts.js | 6 +-
src/user/settings.js | 32 ++++++----
test/api.js | 3 +-
test/categories.js | 6 +-
test/messaging.js | 5 +-
test/posts.js | 5 +-
test/topics.js | 42 +++++++++++--
test/uploads.js | 59 ++++++++++++-------
64 files changed, 459 insertions(+), 137 deletions(-)
diff --git a/.eslintrc b/.eslintrc
index 5cd72ea708..b81c92ff86 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -81,8 +81,7 @@
}
],
// allow lines of up to 120 characters
- // "max-len": ["error", { "code": 120, "tabWidth": 2, "ignoreUrls": true, "ignoreStrings": true, "ignoreTemplateLiterals": true, "ignoreRegExpLiterals": true }],
- "max-len": "off", // do this LAST
+ "max-len": ["error", { "code": 120, "tabWidth": 2, "ignoreUrls": true, "ignoreStrings": true, "ignoreTemplateLiterals": true, "ignoreRegExpLiterals": true }],
// === Disable rules ===
// more liberal naming
diff --git a/public/src/admin/manage/users.js b/public/src/admin/manage/users.js
index 6df89761e5..5552e89d4a 100644
--- a/public/src/admin/manage/users.js
+++ b/public/src/admin/manage/users.js
@@ -184,7 +184,9 @@ define('admin/manage/users', [
data[cur.name] = cur.value;
return data;
}, {});
- var until = formData.length > 0 ? (Date.now() + (formData.length * 1000 * 60 * 60 * (parseInt(formData.unit, 10) ? 24 : 1))) : 0;
+ var until = formData.length > 0 ? (
+ Date.now() + (formData.length * 1000 * 60 * 60 * (parseInt(formData.unit, 10) ? 24 : 1))
+ ) : 0;
Promise.all(uids.map(function (uid) {
return api.put('/users/' + uid + '/ban', {
diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js
index 02d5269fd8..c3fa06d349 100644
--- a/public/src/ajaxify.js
+++ b/public/src/ajaxify.js
@@ -62,7 +62,11 @@ ajaxify = window.ajaxify || {};
$('#footer, #content').removeClass('hide').addClass('ajaxifying');
ajaxify.loadData(url, function (err, data) {
- if (!err || (err && err.data && (parseInt(err.data.status, 10) !== 302 && parseInt(err.data.status, 10) !== 308))) {
+ if (!err || (
+ err &&
+ err.data &&
+ (parseInt(err.data.status, 10) !== 302 && parseInt(err.data.status, 10) !== 308)
+ )) {
ajaxify.updateHistory(url, quiet);
}
@@ -340,7 +344,8 @@ ajaxify = window.ajaxify || {};
if (typeof script === 'string') {
return function (next) {
require(['hooks', script], function (hooks, module) {
- // Hint: useful if you want to override a loaded library (e.g. replace core client-side logic), or call a method other than .init()
+ // Hint: useful if you want to override a loaded library (e.g. replace core client-side logic),
+ // or call a method other than .init()
hooks.fire('static:script.init', { tpl_url, name: script, module }).then(() => {
if (module && module.init) {
module.init();
diff --git a/public/src/client/account/edit.js b/public/src/client/account/edit.js
index 7fd37194ce..907b2d7a9a 100644
--- a/public/src/client/account/edit.js
+++ b/public/src/client/account/edit.js
@@ -43,7 +43,9 @@ define('forum/account/edit', [
aboutme: $('#inputAboutMe').val(),
};
- userData.groupTitle = JSON.stringify(Array.isArray(userData.groupTitle) ? userData.groupTitle : [userData.groupTitle]);
+ userData.groupTitle = JSON.stringify(
+ Array.isArray(userData.groupTitle) ? userData.groupTitle : [userData.groupTitle]
+ );
$(window).trigger('action:profile.update', userData);
diff --git a/public/src/client/account/header.js b/public/src/client/account/header.js
index fa188d1da7..d7d04ebdd5 100644
--- a/public/src/client/account/header.js
+++ b/public/src/client/account/header.js
@@ -150,7 +150,9 @@ define('forum/account/header', [
return data;
}, {});
- var until = formData.length > 0 ? (Date.now() + (formData.length * 1000 * 60 * 60 * (parseInt(formData.unit, 10) ? 24 : 1))) : 0;
+ var until = formData.length > 0 ? (
+ Date.now() + (formData.length * 1000 * 60 * 60 * (parseInt(formData.unit, 10) ? 24 : 1))
+ ) : 0;
api.put('/users/' + theirid + '/ban', {
until: until,
diff --git a/public/src/client/groups/details.js b/public/src/client/groups/details.js
index ae0d92b74a..531c62532e 100644
--- a/public/src/client/groups/details.js
+++ b/public/src/client/groups/details.js
@@ -10,7 +10,17 @@ define('forum/groups/details', [
'api',
'slugify',
'categorySelector',
-], function (memberList, iconSelect, components, coverPhoto, pictureCropper, translator, api, slugify, categorySelector) {
+], function (
+ memberList,
+ iconSelect,
+ components,
+ coverPhoto,
+ pictureCropper,
+ translator,
+ api,
+ slugify,
+ categorySelector
+) {
var Details = {};
var groupName;
diff --git a/public/src/client/topic.js b/public/src/client/topic.js
index 0a5b47fee6..9e186457ea 100644
--- a/public/src/client/topic.js
+++ b/public/src/client/topic.js
@@ -130,7 +130,10 @@ define('forum/topic', [
if (components.get('post/anchor', postIndex - 1).length) {
return navigator.scrollToPostIndex(postIndex - 1, true, 0);
}
- } else if (bookmark && (!config.usePagination || (config.usePagination && ajaxify.data.pagination.currentPage === 1)) && ajaxify.data.postcount > ajaxify.data.bookmarkThreshold) {
+ } else if (bookmark && (
+ !config.usePagination ||
+ (config.usePagination && ajaxify.data.pagination.currentPage === 1)
+ ) && ajaxify.data.postcount > ajaxify.data.bookmarkThreshold) {
app.alert({
alert_id: 'bookmark',
message: '[[topic:bookmark_instructions]]',
@@ -250,7 +253,14 @@ define('forum/topic', [
index = Math.max(1, ajaxify.data.postcount - index + 2);
}
- if (ajaxify.data.postcount > ajaxify.data.bookmarkThreshold && (!currentBookmark || parseInt(index, 10) > parseInt(currentBookmark, 10) || ajaxify.data.postcount < parseInt(currentBookmark, 10))) {
+ if (
+ ajaxify.data.postcount > ajaxify.data.bookmarkThreshold &&
+ (
+ !currentBookmark ||
+ parseInt(index, 10) > parseInt(currentBookmark, 10) ||
+ ajaxify.data.postcount < parseInt(currentBookmark, 10)
+ )
+ ) {
if (app.user.uid) {
socket.emit('topics.bookmark', {
tid: ajaxify.data.tid,
diff --git a/public/src/client/topic/events.js b/public/src/client/topic/events.js
index d98195434b..d0e30a09da 100644
--- a/public/src/client/topic/events.js
+++ b/public/src/client/topic/events.js
@@ -84,7 +84,11 @@ define('forum/topic/events', [
}
function onTopicPurged(data) {
- if (ajaxify.data.category && ajaxify.data.category.slug && parseInt(data.tid, 10) === parseInt(ajaxify.data.tid, 10)) {
+ if (
+ ajaxify.data.category &&
+ ajaxify.data.category.slug &&
+ parseInt(data.tid, 10) === parseInt(ajaxify.data.tid, 10)
+ ) {
ajaxify.go('category/' + ajaxify.data.category.slug, null, true);
}
}
diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.js
index 0300bd4018..2173f50af5 100644
--- a/public/src/client/topic/posts.js
+++ b/public/src/client/topic/posts.js
@@ -13,7 +13,12 @@ define('forum/topic/posts', [
var Posts = { };
Posts.onNewPost = function (data) {
- if (!data || !data.posts || !data.posts.length || parseInt(data.posts[0].tid, 10) !== parseInt(ajaxify.data.tid, 10)) {
+ if (
+ !data ||
+ !data.posts ||
+ !data.posts.length ||
+ parseInt(data.posts[0].tid, 10) !== parseInt(ajaxify.data.tid, 10)
+ ) {
return;
}
@@ -88,8 +93,10 @@ define('forum/topic/posts', [
ajaxify.data.pagination.pageCount = Math.max(1, Math.ceil(posts[0].topic.postcount / config.postsPerPage));
var direction = config.topicPostSort === 'oldest_to_newest' || config.topicPostSort === 'most_votes' ? 1 : -1;
- var isPostVisible = (ajaxify.data.pagination.currentPage === ajaxify.data.pagination.pageCount && direction === 1) ||
- (ajaxify.data.pagination.currentPage === 1 && direction === -1);
+ var isPostVisible = (
+ ajaxify.data.pagination.currentPage === ajaxify.data.pagination.pageCount &&
+ direction === 1
+ ) || (ajaxify.data.pagination.currentPage === 1 && direction === -1);
if (isPostVisible) {
createNewPosts(data, components.get('post').not('[data-index=0]'), direction, false, scrollToPost);
@@ -299,7 +306,9 @@ define('forum/topic/posts', [
}
Promise.all(events.map((event) => {
- const beforeIdx = postTimestamps.findIndex(timestamp => (reverse ? (timestamp < event.timestamp) : (timestamp > event.timestamp)));
+ const beforeIdx = postTimestamps.findIndex(
+ timestamp => (reverse ? (timestamp < event.timestamp) : (timestamp > event.timestamp))
+ );
let postEl;
if (beforeIdx > -1) {
postEl = document.querySelector(`[component="post"][data-pid="${ajaxify.data.posts[beforeIdx + (reverse ? 1 : 0)].pid}"]`);
diff --git a/public/src/modules/handleBack.js b/public/src/modules/handleBack.js
index ea69798d28..e16546b705 100644
--- a/public/src/modules/handleBack.js
+++ b/public/src/modules/handleBack.js
@@ -34,7 +34,12 @@ define('handleBack', [
function onBackClicked(isMarkedUnread) {
var highlightUnread = isMarkedUnread && ajaxify.data.template.unread;
- if (ajaxify.data.template.category || ajaxify.data.template.recent || ajaxify.data.template.popular || highlightUnread) {
+ if (
+ ajaxify.data.template.category ||
+ ajaxify.data.template.recent ||
+ ajaxify.data.template.popular ||
+ highlightUnread
+ ) {
var bookmarkIndex = storage.getItem('category:bookmark');
var clickedIndex = storage.getItem('category:bookmark:clicked');
diff --git a/public/src/modules/hooks.js b/public/src/modules/hooks.js
index 1a5b7cdf32..ef09f7f236 100644
--- a/public/src/modules/hooks.js
+++ b/public/src/modules/hooks.js
@@ -28,7 +28,9 @@ define('hooks', [], () => {
return listeners.reduce((promise, listener) => promise.then((data) => {
try {
const result = listener(data);
- return utils.isPromise(result) ? result.then(data => Promise.resolve(data)).catch(e => _onHookError(e, listener, data)) : result;
+ return utils.isPromise(result) ?
+ result.then(data => Promise.resolve(data)).catch(e => _onHookError(e, listener, data)) :
+ result;
} catch (e) {
return _onHookError(e, listener, data);
}
diff --git a/public/src/modules/pictureCropper.js b/public/src/modules/pictureCropper.js
index 245312f16d..f9033cd89b 100644
--- a/public/src/modules/pictureCropper.js
+++ b/public/src/modules/pictureCropper.js
@@ -176,7 +176,9 @@ define('pictureCropper', ['cropper'], function (Cropper) {
function checkCORS(cropperTool, data) {
var imageData;
try {
- imageData = data.imageType ? cropperTool.getCroppedCanvas().toDataURL(data.imageType) : cropperTool.getCroppedCanvas().toDataURL();
+ imageData = data.imageType ?
+ cropperTool.getCroppedCanvas().toDataURL(data.imageType) :
+ cropperTool.getCroppedCanvas().toDataURL();
} catch (err) {
var corsErrors = [
'The operation is insecure.',
diff --git a/public/src/modules/settings/key.js b/public/src/modules/settings/key.js
index 524fd1ebec..fd0b41e926 100644
--- a/public/src/modules/settings/key.js
+++ b/public/src/modules/settings/key.js
@@ -42,8 +42,22 @@ define('settings/key', function () {
@returns Key | null The Key-Object the focused element should be set to.
*/
function getKey(event) {
- var anyModChange = event.ctrlKey !== lastKey.c || event.altKey !== lastKey.a || event.shiftKey !== lastKey.s || event.metaKey !== lastKey.m;
- var modChange = event.ctrlKey + event.altKey + event.shiftKey + event.metaKey - lastKey.c - lastKey.a - lastKey.s - lastKey.m;
+ var anyModChange = (
+ event.ctrlKey !== lastKey.c ||
+ event.altKey !== lastKey.a ||
+ event.shiftKey !== lastKey.s ||
+ event.metaKey !== lastKey.m
+ );
+ var modChange = (
+ event.ctrlKey +
+ event.altKey +
+ event.shiftKey +
+ event.metaKey -
+ lastKey.c -
+ lastKey.a -
+ lastKey.s -
+ lastKey.m
+ );
var key = new Key();
key.c = event.ctrlKey;
key.a = event.altKey;
diff --git a/public/src/modules/settings/object.js b/public/src/modules/settings/object.js
index 7e79e54cc3..92c91a041f 100644
--- a/public/src/modules/settings/object.js
+++ b/public/src/modules/settings/object.js
@@ -90,9 +90,15 @@ define('settings/object', function () {
if (value[propertyName] === undefined && attributes['data-new'] !== undefined) {
value[propertyName] = attributes['data-new'];
}
- addObjectPropertyElement(element, key, attributes, propertyName, value[propertyName], separator.clone(), function (el) {
- element.append(el);
- });
+ addObjectPropertyElement(
+ element,
+ key,
+ attributes,
+ propertyName,
+ value[propertyName],
+ separator.clone(),
+ function (el) { element.append(el); }
+ );
}
}
}
diff --git a/public/src/modules/topicList.js b/public/src/modules/topicList.js
index e9d00ad5fd..58a7d23ae3 100644
--- a/public/src/modules/topicList.js
+++ b/public/src/modules/topicList.js
@@ -96,9 +96,19 @@ define('topicList', [
function onNewTopic(data) {
if (
- (ajaxify.data.selectedCids && ajaxify.data.selectedCids.length && ajaxify.data.selectedCids.indexOf(parseInt(data.cid, 10)) === -1) ||
- (ajaxify.data.selectedFilter && ajaxify.data.selectedFilter.filter === 'watched') ||
- (ajaxify.data.template.category && parseInt(ajaxify.data.cid, 10) !== parseInt(data.cid, 10))
+ (
+ ajaxify.data.selectedCids &&
+ ajaxify.data.selectedCids.length &&
+ ajaxify.data.selectedCids.indexOf(parseInt(data.cid, 10)) === -1
+ ) ||
+ (
+ ajaxify.data.selectedFilter &&
+ ajaxify.data.selectedFilter.filter === 'watched'
+ ) ||
+ (
+ ajaxify.data.template.category &&
+ parseInt(ajaxify.data.cid, 10) !== parseInt(data.cid, 10)
+ )
) {
return;
}
@@ -113,11 +123,25 @@ define('topicList', [
return;
}
if (!post.topic.isFollowing && (
- (parseInt(post.topic.mainPid, 10) === parseInt(post.pid, 10)) ||
- (ajaxify.data.selectedCids && ajaxify.data.selectedCids.length && ajaxify.data.selectedCids.indexOf(parseInt(post.topic.cid, 10)) === -1) ||
- (ajaxify.data.selectedFilter && ajaxify.data.selectedFilter.filter === 'new') ||
- (ajaxify.data.selectedFilter && ajaxify.data.selectedFilter.filter === 'watched' && !post.topic.isFollowing) ||
- (ajaxify.data.template.category && parseInt(ajaxify.data.cid, 10) !== parseInt(post.topic.cid, 10))
+ parseInt(post.topic.mainPid, 10) === parseInt(post.pid, 10) ||
+ (
+ ajaxify.data.selectedCids &&
+ ajaxify.data.selectedCids.length &&
+ ajaxify.data.selectedCids.indexOf(parseInt(post.topic.cid, 10)) === -1
+ ) ||
+ (
+ ajaxify.data.selectedFilter &&
+ ajaxify.data.selectedFilter.filter === 'new'
+ ) ||
+ (
+ ajaxify.data.selectedFilter &&
+ ajaxify.data.selectedFilter.filter === 'watched' &&
+ !post.topic.isFollowing
+ ) ||
+ (
+ ajaxify.data.template.category &&
+ parseInt(ajaxify.data.cid, 10) !== parseInt(post.topic.cid, 10)
+ )
)) {
return;
}
diff --git a/public/src/modules/translator.js b/public/src/modules/translator.js
index 30ec2e1979..b83a5a450f 100644
--- a/public/src/modules/translator.js
+++ b/public/src/modules/translator.js
@@ -308,7 +308,8 @@
warn('[translator] Parameter `namespace` is ' + namespace + (namespace === '' ? '(empty string)' : ''));
translation = Promise.resolve({});
} else {
- this.translations[namespace] = this.translations[namespace] || this.load(this.lang, namespace).catch(function () { return {}; });
+ this.translations[namespace] = this.translations[namespace] ||
+ this.load(this.lang, namespace).catch(function () { return {}; });
translation = this.translations[namespace];
}
diff --git a/public/src/utils.js b/public/src/utils.js
index 43c2bc9bd4..0a4696f98d 100644
--- a/public/src/utils.js
+++ b/public/src/utils.js
@@ -646,7 +646,10 @@
params.forEach(function (param) {
var val = param.split('=');
var key = decodeURI(val[0]);
- var value = options.disableToType || options.skipToType[key] ? decodeURI(val[1]) : utils.toType(decodeURI(val[1]));
+ var value = (
+ options.disableToType ||
+ options.skipToType[key] ? decodeURI(val[1]) : utils.toType(decodeURI(val[1]))
+ );
if (key) {
if (key.substr(-2, 2) === '[]') {
@@ -732,8 +735,11 @@
isInternalURI: function (targetLocation, referenceLocation, relative_path) {
return targetLocation.host === '' || // Relative paths are always internal links
(
- targetLocation.host === referenceLocation.host && targetLocation.protocol === referenceLocation.protocol && // Otherwise need to check if protocol and host match
- (relative_path.length > 0 ? targetLocation.pathname.indexOf(relative_path) === 0 : true) // Subfolder installs need this additional check
+ targetLocation.host === referenceLocation.host &&
+ // Otherwise need to check if protocol and host match
+ targetLocation.protocol === referenceLocation.protocol &&
+ // Subfolder installs need this additional check
+ (relative_path.length > 0 ? targetLocation.pathname.indexOf(relative_path) === 0 : true)
);
},
diff --git a/src/analytics.js b/src/analytics.js
index dbc601b689..fa848ad665 100644
--- a/src/analytics.js
+++ b/src/analytics.js
@@ -181,12 +181,17 @@ Analytics.getDailyStatsForSet = async function (set, day, numDays) {
const daysArr = [];
day = new Date(day);
- day.setDate(day.getDate() + 1); // set the date to tomorrow, because getHourlyStatsForSet steps *backwards* 24 hours to sum up the values
+ // set the date to tomorrow, because getHourlyStatsForSet steps *backwards* 24 hours to sum up the values
+ day.setDate(day.getDate() + 1);
day.setHours(0, 0, 0, 0);
while (numDays > 0) {
/* eslint-disable no-await-in-loop */
- const dayData = await Analytics.getHourlyStatsForSet(set, day.getTime() - (1000 * 60 * 60 * 24 * (numDays - 1)), 24);
+ const dayData = await Analytics.getHourlyStatsForSet(
+ set,
+ day.getTime() - (1000 * 60 * 60 * 24 * (numDays - 1)),
+ 24
+ );
daysArr.push(dayData.reduce((cur, next) => cur + next));
numDays -= 1;
}
diff --git a/src/categories/index.js b/src/categories/index.js
index 9a87d5ebbb..718fa9b95e 100644
--- a/src/categories/index.js
+++ b/src/categories/index.js
@@ -118,7 +118,9 @@ Categories.getModeratorUids = async function (cids) {
const uniqGroups = _.uniq(_.flatten(sets.groupNames));
const groupUids = await groups.getMembersOfGroups(uniqGroups);
const map = _.zipObject(uniqGroups, groupUids);
- const moderatorUids = cids.map((cid, index) => _.uniq(sets.uids[index].concat(_.flatten(sets.groupNames[index].map(g => map[g])))));
+ const moderatorUids = cids.map(
+ (cid, index) => _.uniq(sets.uids[index].concat(_.flatten(sets.groupNames[index].map(g => map[g]))))
+ );
return moderatorUids;
};
diff --git a/src/cli/upgrade.js b/src/cli/upgrade.js
index 9c1beab4f0..0e1e96b1da 100644
--- a/src/cli/upgrade.js
+++ b/src/cli/upgrade.js
@@ -68,7 +68,8 @@ function runSteps(tasks) {
}
const message = 'NodeBB Upgrade Complete!';
- // some consoles will return undefined/zero columns, so just use 2 spaces in upgrade script if we can't get our column count
+ // some consoles will return undefined/zero columns,
+ // so just use 2 spaces in upgrade script if we can't get our column count
const { columns } = process.stdout;
const spaces = columns ? new Array(Math.floor(columns / 2) - (message.length / 2) + 1).join(' ') : ' ';
diff --git a/src/controllers/accounts/helpers.js b/src/controllers/accounts/helpers.js
index a6b1d45872..718f5fe7c4 100644
--- a/src/controllers/accounts/helpers.js
+++ b/src/controllers/accounts/helpers.js
@@ -36,7 +36,10 @@ helpers.getUserDataByUserSlug = async function (userslug, callerUID) {
const { canViewInfo } = results;
const isSelf = parseInt(callerUID, 10) === parseInt(userData.uid, 10);
- userData.age = Math.max(0, userData.birthday ? Math.floor((new Date().getTime() - new Date(userData.birthday).getTime()) / 31536000000) : 0);
+ userData.age = Math.max(
+ 0,
+ userData.birthday ? Math.floor((new Date().getTime() - new Date(userData.birthday).getTime()) / 31536000000) : 0
+ );
userData.emailClass = 'hide';
diff --git a/src/controllers/accounts/profile.js b/src/controllers/accounts/profile.js
index 434a6ef925..e009a4aa9a 100644
--- a/src/controllers/accounts/profile.js
+++ b/src/controllers/accounts/profile.js
@@ -65,7 +65,10 @@ async function incrementProfileViews(req, userData) {
if (req.uid >= 1) {
req.session.uids_viewed = req.session.uids_viewed || {};
- if (req.uid !== userData.uid && (!req.session.uids_viewed[userData.uid] || req.session.uids_viewed[userData.uid] < Date.now() - 3600000)) {
+ if (
+ req.uid !== userData.uid &&
+ (!req.session.uids_viewed[userData.uid] || req.session.uids_viewed[userData.uid] < Date.now() - 3600000)
+ ) {
await user.incrementUserFieldBy(userData.uid, 'profileviews', 1);
req.session.uids_viewed[userData.uid] = Date.now();
}
@@ -102,7 +105,9 @@ async function getPosts(callerUid, userData, setSuffix) {
}
if (pids.length) {
const p = await posts.getPostSummaryByPids(pids, callerUid, { stripTags: false });
- postData.push(...p.filter(p => p && p.topic && (isAdmin || cidToIsMod[p.topic.cid] || (!p.deleted && !p.topic.deleted))));
+ postData.push(...p.filter(
+ p => p && p.topic && (isAdmin || cidToIsMod[p.topic.cid] || (!p.deleted && !p.topic.deleted))
+ ));
}
start += count;
} while (postData.length < count && hasMorePosts);
diff --git a/src/controllers/accounts/settings.js b/src/controllers/accounts/settings.js
index 37feace88b..8d561bc976 100644
--- a/src/controllers/accounts/settings.js
+++ b/src/controllers/accounts/settings.js
@@ -99,7 +99,9 @@ settingsController.get = async function (req, res, next) {
'disabled',
];
- userData.upvoteNotifFreq = notifFreqOptions.map(name => ({ name: name, selected: name === userData.settings.upvoteNotifFreq }));
+ userData.upvoteNotifFreq = notifFreqOptions.map(
+ name => ({ name: name, selected: name === userData.settings.upvoteNotifFreq })
+ );
userData.categoryWatchState = { [userData.settings.categoryWatchState]: true };
diff --git a/src/controllers/admin/plugins.js b/src/controllers/admin/plugins.js
index 271c91f29d..eca548af72 100644
--- a/src/controllers/admin/plugins.js
+++ b/src/controllers/admin/plugins.js
@@ -22,10 +22,13 @@ pluginsController.get = async function (req, res) {
memo[cur.label] = cur.value;
return memo;
}, {});
- const trendingPlugins = all.filter(plugin => plugin && Object.keys(trendingScores).includes(plugin.id)).sort((a, b) => trendingScores[b.id] - trendingScores[a.id]).map((plugin) => {
- plugin.downloads = trendingScores[plugin.id];
- return plugin;
- });
+ const trendingPlugins = all
+ .filter(plugin => plugin && Object.keys(trendingScores).includes(plugin.id))
+ .sort((a, b) => trendingScores[b.id] - trendingScores[a.id])
+ .map((plugin) => {
+ plugin.downloads = trendingScores[plugin.id];
+ return plugin;
+ });
res.render('admin/extend/plugins', {
installed: installedPlugins,
diff --git a/src/controllers/api.js b/src/controllers/api.js
index e3e697498e..bbb7cd39bc 100644
--- a/src/controllers/api.js
+++ b/src/controllers/api.js
@@ -95,7 +95,9 @@ apiController.loadConfig = async function (req) {
config.usePagination = settings.usePagination;
config.topicsPerPage = settings.topicsPerPage;
config.postsPerPage = settings.postsPerPage;
- config.userLang = validator.escape(String((req.query.lang ? req.query.lang : null) || settings.userLang || config.defaultLang));
+ config.userLang = validator.escape(
+ String((req.query.lang ? req.query.lang : null) || settings.userLang || config.defaultLang)
+ );
config.acpLang = validator.escape(String((req.query.lang ? req.query.lang : null) || settings.acpLang));
config.openOutgoingLinksInNewTab = settings.openOutgoingLinksInNewTab;
config.topicPostSort = settings.topicPostSort || config.topicPostSort;
diff --git a/src/controllers/authentication.js b/src/controllers/authentication.js
index 9f1322ef99..737d87cf18 100644
--- a/src/controllers/authentication.js
+++ b/src/controllers/authentication.js
@@ -83,7 +83,11 @@ authenticationController.register = async function (req, res) {
throw new Error('[[error:invalid-email]]');
}
- if (!userData.username || userData.username.length < meta.config.minimumUsernameLength || slugify(userData.username).length < meta.config.minimumUsernameLength) {
+ if (
+ !userData.username ||
+ userData.username.length < meta.config.minimumUsernameLength ||
+ slugify(userData.username).length < meta.config.minimumUsernameLength
+ ) {
throw new Error('[[error:username-too-short]]');
}
diff --git a/src/controllers/helpers.js b/src/controllers/helpers.js
index 0eb47fb904..13a639eb83 100644
--- a/src/controllers/helpers.js
+++ b/src/controllers/helpers.js
@@ -315,7 +315,12 @@ helpers.getVisibleCategories = async function (params) {
return false;
}
const hasVisibleChildren = checkVisibleChildren(c, cidToAllowed, cidToWatchState, states);
- const isCategoryVisible = cidToAllowed[c.cid] && (showLinks || !c.link) && !c.disabled && states.includes(cidToWatchState[c.cid]);
+ const isCategoryVisible = (
+ cidToAllowed[c.cid] &&
+ (showLinks || !c.link) &&
+ !c.disabled &&
+ states.includes(cidToWatchState[c.cid])
+ );
const shouldBeRemoved = !hasVisibleChildren && !isCategoryVisible;
const shouldBeDisaplayedAsDisabled = hasVisibleChildren && !isCategoryVisible;
@@ -380,7 +385,8 @@ function checkVisibleChildren(c, cidToAllowed, cidToWatchState, states) {
return false;
}
return c.children.some(c => !c.disabled && (
- (cidToAllowed[c.cid] && states.includes(cidToWatchState[c.cid])) || checkVisibleChildren(c, cidToAllowed, cidToWatchState, states)
+ (cidToAllowed[c.cid] && states.includes(cidToWatchState[c.cid])) ||
+ checkVisibleChildren(c, cidToAllowed, cidToWatchState, states)
));
}
diff --git a/src/controllers/index.js b/src/controllers/index.js
index 46ba28a67c..e965ff0606 100644
--- a/src/controllers/index.js
+++ b/src/controllers/index.js
@@ -202,7 +202,9 @@ Controllers.registerInterstitial = async function (req, res, next) {
return helpers.redirect(res, returnTo || '/');
}
- const renders = data.interstitials.map(interstitial => req.app.renderAsync(interstitial.template, interstitial.data || {}));
+ const renders = data.interstitials.map(
+ interstitial => req.app.renderAsync(interstitial.template, interstitial.data || {})
+ );
const sections = await Promise.all(renders);
res.render('registerComplete', {
diff --git a/src/controllers/mods.js b/src/controllers/mods.js
index acffd4f545..33538a6ad4 100644
--- a/src/controllers/mods.js
+++ b/src/controllers/mods.js
@@ -131,7 +131,10 @@ modsController.flags.detail = async function (req, res, next) {
assignees: results.assignees,
type_bool: ['post', 'user', 'empty'].reduce((memo, cur) => {
if (cur !== 'empty') {
- memo[cur] = results.flagData.type === cur && (!results.flagData.target || !!Object.keys(results.flagData.target).length);
+ memo[cur] = results.flagData.type === cur && (
+ !results.flagData.target ||
+ !!Object.keys(results.flagData.target).length
+ );
} else {
memo[cur] = !Object.keys(results.flagData.target).length;
}
diff --git a/src/controllers/topics.js b/src/controllers/topics.js
index 7ced57b9db..005c332976 100644
--- a/src/controllers/topics.js
+++ b/src/controllers/topics.js
@@ -22,7 +22,10 @@ const upload_url = nconf.get('upload_url');
topicsController.get = async function getTopic(req, res, callback) {
const tid = req.params.topic_id;
- if ((req.params.post_index && !utils.isNumber(req.params.post_index) && req.params.post_index !== 'unread') || !utils.isNumber(tid)) {
+ if (
+ (req.params.post_index && !utils.isNumber(req.params.post_index) && req.params.post_index !== 'unread') ||
+ !utils.isNumber(tid)
+ ) {
return callback();
}
let postIndex = parseInt(req.params.post_index, 10) || 1;
@@ -40,7 +43,11 @@ topicsController.get = async function getTopic(req, res, callback) {
let currentPage = parseInt(req.query.page, 10) || 1;
const pageCount = Math.max(1, Math.ceil((topicData && topicData.postcount) / settings.postsPerPage));
- if (!topicData || userPrivileges.disabled || (settings.usePagination && (currentPage < 1 || currentPage > pageCount))) {
+ if (
+ !topicData ||
+ userPrivileges.disabled ||
+ (settings.usePagination && (currentPage < 1 || currentPage > pageCount))
+ ) {
return callback();
}
diff --git a/src/controllers/uploads.js b/src/controllers/uploads.js
index a5e3b50bd9..01adb2f8b8 100644
--- a/src/controllers/uploads.js
+++ b/src/controllers/uploads.js
@@ -101,7 +101,10 @@ async function uploadAsFile(req, uploadedFile) {
async function resizeImage(fileObj) {
const imageData = await image.size(fileObj.path);
- if (imageData.width < meta.config.resizeImageWidthThreshold || meta.config.resizeImageWidth > meta.config.resizeImageWidthThreshold) {
+ if (
+ imageData.width < meta.config.resizeImageWidthThreshold ||
+ meta.config.resizeImageWidth > meta.config.resizeImageWidthThreshold
+ ) {
return fileObj;
}
diff --git a/src/controllers/write/topics.js b/src/controllers/write/topics.js
index e940fd28e7..23ade7262d 100644
--- a/src/controllers/write/topics.js
+++ b/src/controllers/write/topics.js
@@ -168,7 +168,8 @@ Topics.deleteThumb = async (req, res) => {
};
async function checkThumbPrivileges({ tid, uid, res }) {
- // req.params.tid could be either a tid (pushing a new thumb to an existing topic) or a post UUID (a new topic being composed)
+ // req.params.tid could be either a tid (pushing a new thumb to an existing topic)
+ // or a post UUID (a new topic being composed)
const isUUID = validator.isUUID(tid);
// Sanity-check the tid if it's strictly not a uuid
diff --git a/src/database/mongo/sorted.js b/src/database/mongo/sorted.js
index 39f2258466..87664c71ed 100644
--- a/src/database/mongo/sorted.js
+++ b/src/database/mongo/sorted.js
@@ -95,7 +95,9 @@ module.exports = function (module) {
const batch = require('../../batch');
const batchSize = Math.ceil(key.length / Math.ceil(key.length / 100));
await batch.processArray(key, async currentBatch => batches.push(currentBatch), { batch: batchSize });
- const batchData = await Promise.all(batches.map(batch => doQuery({ $in: batch }, { _id: 0, _key: 0 }, 0, stop + 1)));
+ const batchData = await Promise.all(batches.map(
+ batch => doQuery({ $in: batch }, { _id: 0, _key: 0 }, 0, stop + 1)
+ ));
result = dbHelpers.mergeBatch(batchData, 0, stop, sort);
if (start > 0) {
result = result.slice(start, stop !== -1 ? stop + 1 : undefined);
diff --git a/src/database/mongo/sorted/add.js b/src/database/mongo/sorted/add.js
index 90940e1d1d..13ee427c23 100644
--- a/src/database/mongo/sorted/add.js
+++ b/src/database/mongo/sorted/add.js
@@ -65,7 +65,10 @@ module.exports = function (module) {
const bulk = module.client.collection('objects').initializeUnorderedBulkOp();
for (let i = 0; i < keys.length; i += 1) {
- bulk.find({ _key: keys[i], value: value }).upsert().updateOne({ $set: { score: parseFloat(isArrayOfScores ? scores[i] : scores) } });
+ bulk
+ .find({ _key: keys[i], value: value })
+ .upsert()
+ .updateOne({ $set: { score: parseFloat(isArrayOfScores ? scores[i] : scores) } });
}
await bulk.execute();
};
diff --git a/src/groups/posts.js b/src/groups/posts.js
index ed97f9635a..58d6831cfe 100644
--- a/src/groups/posts.js
+++ b/src/groups/posts.js
@@ -16,9 +16,10 @@ module.exports = function (Groups) {
// Only process those groups that have the cid in its memberPostCids setting (or no setting at all)
const groupData = await groups.getGroupsFields(groupNames, ['memberPostCids']);
- groupNames = groupNames.filter(
- (groupName, idx) => !groupData[idx].memberPostCidsArray.length || groupData[idx].memberPostCidsArray.includes(postData.cid)
- );
+ groupNames = groupNames.filter((groupName, idx) => (
+ !groupData[idx].memberPostCidsArray.length ||
+ groupData[idx].memberPostCidsArray.includes(postData.cid)
+ ));
const keys = groupNames.map(groupName => `group:${groupName}:member:pids`);
await db.sortedSetsAdd(keys, postData.timestamp, postData.pid);
diff --git a/src/install.js b/src/install.js
index 41afe5e27d..36843d1881 100644
--- a/src/install.js
+++ b/src/install.js
@@ -129,7 +129,13 @@ async function setupConfig() {
const redisQuestions = require('./database/redis').questions;
const mongoQuestions = require('./database/mongo').questions;
const postgresQuestions = require('./database/postgres').questions;
- const allQuestions = questions.main.concat(questions.optional).concat(redisQuestions).concat(mongoQuestions).concat(postgresQuestions);
+ const allQuestions = [
+ ...questions.main,
+ ...questions.optional,
+ ...redisQuestions,
+ ...mongoQuestions,
+ ...postgresQuestions,
+ ];
allQuestions.forEach((question) => {
if (install.values.hasOwnProperty(question.name)) {
@@ -307,7 +313,8 @@ async function createAdmin() {
const results = await promptGet(questions);
return await success(results);
}
- // If automated setup did not provide a user password, generate one, it will be shown to the user upon setup completion
+ // If automated setup did not provide a user password, generate one,
+ // it will be shown to the user upon setup completion
if (!install.values.hasOwnProperty('admin:password') && !nconf.get('admin:password')) {
console.log('Password was not provided during automated setup, generating one...');
password = utils.generateUUID().slice(0, 8);
diff --git a/src/messaging/data.js b/src/messaging/data.js
index 9391c5c4a7..de0742f528 100644
--- a/src/messaging/data.js
+++ b/src/messaging/data.js
@@ -20,7 +20,9 @@ module.exports = function (Messaging) {
const keys = mids.map(mid => `message:${mid}`);
const messages = await (fields.length ? db.getObjectsFields(keys, fields) : db.getObjects(keys));
- return await Promise.all(messages.map(async (message, idx) => modifyMessage(message, fields, parseInt(mids[idx], 10))));
+ return await Promise.all(messages.map(
+ async (message, idx) => modifyMessage(message, fields, parseInt(mids[idx], 10))
+ ));
};
Messaging.getMessageField = async (mid, field) => {
diff --git a/src/middleware/expose.js b/src/middleware/expose.js
index a9532506f8..3642465c01 100644
--- a/src/middleware/expose.js
+++ b/src/middleware/expose.js
@@ -41,7 +41,10 @@ module.exports = function (middleware) {
middleware.exposePrivilegeSet = async (req, res, next) => {
// Exposes a user's global/admin privilege set
- res.locals.privileges = { ...await privileges.global.get(req.user.uid), ...await privileges.admin.get(req.user.uid) };
+ res.locals.privileges = {
+ ...await privileges.global.get(req.user.uid),
+ ...await privileges.admin.get(req.user.uid),
+ };
return next();
};
};
diff --git a/src/notifications.js b/src/notifications.js
index 7b1be349e5..332301cebc 100644
--- a/src/notifications.js
+++ b/src/notifications.js
@@ -118,7 +118,11 @@ Notifications.create = async function (data) {
}
data.importance = data.importance || 5;
const oldNotif = await db.getObject(`notifications:${data.nid}`);
- if (oldNotif && parseInt(oldNotif.pid, 10) === parseInt(data.pid, 10) && parseInt(oldNotif.importance, 10) > parseInt(data.importance, 10)) {
+ if (
+ oldNotif &&
+ parseInt(oldNotif.pid, 10) === parseInt(data.pid, 10) &&
+ parseInt(oldNotif.importance, 10) > parseInt(data.importance, 10)
+ ) {
return null;
}
const now = Date.now();
diff --git a/src/posts/parse.js b/src/posts/parse.js
index 2f47ff140a..944c1c2125 100644
--- a/src/posts/parse.js
+++ b/src/posts/parse.js
@@ -94,7 +94,9 @@ module.exports = function (Posts) {
absolute = `//${current[1]}`;
}
- content = content.slice(0, current.index + regex.length) + absolute + content.slice(current.index + regex.length + current[1].length);
+ content = content.slice(0, current.index + regex.length) +
+ absolute +
+ content.slice(current.index + regex.length + current[1].length);
}
} catch (err) {
winston.verbose(err.messsage);
@@ -117,7 +119,10 @@ module.exports = function (Posts) {
Posts.configureSanitize = async () => {
// Each allowed tags should have some common global attributes...
sanitizeConfig.allowedTags.forEach((tag) => {
- sanitizeConfig.allowedAttributes[tag] = _.union(sanitizeConfig.allowedAttributes[tag], sanitizeConfig.globalAttributes);
+ sanitizeConfig.allowedAttributes[tag] = _.union(
+ sanitizeConfig.allowedAttributes[tag],
+ sanitizeConfig.globalAttributes
+ );
});
// Some plugins might need to adjust or whitelist their own tags...
diff --git a/src/posts/summary.js b/src/posts/summary.js
index a88c61c109..93fbc5fee6 100644
--- a/src/posts/summary.js
+++ b/src/posts/summary.js
@@ -39,7 +39,8 @@ module.exports = function (Posts) {
const cidToCategory = toObject('cid', topicsAndCategories.categories);
posts.forEach((post) => {
- // If the post author isn't represented in the retrieved users' data, then it means they were deleted, assume guest.
+ // If the post author isn't represented in the retrieved users' data,
+ // then it means they were deleted, assume guest.
if (!uidToUser.hasOwnProperty(post.uid)) {
post.uid = 0;
}
diff --git a/src/privileges/posts.js b/src/privileges/posts.js
index b6120f15f2..68842a3992 100644
--- a/src/privileges/posts.js
+++ b/src/privileges/posts.js
@@ -94,8 +94,11 @@ module.exports = function (privileges) {
const cidsSet = new Set(allowedCids);
const canViewDeleted = _.zipObject(cids, results.view_deleted);
- pids = postData.filter(post => post.topic && cidsSet.has(post.topic.cid) &&
- ((!post.topic.deleted && !post.deleted) || canViewDeleted[post.topic.cid] || results.isAdmin)).map(post => post.pid);
+ pids = postData.filter(post => (
+ post.topic &&
+ cidsSet.has(post.topic.cid) &&
+ ((!post.topic.deleted && !post.deleted) || canViewDeleted[post.topic.cid] || results.isAdmin)
+ )).map(post => post.pid);
const data = await plugins.hooks.fire('filter:privileges.posts.filter', {
privilege: privilege,
@@ -121,10 +124,19 @@ module.exports = function (privileges) {
return { flag: true };
}
- if (!results.isMod && meta.config.postEditDuration && (Date.now() - results.postData.timestamp > meta.config.postEditDuration * 1000)) {
+ if (
+ !results.isMod &&
+ meta.config.postEditDuration &&
+ (Date.now() - results.postData.timestamp > meta.config.postEditDuration * 1000)
+ ) {
return { flag: false, message: `[[error:post-edit-duration-expired, ${meta.config.postEditDuration}]]` };
}
- if (!results.isMod && meta.config.newbiePostEditDuration > 0 && meta.config.newbiePostDelayThreshold > results.userData.reputation && Date.now() - results.postData.timestamp > meta.config.newbiePostEditDuration * 1000) {
+ if (
+ !results.isMod &&
+ meta.config.newbiePostEditDuration > 0 &&
+ meta.config.newbiePostDelayThreshold > results.userData.reputation &&
+ Date.now() - results.postData.timestamp > meta.config.newbiePostEditDuration * 1000
+ ) {
return { flag: false, message: `[[error:post-edit-duration-expired, ${meta.config.newbiePostEditDuration}]]` };
}
diff --git a/src/privileges/topics.js b/src/privileges/topics.js
index c3e53136e1..5524b12bb0 100644
--- a/src/privileges/topics.js
+++ b/src/privileges/topics.js
@@ -71,12 +71,18 @@ module.exports = function (privileges) {
const cids = _.uniq(topicsData.map(topic => topic.cid));
const results = await privileges.categories.getBase(privilege, cids, uid);
- const allowedCids = cids.filter((cid, index) => !results.categories[index].disabled && (results.allowedTo[index] || results.isAdmin));
+ const allowedCids = cids.filter((cid, index) => (
+ !results.categories[index].disabled &&
+ (results.allowedTo[index] || results.isAdmin)
+ ));
const cidsSet = new Set(allowedCids);
const canViewDeleted = _.zipObject(cids, results.view_deleted);
- tids = topicsData.filter(t => cidsSet.has(t.cid) && (!t.deleted || canViewDeleted[t.cid] || results.isAdmin)).map(t => t.tid);
+ tids = topicsData.filter(t => (
+ cidsSet.has(t.cid) &&
+ (!t.deleted || canViewDeleted[t.cid] || results.isAdmin)
+ )).map(t => t.tid);
const data = await plugins.hooks.fire('filter:privileges.topics.filter', {
privilege: privilege,
diff --git a/src/routes/feeds.js b/src/routes/feeds.js
index 0869636695..9be9acf366 100644
--- a/src/routes/feeds.js
+++ b/src/routes/feeds.js
@@ -97,7 +97,9 @@ async function generateForTopic(req, res) {
const replies = topicData.posts.slice(1);
replies.forEach((postData) => {
if (!postData.deleted) {
- const dateStamp = new Date(parseInt(parseInt(postData.edited, 10) === 0 ? postData.timestamp : postData.edited, 10)).toUTCString();
+ const dateStamp = new Date(
+ parseInt(parseInt(postData.edited, 10) === 0 ? postData.timestamp : postData.edited, 10)
+ ).toUTCString();
feed.item({
title: `Reply to ${utils.stripHTMLTags(topicData.title, utils.tags)} on ${dateStamp}`,
diff --git a/src/routes/helpers.js b/src/routes/helpers.js
index 7b9ee0c623..a1133738a7 100644
--- a/src/routes/helpers.js
+++ b/src/routes/helpers.js
@@ -11,7 +11,14 @@ helpers.setupPageRoute = function (router, name, middleware, middlewares, contro
middleware.pluginHooks,
].concat(middlewares);
- router.get(name, middleware.busyCheck, middleware.applyCSRF, middleware.buildHeader, middlewares, helpers.tryRoute(controller));
+ router.get(
+ name,
+ middleware.busyCheck,
+ middleware.applyCSRF,
+ middleware.buildHeader,
+ middlewares,
+ helpers.tryRoute(controller)
+ );
router.get(`/api${name}`, middlewares, helpers.tryRoute(controller));
};
diff --git a/src/routes/write/files.js b/src/routes/write/files.js
index f4eb603c35..9dd8f0d30d 100644
--- a/src/routes/write/files.js
+++ b/src/routes/write/files.js
@@ -10,8 +10,16 @@ const { setupApiRoute } = routeHelpers;
module.exports = function () {
const middlewares = [middleware.authenticate];
- // setupApiRoute(router, 'put', '/', [...middlewares, middleware.checkRequired.bind(null, ['path']), middleware.assert.folder], controllers.write.files.upload);
- setupApiRoute(router, 'delete', '/', [...middlewares, middleware.checkRequired.bind(null, ['path']), middleware.assert.path], controllers.write.files.delete);
+ // setupApiRoute(router, 'put', '/', [
+ // ...middlewares,
+ // middleware.checkRequired.bind(null, ['path']),
+ // middleware.assert.folder
+ // ], controllers.write.files.upload);
+ setupApiRoute(router, 'delete', '/', [
+ ...middlewares,
+ middleware.checkRequired.bind(null, ['path']),
+ middleware.assert.path,
+ ], controllers.write.files.delete);
return router;
};
diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js
index 79e46cd9cc..60c6f8911d 100644
--- a/src/socket.io/admin.js
+++ b/src/socket.io/admin.js
@@ -42,7 +42,9 @@ SocketAdmin.before = async function (socket, method) {
// Check admin privileges mapping (if not in mapping, deny access)
const privilegeSet = privileges.admin.socketMap.hasOwnProperty(method) ? privileges.admin.socketMap[method].split(';') : [];
- const hasPrivilege = (await Promise.all(privilegeSet.map(async privilege => privileges.admin.can(privilege, socket.uid)))).some(Boolean);
+ const hasPrivilege = (await Promise.all(privilegeSet.map(
+ async privilege => privileges.admin.can(privilege, socket.uid)
+ ))).some(Boolean);
if (privilegeSet.length && hasPrivilege) {
return;
}
diff --git a/src/socket.io/admin/analytics.js b/src/socket.io/admin/analytics.js
index 051b8bb282..6bb80c9df1 100644
--- a/src/socket.io/admin/analytics.js
+++ b/src/socket.io/admin/analytics.js
@@ -41,7 +41,8 @@ Analytics.get = function (socket, data, callback) {
},
}, (err, data) => {
data.pastDay = data.pageviews.reduce((a, b) => parseInt(a, 10) + parseInt(b, 10));
- data.pageviews[data.pageviews.length - 1] = parseInt(data.pageviews[data.pageviews.length - 1], 10) + analytics.getUnwrittenPageviews();
+ const last = data.pageviews.length - 1;
+ data.pageviews[last] = parseInt(data.pageviews[last], 10) + analytics.getUnwrittenPageviews();
callback(err, data);
});
}
diff --git a/src/socket.io/index.js b/src/socket.io/index.js
index 35e3bf6d26..196ea2ad06 100644
--- a/src/socket.io/index.js
+++ b/src/socket.io/index.js
@@ -185,7 +185,9 @@ async function checkMaintenance(socket) {
throw new Error(`[[pages:maintenance.text, ${validator.escape(String(meta.config.title || 'NodeBB'))}]]`);
}
-const getSessionAsync = util.promisify((sid, callback) => db.sessionStore.get(sid, (err, sessionObj) => callback(err, sessionObj || null)));
+const getSessionAsync = util.promisify(
+ (sid, callback) => db.sessionStore.get(sid, (err, sessionObj) => callback(err, sessionObj || null))
+);
async function validateSession(socket) {
const req = socket.request;
diff --git a/src/socket.io/topics/infinitescroll.js b/src/socket.io/topics/infinitescroll.js
index 7723011b85..a46ea8d19f 100644
--- a/src/socket.io/topics/infinitescroll.js
+++ b/src/socket.io/topics/infinitescroll.js
@@ -26,7 +26,10 @@ module.exports = function (SocketTopics) {
const reverse = data.topicPostSort === 'newest_to_oldest' || data.topicPostSort === 'most_votes';
let start = Math.max(0, parseInt(data.after, 10));
- const infScrollPostsPerPage = Math.max(0, Math.min(meta.config.postsPerPage || 20, parseInt(data.count, 10) || meta.config.postsPerPage || 20));
+ const infScrollPostsPerPage = Math.max(0, Math.min(
+ meta.config.postsPerPage || 20,
+ parseInt(data.count, 10) || meta.config.postsPerPage || 20
+ ));
if (data.direction === -1) {
start -= (infScrollPostsPerPage + 1);
@@ -96,7 +99,10 @@ module.exports = function (SocketTopics) {
};
function calculateStartStop(data) {
- const itemsPerPage = Math.min(meta.config.topicsPerPage || 20, parseInt(data.count, 10) || meta.config.topicsPerPage || 20);
+ const itemsPerPage = Math.min(
+ meta.config.topicsPerPage || 20,
+ parseInt(data.count, 10) || meta.config.topicsPerPage || 20
+ );
let start = Math.max(0, parseInt(data.after, 10));
if (data.direction === -1) {
start -= itemsPerPage;
diff --git a/src/topics/events.js b/src/topics/events.js
index de7add9589..f93329bade 100644
--- a/src/topics/events.js
+++ b/src/topics/events.js
@@ -12,7 +12,8 @@ const Events = module.exports;
* You are able to define additional topic event types here.
* Register to hook `filter:topicEvents.init` and append your custom type to the `types` object.
* You can then log a custom topic event by calling `topics.events.log(tid, { type, uid });`
- * `uid` is optional; if you pass in a valid uid in the payload, the user avatar/username will be rendered as part of the event text
+ * `uid` is optional; if you pass in a valid uid in the payload,
+ * the user avatar/username will be rendered as part of the event text
*
*/
Events._types = {
diff --git a/src/topics/sorted.js b/src/topics/sorted.js
index c69e4c2585..ce08c48ecf 100644
--- a/src/topics/sorted.js
+++ b/src/topics/sorted.js
@@ -151,7 +151,12 @@ module.exports = function (Topics) {
topicData = filtered;
const cids = params.cids && params.cids.map(String);
- tids = topicData.filter(t => t && t.cid && !isCidIgnored[t.cid] && (!cids || cids.includes(String(t.cid)))).map(t => t.tid);
+ tids = topicData.filter(t => (
+ t &&
+ t.cid &&
+ !isCidIgnored[t.cid] &&
+ (!cids || cids.includes(String(t.cid)))
+ )).map(t => t.tid);
const result = await plugins.hooks.fire('filter:topics.filterSortedTids', { tids: tids, params: params });
return result.tids;
diff --git a/src/topics/teaser.js b/src/topics/teaser.js
index 0583818662..24e6d5d775 100644
--- a/src/topics/teaser.js
+++ b/src/topics/teaser.js
@@ -56,7 +56,8 @@ module.exports = function (Topics) {
users[user.uid] = user;
});
postData.forEach((post) => {
- // If the post author isn't represented in the retrieved users' data, then it means they were deleted, assume guest.
+ // If the post author isn't represented in the retrieved users' data,
+ // then it means they were deleted, assume guest.
if (!users.hasOwnProperty(post.uid)) {
post.uid = 0;
}
diff --git a/src/upgrades/1.10.2/upgrade_bans_to_hashes.js b/src/upgrades/1.10.2/upgrade_bans_to_hashes.js
index 0234915c63..24a2cd8cc0 100644
--- a/src/upgrades/1.10.2/upgrade_bans_to_hashes.js
+++ b/src/upgrades/1.10.2/upgrade_bans_to_hashes.js
@@ -47,7 +47,12 @@ module.exports = {
// has no history, but is banned, create plain object with just uid and timestmap
if (!results.bans.length && parseInt(results.userData.banned, 10)) {
- const banTimestamp = results.userData.lastonline || results.userData.lastposttime || results.userData.joindate || Date.now();
+ const banTimestamp = (
+ results.userData.lastonline ||
+ results.userData.lastposttime ||
+ results.userData.joindate ||
+ Date.now()
+ );
const banKey = `uid:${uid}:ban:${banTimestamp}`;
addBan(banKey, { uid: uid, timestamp: banTimestamp }, next);
return;
diff --git a/src/user/auth.js b/src/user/auth.js
index 21a050480f..5ec8ab2030 100644
--- a/src/user/auth.js
+++ b/src/user/auth.js
@@ -62,8 +62,12 @@ module.exports = function (User) {
]);
};
- const getSessionFromStore = util.promisify((sid, callback) => db.sessionStore.get(sid, (err, sessObj) => callback(err, sessObj || null)));
- const sessionStoreDestroy = util.promisify((sid, callback) => db.sessionStore.destroy(sid, err => callback(err)));
+ const getSessionFromStore = util.promisify(
+ (sid, callback) => db.sessionStore.get(sid, (err, sessObj) => callback(err, sessObj || null))
+ );
+ const sessionStoreDestroy = util.promisify(
+ (sid, callback) => db.sessionStore.destroy(sid, err => callback(err))
+ );
User.auth.getSessions = async function (uid, curSessionId) {
await cleanExpiredSessions(uid);
diff --git a/src/user/jobs/export-profile.js b/src/user/jobs/export-profile.js
index 4578d6bc23..49c18550ca 100644
--- a/src/user/jobs/export-profile.js
+++ b/src/user/jobs/export-profile.js
@@ -33,7 +33,19 @@ process.on('message', async (msg) => {
const profilePath = path.join(__dirname, '../../../build/export', profileFile);
const user = require('../index');
- const [userData, userSettings, ips, sessions, usernames, emails, bookmarks, watchedTopics, upvoted, downvoted, following] = await Promise.all([
+ const [
+ userData,
+ userSettings,
+ ips,
+ sessions,
+ usernames,
+ emails,
+ bookmarks,
+ watchedTopics,
+ upvoted,
+ downvoted,
+ following,
+ ] = await Promise.all([
db.getObject(`user:${targetUid}`),
db.getObject(`user:${targetUid}:settings`),
user.getIPs(targetUid, 9),
diff --git a/src/user/posts.js b/src/user/posts.js
index b0d1b6d5cc..8537f7114d 100644
--- a/src/user/posts.js
+++ b/src/user/posts.js
@@ -41,7 +41,11 @@ module.exports = function (User) {
const lasttime = userData[field] || 0;
- if (meta.config.newbiePostDelay > 0 && meta.config.newbiePostDelayThreshold > userData.reputation && now - lasttime < meta.config.newbiePostDelay * 1000) {
+ if (
+ meta.config.newbiePostDelay > 0 &&
+ meta.config.newbiePostDelayThreshold > userData.reputation &&
+ now - lasttime < meta.config.newbiePostDelay * 1000
+ ) {
throw new Error(`[[error:too-many-posts-newbie, ${meta.config.newbiePostDelay}, ${meta.config.newbiePostDelayThreshold}]]`);
} else if (now - lasttime < meta.config.postDelay * 1000) {
throw new Error(`[[error:too-many-posts, ${meta.config.postDelay}]]`);
diff --git a/src/user/settings.js b/src/user/settings.js
index 490282e46f..4e657a605d 100644
--- a/src/user/settings.js
+++ b/src/user/settings.js
@@ -47,16 +47,16 @@ module.exports = function (User) {
settings.openOutgoingLinksInNewTab = parseInt(getSetting(settings, 'openOutgoingLinksInNewTab', 0), 10) === 1;
settings.dailyDigestFreq = getSetting(settings, 'dailyDigestFreq', 'off');
settings.usePagination = parseInt(getSetting(settings, 'usePagination', 0), 10) === 1;
- settings.topicsPerPage =
- Math.min(
- meta.config.maxTopicsPerPage,
- Math.min(settings.topicsPerPage ? parseInt(settings.topicsPerPage, 10) : defaultTopicsPerPage, defaultTopicsPerPage)
- );
- settings.postsPerPage =
- Math.min(
- meta.config.maxPostsPerPage,
- Math.min(settings.postsPerPage ? parseInt(settings.postsPerPage, 10) : defaultPostsPerPage, defaultPostsPerPage)
- );
+ settings.topicsPerPage = Math.min(
+ meta.config.maxTopicsPerPage,
+ settings.topicsPerPage ? parseInt(settings.topicsPerPage, 10) : defaultTopicsPerPage,
+ defaultTopicsPerPage
+ );
+ settings.postsPerPage = Math.min(
+ meta.config.maxPostsPerPage,
+ settings.postsPerPage ? parseInt(settings.postsPerPage, 10) : defaultPostsPerPage,
+ defaultPostsPerPage
+ );
settings.userLang = settings.userLang || meta.config.defaultLang || 'en-GB';
settings.acpLang = settings.acpLang || settings.userLang;
settings.topicPostSort = getSetting(settings, 'topicPostSort', 'oldest_to_newest');
@@ -91,12 +91,20 @@ module.exports = function (User) {
User.saveSettings = async function (uid, data) {
const maxPostsPerPage = meta.config.maxPostsPerPage || 20;
- if (!data.postsPerPage || parseInt(data.postsPerPage, 10) <= 1 || parseInt(data.postsPerPage, 10) > maxPostsPerPage) {
+ if (
+ !data.postsPerPage ||
+ parseInt(data.postsPerPage, 10) <= 1 ||
+ parseInt(data.postsPerPage, 10) > maxPostsPerPage
+ ) {
throw new Error(`[[error:invalid-pagination-value, 2, ${maxPostsPerPage}]]`);
}
const maxTopicsPerPage = meta.config.maxTopicsPerPage || 20;
- if (!data.topicsPerPage || parseInt(data.topicsPerPage, 10) <= 1 || parseInt(data.topicsPerPage, 10) > maxTopicsPerPage) {
+ if (
+ !data.topicsPerPage ||
+ parseInt(data.topicsPerPage, 10) <= 1 ||
+ parseInt(data.topicsPerPage, 10) > maxTopicsPerPage
+ ) {
throw new Error(`[[error:invalid-pagination-value, 2, ${maxTopicsPerPage}]]`);
}
diff --git a/test/api.js b/test/api.js
index e3623412b0..0d5b3fe5ee 100644
--- a/test/api.js
+++ b/test/api.js
@@ -286,7 +286,8 @@ describe('API', async () => {
generateTests(writeApi, Object.keys(writeApi.paths), writeApi.servers[0].url);
function generateTests(api, paths, prefix) {
- // Iterate through all documented paths, make a call to it, and compare the result body with what is defined in the spec
+ // Iterate through all documented paths, make a call to it,
+ // and compare the result body with what is defined in the spec
const pathLib = path; // for calling path module from inside this forEach
paths.forEach((path) => {
const context = api.paths[path];
diff --git a/test/categories.js b/test/categories.js
index b690c7dfb5..dc5b7cda4d 100644
--- a/test/categories.js
+++ b/test/categories.js
@@ -545,7 +545,11 @@ describe('Categories', () => {
},
function (category, next) {
child1Cid = category.cid;
- socketCategories.copySettingsFrom({ uid: adminUid }, { fromCid: parentCid, toCid: child1Cid, copyParent: true }, next);
+ socketCategories.copySettingsFrom(
+ { uid: adminUid },
+ { fromCid: parentCid, toCid: child1Cid, copyParent: true },
+ next
+ );
},
function (destinationCategory, next) {
Categories.getCategoryField(child1Cid, 'description', next);
diff --git a/test/messaging.js b/test/messaging.js
index c3223c980e..ecec16026c 100644
--- a/test/messaging.js
+++ b/test/messaging.js
@@ -224,7 +224,10 @@ describe('Messaging Library', () => {
it('should send not a user-leave system message when a user tries to leave a room they are not in', async () => {
await socketModules.chats.leave({ uid: bazUid }, roomId);
- const messages = await socketModules.chats.getMessages({ uid: fooUid }, { uid: fooUid, roomId: roomId, start: 0 });
+ const messages = await socketModules.chats.getMessages(
+ { uid: fooUid },
+ { uid: fooUid, roomId: roomId, start: 0 }
+ );
assert.equal(messages.length, 4);
const message = messages.pop();
assert.strictEqual(message.system, true);
diff --git a/test/posts.js b/test/posts.js
index de431a2b44..3f188b1ea4 100644
--- a/test/posts.js
+++ b/test/posts.js
@@ -446,7 +446,10 @@ describe('Post\'s', () => {
it('should purge posts and purge topic', (done) => {
createTopicWithReply((topicPostData, replyData) => {
- socketPosts.purgePosts({ uid: voterUid }, { pids: [replyData.pid, topicPostData.postData.pid], tid: topicPostData.topicData.tid }, (err) => {
+ socketPosts.purgePosts({ uid: voterUid }, {
+ pids: [replyData.pid, topicPostData.postData.pid],
+ tid: topicPostData.topicData.tid,
+ }, (err) => {
assert.ifError(err);
posts.exists(`post:${replyData.pid}`, (err, exists) => {
assert.ifError(err);
diff --git a/test/topics.js b/test/topics.js
index ae3899af5f..8e7109f4b4 100644
--- a/test/topics.js
+++ b/test/topics.js
@@ -58,7 +58,12 @@ describe('Topic\'s', () => {
});
it('should create a new topic with proper parameters', (done) => {
- topics.post({ uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId }, (err, result) => {
+ topics.post({
+ uid: topic.userId,
+ title: topic.title,
+ content: topic.content,
+ cid: topic.categoryId,
+ }, (err, result) => {
assert.ifError(err);
assert(result);
topic.tid = result.topicData.tid;
@@ -170,7 +175,12 @@ describe('Topic\'s', () => {
let newPost;
before((done) => {
- topics.post({ uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId }, (err, result) => {
+ topics.post({
+ uid: topic.userId,
+ title: topic.title,
+ content: topic.content,
+ cid: topic.categoryId,
+ }, (err, result) => {
if (err) {
return done(err);
}
@@ -265,7 +275,12 @@ describe('Topic\'s', () => {
let newPost;
before((done) => {
- topics.post({ uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId }, (err, result) => {
+ topics.post({
+ uid: topic.userId,
+ title: topic.title,
+ content: topic.content,
+ cid: topic.categoryId,
+ }, (err, result) => {
if (err) {
return done(err);
}
@@ -471,7 +486,12 @@ describe('Topic\'s', () => {
before((done) => {
async.waterfall([
function (next) {
- topics.post({ uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId }, (err, result) => {
+ topics.post({
+ uid: topic.userId,
+ title: topic.title,
+ content: topic.content,
+ cid: topic.categoryId,
+ }, (err, result) => {
assert.ifError(err);
newTopic = result.topicData;
next();
@@ -985,7 +1005,12 @@ describe('Topic\'s', () => {
groups.join('administrators', topic.userId, next);
},
function (next) {
- topics.post({ uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId }, (err, result) => {
+ topics.post({
+ uid: topic.userId,
+ title: topic.title,
+ content: topic.content,
+ cid: topic.categoryId,
+ }, (err, result) => {
assert.ifError(err);
newTopic = result.topicData;
next();
@@ -1276,7 +1301,12 @@ describe('Topic\'s', () => {
const socketTopics = require('../src/socket.io/topics');
let tid;
before((done) => {
- topics.post({ uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId }, (err, result) => {
+ topics.post({
+ uid: topic.userId,
+ title: topic.title,
+ content: topic.content,
+ cid: topic.categoryId,
+ }, (err, result) => {
assert.ifError(err);
tid = result.topicData.tid;
done();
diff --git a/test/uploads.js b/test/uploads.js
index 9f3177e005..57be8c9d97 100644
--- a/test/uploads.js
+++ b/test/uploads.js
@@ -196,36 +196,51 @@ describe('Upload Controllers', () => {
});
// it('should fail if topic thumbs are disabled', function (done) {
- // helpers.uploadFile(nconf.get('url') + '/api/topic/thumb/upload', path.join(__dirname, '../test/files/test.png'), {}, jar, csrf_token, function (err, res, body) {
- // assert.ifError(err);
- // assert.strictEqual(res.statusCode, 404);
- // console.log(body);
- // assert(body && body.status && body.status.code);
- // assert.strictEqual(body.status.code, '[[error:topic-thumbnails-are-disabled]]');
- // done();
- // });
+ // helpers.uploadFile(
+ // nconf.get('url') + '/api/topic/thumb/upload',
+ // path.join(__dirname, '../test/files/test.png'),
+ // {}, jar, csrf_token,
+ // function (err, res, body) {
+ // assert.ifError(err);
+ // assert.strictEqual(res.statusCode, 404);
+ // console.log(body);
+ // assert(body && body.status && body.status.code);
+ // assert.strictEqual(body.status.code, '[[error:topic-thumbnails-are-disabled]]');
+ // done();
+ // }
+ // );
// });
// it('should fail if file is not image', function (done) {
// meta.config.allowTopicsThumbnail = 1;
- // helpers.uploadFile(nconf.get('url') + '/api/topic/thumb/upload', path.join(__dirname, '../test/files/503.html'), {}, jar, csrf_token, function (err, res, body) {
- // assert.ifError(err);
- // assert.equal(res.statusCode, 500);
- // assert.equal(body.error, '[[error:invalid-file]]');
- // done();
- // });
+ // helpers.uploadFile(
+ // nconf.get('url') + '/api/topic/thumb/upload',
+ // path.join(__dirname, '../test/files/503.html'),
+ // {}, jar, csrf_token,
+ // function (err, res, body) {
+ // assert.ifError(err);
+ // assert.equal(res.statusCode, 500);
+ // assert.equal(body.error, '[[error:invalid-file]]');
+ // done();
+ // }
+ // );
// });
// it('should upload topic thumb', function (done) {
// meta.config.allowTopicsThumbnail = 1;
- // helpers.uploadFile(nconf.get('url') + '/api/topic/thumb/upload', path.join(__dirname, '../test/files/test.png'), {}, jar, csrf_token, function (err, res, body) {
- // assert.ifError(err);
- // assert.equal(res.statusCode, 200);
- // assert(Array.isArray(body));
- // assert(body[0].path);
- // assert(body[0].url);
- // done();
- // });
+ // helpers.uploadFile(
+ // nconf.get('url') + '/api/topic/thumb/upload',
+ // path.join(__dirname, '../test/files/test.png'),
+ // {}, jar, csrf_token,
+ // function (err, res, body) {
+ // assert.ifError(err);
+ // assert.equal(res.statusCode, 200);
+ // assert(Array.isArray(body));
+ // assert(body[0].path);
+ // assert(body[0].url);
+ // done();
+ // }
+ // );
// });
it('should not allow non image uploads', (done) => {