mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 16:35:47 +01:00
Merge branch 'develop' into chat-rewrite
This commit is contained in:
@@ -3,9 +3,9 @@
|
||||
"enable": "Paginuj tematy oraz posty zamiast używać nieskończonego przewijania",
|
||||
"topics": "Paginacja tematów",
|
||||
"posts-per-page": "Postów na stronie",
|
||||
"max-posts-per-page": "Maximum posts per page",
|
||||
"max-posts-per-page": "Maksymalna liczba postów na stronę",
|
||||
"categories": "Paginacja kategorii",
|
||||
"topics-per-page": "Tematów na stronę",
|
||||
"max-topics-per-page": "Maximum topics per page",
|
||||
"max-topics-per-page": "Maksymalna liczba tematów na stronę",
|
||||
"initial-num-load": "Początkowa liczba pozycji do załadowania w Nieprzeczytanych, Ostatnich oraz Popularnych tematów"
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
"sorting.oldest-to-newest": "Najstarsze do najnowszych",
|
||||
"sorting.newest-to-oldest": "Najnowsze do najstarszych",
|
||||
"sorting.most-votes": "Najwięcej głosów",
|
||||
"sorting.most-posts": "Most Posts",
|
||||
"sorting.most-posts": "Najwięcej postów",
|
||||
"sorting.topic-default": "Domyślne sortowanie tematów",
|
||||
"restrictions": "Ograniczenia pisania",
|
||||
"restrictions.post-queue": "Włącz kolejkę postów",
|
||||
|
||||
@@ -10,6 +10,6 @@
|
||||
"all-topics": "Wszystkie tematy",
|
||||
"new-topics": "Nowe tematy",
|
||||
"watched-topics": "Obserwowane tematy",
|
||||
"unreplied-topics": "Unreplied Topics",
|
||||
"multiple-categories-selected": "Multiple Selected"
|
||||
"unreplied-topics": "Tematy bez odpowiedzi",
|
||||
"multiple-categories-selected": "Kilka zaznaczonych"
|
||||
}
|
||||
@@ -75,6 +75,7 @@ define('forum/footer', ['notifications', 'chat', 'components', 'translator'], fu
|
||||
socket.on('event:new_post', onNewPost);
|
||||
}
|
||||
|
||||
// DEPRECATED: remove in 1.8.0
|
||||
if (app.user.uid) {
|
||||
socket.emit('user.getUnreadCounts', function (err, data) {
|
||||
if (err) {
|
||||
|
||||
@@ -157,7 +157,7 @@ define('forum/topic', [
|
||||
components.get('topic').on('click', '[component="post/parent"]', function (e) {
|
||||
var toPid = $(this).attr('data-topid');
|
||||
|
||||
var toPost = $('[component="post"][data-pid="' + toPid + '"]');
|
||||
var toPost = $('[component="topic"]>[component="post"][data-pid="' + toPid + '"]');
|
||||
if (toPost.length) {
|
||||
e.preventDefault();
|
||||
navigator.scrollToIndex(toPost.attr('data-index'), true);
|
||||
|
||||
@@ -137,16 +137,16 @@ define('notifications', ['sounds', 'translator', 'components', 'navigator', 'ben
|
||||
return parseInt(a.datetime, 10) > parseInt(b.datetime, 10) ? -1 : 1;
|
||||
});
|
||||
|
||||
translator.toggleTimeagoShorthand();
|
||||
translator.toggleTimeagoShorthand(function () {
|
||||
for (var i = 0; i < notifs.length; i += 1) {
|
||||
notifs[i].timeago = $.timeago(new Date(parseInt(notifs[i].datetime, 10)));
|
||||
}
|
||||
translator.toggleTimeagoShorthand();
|
||||
|
||||
Benchpress.parse('partials/notifications_list', { notifications: notifs }, function (html) {
|
||||
notifList.translateHtml(html);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Notifications.updateNotifCount = function (count) {
|
||||
|
||||
@@ -576,23 +576,29 @@
|
||||
adaptor.getTranslations(language, namespace, callback);
|
||||
},
|
||||
|
||||
toggleTimeagoShorthand: function toggleTimeagoShorthand() {
|
||||
toggleTimeagoShorthand: function toggleTimeagoShorthand(callback) {
|
||||
function toggle() {
|
||||
var tmp = assign({}, jQuery.timeago.settings.strings);
|
||||
jQuery.timeago.settings.strings = assign({}, adaptor.timeagoShort);
|
||||
adaptor.timeagoShort = assign({}, tmp);
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
if (!adaptor.timeagoShort) {
|
||||
var languageCode = utils.userLangToTimeagoCode(config.userLang);
|
||||
var originalSettings = assign({}, jQuery.timeago.settings.strings);
|
||||
jQuery.getScript(config.relative_path + '/assets/vendor/jquery/timeago/locales/jquery.timeago.' + languageCode + '-short.js').done(function () {
|
||||
adaptor.timeagoShort = assign({}, jQuery.timeago.settings.strings);
|
||||
jQuery.timeago.settings.strings = assign({}, originalSettings);
|
||||
toggle();
|
||||
});
|
||||
} else {
|
||||
toggle();
|
||||
}
|
||||
},
|
||||
prepareDOM: function prepareDOM() {
|
||||
// Load the appropriate timeago locale file,
|
||||
// and correct NodeBB language codes to timeago codes, if necessary
|
||||
var languageCode = utils.userLangToTimeagoCode(config.userLang);
|
||||
|
||||
adaptor.timeagoShort = assign({}, jQuery.timeago.settings.strings);
|
||||
|
||||
jQuery.getScript(config.relative_path + '/assets/vendor/jquery/timeago/locales/jquery.timeago.' + languageCode + '-short.js').done(function () {
|
||||
// Switch back to long-form
|
||||
adaptor.toggleTimeagoShorthand();
|
||||
});
|
||||
|
||||
// Add directional code if necessary
|
||||
adaptor.translate('[[language:dir]]', function (value) {
|
||||
if (value && !$('html').attr('data-dir')) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
var packageInstall = require('../meta/package-install');
|
||||
var packageInstall = require('./package-install');
|
||||
var dirname = require('./paths').baseDir;
|
||||
|
||||
// check to make sure dependencies are installed
|
||||
@@ -12,12 +12,17 @@ try {
|
||||
} catch (e) {
|
||||
if (e.code === 'ENOENT') {
|
||||
console.warn('package.json not found.');
|
||||
console.log('Populating package.json...\n');
|
||||
console.log('Populating package.json...');
|
||||
|
||||
packageInstall.updatePackageFile();
|
||||
packageInstall.preserveExtraneousPlugins();
|
||||
|
||||
console.log('OK'.green + '\n'.reset);
|
||||
try {
|
||||
require('colors');
|
||||
console.log('OK'.green);
|
||||
} catch (e) {
|
||||
console.log('OK');
|
||||
}
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
@@ -33,7 +38,7 @@ try {
|
||||
console.warn('Dependencies not yet installed.');
|
||||
console.log('Installing them now...\n');
|
||||
|
||||
packageInstall.npmInstallProduction();
|
||||
packageInstall.installAll();
|
||||
|
||||
require('colors');
|
||||
console.log('OK'.green + '\n'.reset);
|
||||
|
||||
@@ -29,14 +29,27 @@ function updatePackageFile() {
|
||||
|
||||
exports.updatePackageFile = updatePackageFile;
|
||||
|
||||
function npmInstallProduction() {
|
||||
cproc.execSync('npm i --production', {
|
||||
function installAll() {
|
||||
process.stdout.write('\n');
|
||||
|
||||
var prod = global.env !== 'development';
|
||||
var command = 'npm install';
|
||||
try {
|
||||
var packageManager = require('nconf').get('package_manager');
|
||||
if (packageManager === 'yarn') {
|
||||
command = 'yarn';
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
cproc.execSync(command + (prod ? ' --production' : ''), {
|
||||
cwd: path.join(__dirname, '../../'),
|
||||
stdio: [0, 1, 2],
|
||||
});
|
||||
}
|
||||
|
||||
exports.npmInstallProduction = npmInstallProduction;
|
||||
exports.installAll = installAll;
|
||||
|
||||
function preserveExtraneousPlugins() {
|
||||
// Skip if `node_modules/` is not found or inaccessible
|
||||
@@ -7,9 +7,18 @@ var cproc = require('child_process');
|
||||
var semver = require('semver');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var nconf = require('nconf');
|
||||
|
||||
var paths = require('./paths');
|
||||
|
||||
var packageManager = nconf.get('package_manager');
|
||||
var packageManagerExecutable = packageManager === 'yarn' ? 'yarn' : 'npm';
|
||||
var packageManagerInstallArgs = packageManager === 'yarn' ? ['add'] : ['install', '--save'];
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
packageManagerExecutable += '.cmd';
|
||||
}
|
||||
|
||||
var dirname = paths.baseDir;
|
||||
|
||||
function getModuleVersions(modules, callback) {
|
||||
@@ -38,58 +47,54 @@ function getInstalledPlugins(callback) {
|
||||
async.parallel({
|
||||
files: async.apply(fs.readdir, path.join(dirname, 'node_modules')),
|
||||
deps: async.apply(fs.readFile, path.join(dirname, 'package.json'), { encoding: 'utf-8' }),
|
||||
bundled: async.apply(fs.readFile, path.join(dirname, 'install/package.json'), { encoding: 'utf-8' }),
|
||||
}, function (err, payload) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var isNbbModule = /^nodebb-(?:plugin|theme|widget|rewards)-[\w-]+$/;
|
||||
var moduleName;
|
||||
var isGitRepo;
|
||||
var checklist;
|
||||
|
||||
payload.files = payload.files.filter(function (file) {
|
||||
return isNbbModule.test(file);
|
||||
});
|
||||
|
||||
try {
|
||||
payload.deps = JSON.parse(payload.deps).dependencies;
|
||||
payload.bundled = [];
|
||||
payload.installed = [];
|
||||
payload.deps = Object.keys(JSON.parse(payload.deps).dependencies);
|
||||
payload.bundled = Object.keys(JSON.parse(payload.bundled).dependencies);
|
||||
} catch (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
for (moduleName in payload.deps) {
|
||||
if (isNbbModule.test(moduleName)) {
|
||||
payload.bundled.push(moduleName);
|
||||
}
|
||||
}
|
||||
payload.bundled = payload.bundled.filter(function (pkgName) {
|
||||
return isNbbModule.test(pkgName);
|
||||
});
|
||||
payload.deps = payload.deps.filter(function (pkgName) {
|
||||
return isNbbModule.test(pkgName);
|
||||
});
|
||||
|
||||
// Whittle down deps to send back only extraneously installed plugins/themes/etc
|
||||
payload.files.forEach(function (moduleName) {
|
||||
try {
|
||||
fs.accessSync(path.join(dirname, 'node_modules', moduleName, '.git'));
|
||||
isGitRepo = true;
|
||||
} catch (e) {
|
||||
isGitRepo = false;
|
||||
checklist = payload.deps.filter(function (pkgName) {
|
||||
if (payload.bundled.includes(pkgName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
payload.files.indexOf(moduleName) !== -1 && // found in `node_modules/`
|
||||
payload.bundled.indexOf(moduleName) === -1 && // not found in `package.json`
|
||||
!fs.lstatSync(path.join(dirname, 'node_modules', moduleName)).isSymbolicLink() && // is not a symlink
|
||||
!isGitRepo // .git/ does not exist, so it is not a git repository
|
||||
) {
|
||||
payload.installed.push(moduleName);
|
||||
// Ignore git repositories
|
||||
try {
|
||||
fs.accessSync(path.join(dirname, 'node_modules', pkgName, '.git'));
|
||||
return false;
|
||||
} catch (e) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
getModuleVersions(payload.installed, callback);
|
||||
getModuleVersions(checklist, callback);
|
||||
});
|
||||
}
|
||||
|
||||
function getCurrentVersion(callback) {
|
||||
fs.readFile(path.join(dirname, 'package.json'), { encoding: 'utf-8' }, function (err, pkg) {
|
||||
fs.readFile(path.join(dirname, 'install/package.json'), { encoding: 'utf-8' }, function (err, pkg) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -105,19 +110,19 @@ function getCurrentVersion(callback) {
|
||||
|
||||
function checkPlugins(standalone, callback) {
|
||||
if (standalone) {
|
||||
console.log('Checking installed plugins and themes for updates... ');
|
||||
process.stdout.write('Checking installed plugins and themes for updates... ');
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
async.apply(async.parallel, {
|
||||
plugins: async.apply(getInstalledPlugins),
|
||||
version: async.apply(getCurrentVersion),
|
||||
plugins: getInstalledPlugins,
|
||||
version: getCurrentVersion,
|
||||
}),
|
||||
function (payload, next) {
|
||||
var toCheck = Object.keys(payload.plugins);
|
||||
|
||||
if (!toCheck.length) {
|
||||
console.log('OK'.green + ''.reset);
|
||||
process.stdout.write(' OK'.green + ''.reset);
|
||||
return next(null, []); // no extraneous plugins installed
|
||||
}
|
||||
|
||||
@@ -127,10 +132,10 @@ function checkPlugins(standalone, callback) {
|
||||
json: true,
|
||||
}, function (err, res, body) {
|
||||
if (err) {
|
||||
console.log('error'.red + ''.reset);
|
||||
process.stdout.write('error'.red + ''.reset);
|
||||
return next(err);
|
||||
}
|
||||
console.log('OK'.green + ''.reset);
|
||||
process.stdout.write(' OK'.green + ''.reset);
|
||||
|
||||
if (!Array.isArray(body) && toCheck.length === 1) {
|
||||
body = [body];
|
||||
@@ -172,11 +177,10 @@ function upgradePlugins(callback) {
|
||||
}
|
||||
|
||||
if (found && found.length) {
|
||||
console.log('\nA total of ' + String(found.length).bold + ' package(s) can be upgraded:');
|
||||
process.stdout.write('\n\nA total of ' + String(found.length).bold + ' package(s) can be upgraded:\n\n');
|
||||
found.forEach(function (suggestObj) {
|
||||
console.log(' * '.yellow + suggestObj.name.reset + ' (' + suggestObj.current.yellow + ' -> '.reset + suggestObj.suggested.green + ')\n'.reset);
|
||||
process.stdout.write(' * '.yellow + suggestObj.name.reset + ' (' + suggestObj.current.yellow + ' -> '.reset + suggestObj.suggested.green + ')\n'.reset);
|
||||
});
|
||||
console.log('');
|
||||
} else {
|
||||
if (standalone) {
|
||||
console.log('\nAll packages up-to-date!'.green + ''.reset);
|
||||
@@ -190,7 +194,7 @@ function upgradePlugins(callback) {
|
||||
prompt.start();
|
||||
prompt.get({
|
||||
name: 'upgrade',
|
||||
description: 'Proceed with upgrade (y|n)?'.reset,
|
||||
description: '\nProceed with upgrade (y|n)?'.reset,
|
||||
type: 'string',
|
||||
}, function (err, result) {
|
||||
if (err) {
|
||||
@@ -199,15 +203,16 @@ function upgradePlugins(callback) {
|
||||
|
||||
if (['y', 'Y', 'yes', 'YES'].indexOf(result.upgrade) !== -1) {
|
||||
console.log('\nUpgrading packages...');
|
||||
var args = ['i'];
|
||||
found.forEach(function (suggestObj) {
|
||||
args.push(suggestObj.name + '@' + suggestObj.suggested);
|
||||
});
|
||||
var args = packageManagerInstallArgs.concat(found.map(function (suggestObj) {
|
||||
return suggestObj.name + '@' + suggestObj.suggested;
|
||||
}));
|
||||
|
||||
cproc.execFile((process.platform === 'win32') ? 'npm.cmd' : 'npm', args, { stdio: 'ignore' }, callback);
|
||||
cproc.execFile(packageManagerExecutable, args, { stdio: 'ignore' }, function (err) {
|
||||
callback(err, false);
|
||||
});
|
||||
} else {
|
||||
console.log('Package upgrades skipped'.yellow + '. Check for upgrades at any time by running "'.reset + './nodebb upgrade-plugins'.green + '".'.reset);
|
||||
callback();
|
||||
console.log('Package upgrades skipped'.yellow + '. Check for upgrades at any time by running "'.reset + './nodebb upgrade -p'.green + '".'.reset);
|
||||
callback(null, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
var async = require('async');
|
||||
var nconf = require('nconf');
|
||||
|
||||
var packageInstall = require('../meta/package-install');
|
||||
var packageInstall = require('./package-install');
|
||||
var upgrade = require('../upgrade');
|
||||
var build = require('../meta/build');
|
||||
var db = require('../database');
|
||||
@@ -22,7 +22,7 @@ var steps = {
|
||||
install: {
|
||||
message: 'Bringing base dependencies up to date...',
|
||||
handler: function (next) {
|
||||
packageInstall.npmInstallProduction();
|
||||
packageInstall.installAll();
|
||||
next();
|
||||
},
|
||||
},
|
||||
@@ -53,10 +53,12 @@ var steps = {
|
||||
function runSteps(tasks) {
|
||||
tasks = tasks.map(function (key, i) {
|
||||
return function (next) {
|
||||
console.log(((i + 1) + '. ').bold + steps[key].message.yellow);
|
||||
return steps[key].handler(function (err) {
|
||||
process.stdout.write('\n' + ((i + 1) + '. ').bold + steps[key].message.yellow);
|
||||
return steps[key].handler(function (err, inhibitOk) {
|
||||
if (err) { return next(err); }
|
||||
console.log(' OK'.green);
|
||||
if (!inhibitOk) {
|
||||
process.stdout.write(' OK'.green + '\n'.reset);
|
||||
}
|
||||
next();
|
||||
});
|
||||
};
|
||||
@@ -73,7 +75,7 @@ function runSteps(tasks) {
|
||||
var columns = process.stdout.columns;
|
||||
var spaces = columns ? new Array(Math.floor(columns / 2) - (message.length / 2) + 1).join(' ') : ' ';
|
||||
|
||||
console.log('\n' + spaces + message.green.bold + '\n'.reset);
|
||||
console.log('\n\n' + spaces + message.green.bold + '\n'.reset);
|
||||
|
||||
process.exit();
|
||||
});
|
||||
|
||||
@@ -199,14 +199,17 @@ function addTags(categoryData, res) {
|
||||
}
|
||||
|
||||
res.locals.linkTags = [
|
||||
{
|
||||
rel: 'alternate',
|
||||
type: 'application/rss+xml',
|
||||
href: categoryData.rssFeedUrl,
|
||||
},
|
||||
{
|
||||
rel: 'up',
|
||||
href: nconf.get('url'),
|
||||
},
|
||||
];
|
||||
|
||||
if (!categoryData['feeds:disableRSS']) {
|
||||
res.locals.linkTags.push({
|
||||
rel: 'alternate',
|
||||
type: 'application/rss+xml',
|
||||
href: categoryData.rssFeedUrl,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,17 +257,20 @@ function addTags(topicData, req, res) {
|
||||
addOGImageTags(res, topicData, postAtIndex);
|
||||
|
||||
res.locals.linkTags = [
|
||||
{
|
||||
rel: 'alternate',
|
||||
type: 'application/rss+xml',
|
||||
href: topicData.rssFeedUrl,
|
||||
},
|
||||
{
|
||||
rel: 'canonical',
|
||||
href: nconf.get('url') + '/topic/' + topicData.slug,
|
||||
},
|
||||
];
|
||||
|
||||
if (!topicData['feeds:disableRSS']) {
|
||||
res.locals.linkTags.push({
|
||||
rel: 'alternate',
|
||||
type: 'application/rss+xml',
|
||||
href: topicData.rssFeedUrl,
|
||||
});
|
||||
}
|
||||
|
||||
if (topicData.category) {
|
||||
res.locals.linkTags.push({
|
||||
rel: 'up',
|
||||
|
||||
@@ -66,7 +66,7 @@ module.exports = function (db, module) {
|
||||
if (!key) {
|
||||
return callback();
|
||||
}
|
||||
module.getObjectField(key, 'value', callback);
|
||||
module.getObjectField(key, 'data', callback);
|
||||
};
|
||||
|
||||
module.set = function (key, value, callback) {
|
||||
@@ -74,7 +74,7 @@ module.exports = function (db, module) {
|
||||
if (!key) {
|
||||
return callback();
|
||||
}
|
||||
var data = { value: value };
|
||||
var data = { data: value };
|
||||
module.setObject(key, data, callback);
|
||||
};
|
||||
|
||||
@@ -115,7 +115,7 @@ module.exports = function (db, module) {
|
||||
return callback(null, 'set');
|
||||
} else if (keys.length === 3 && data.hasOwnProperty('_key') && data.hasOwnProperty('array')) {
|
||||
return callback(null, 'list');
|
||||
} else if (keys.length === 3 && data.hasOwnProperty('_key') && data.hasOwnProperty('value')) {
|
||||
} else if (keys.length === 3 && data.hasOwnProperty('_key') && data.hasOwnProperty('data')) {
|
||||
return callback(null, 'string');
|
||||
}
|
||||
callback(null, 'hash');
|
||||
|
||||
@@ -240,7 +240,7 @@ module.exports = function (Groups) {
|
||||
old: oldName,
|
||||
new: newName,
|
||||
});
|
||||
|
||||
Groups.resetCache();
|
||||
next();
|
||||
},
|
||||
], next);
|
||||
|
||||
@@ -99,6 +99,8 @@ function beforeBuild(targets, callback) {
|
||||
var plugins = require('../plugins');
|
||||
meta = require('../meta');
|
||||
|
||||
process.stdout.write(' started'.green + '\n'.reset);
|
||||
|
||||
async.series([
|
||||
db.init,
|
||||
meta.themes.setupPaths,
|
||||
@@ -210,7 +212,7 @@ function build(targets, callback) {
|
||||
}
|
||||
|
||||
winston.info('[build] Asset compilation successful. Completed in ' + totalTime + 'sec.');
|
||||
callback();
|
||||
callback(null, true);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ var jsesc = require('jsesc');
|
||||
|
||||
var db = require('../database');
|
||||
var user = require('../user');
|
||||
var topics = require('../topics');
|
||||
var messaging = require('../messaging');
|
||||
var meta = require('../meta');
|
||||
var plugins = require('../plugins');
|
||||
var navigation = require('../navigation');
|
||||
@@ -109,10 +111,16 @@ module.exports = function (middleware) {
|
||||
next(null, translated);
|
||||
});
|
||||
},
|
||||
navigation: async.apply(navigation.get),
|
||||
navigation: navigation.get,
|
||||
tags: async.apply(meta.tags.parse, req, data, res.locals.metaTags, res.locals.linkTags),
|
||||
banned: async.apply(user.isBanned, req.uid),
|
||||
banReason: async.apply(user.getBannedReason, req.uid),
|
||||
|
||||
unreadTopicCount: async.apply(topics.getTotalUnread, req.uid),
|
||||
unreadNewTopicCount: async.apply(topics.getTotalUnread, req.uid, 'new'),
|
||||
unreadWatchedTopicCount: async.apply(topics.getTotalUnread, req.uid, 'watched'),
|
||||
unreadChatCount: async.apply(messaging.getUnreadCount, req.uid),
|
||||
unreadNotificationCount: async.apply(user.notifications.getUnreadCount, req.uid),
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -131,8 +139,45 @@ module.exports = function (middleware) {
|
||||
|
||||
setBootswatchCSS(templateValues, res.locals.config);
|
||||
|
||||
var unreadCount = {
|
||||
topic: results.unreadTopicCount || 0,
|
||||
newTopic: results.unreadNewTopicCount || 0,
|
||||
watchedTopic: results.unreadWatchedTopicCount || 0,
|
||||
chat: results.unreadChatCount || 0,
|
||||
notification: results.unreadNotificationCount || 0,
|
||||
};
|
||||
Object.keys(unreadCount).forEach(function (key) {
|
||||
if (unreadCount[key] > 99) {
|
||||
unreadCount[key] = '99+';
|
||||
}
|
||||
});
|
||||
|
||||
results.navigation = results.navigation.map(function (item) {
|
||||
if (item.originalRoute === '/unread' && results.unreadTopicCount > 0) {
|
||||
return Object.assign({}, item, {
|
||||
content: unreadCount.topic,
|
||||
iconClass: item.iconClass + ' unread-count',
|
||||
});
|
||||
}
|
||||
if (item.originalRoute === '/unread/new' && results.unreadNewTopicCount > 0) {
|
||||
return Object.assign({}, item, {
|
||||
content: unreadCount.newTopic,
|
||||
iconClass: item.iconClass + ' unread-count',
|
||||
});
|
||||
}
|
||||
if (item.originalRoute === '/unread/watched' && results.unreadWatchedTopicCount > 0) {
|
||||
return Object.assign({}, item, {
|
||||
content: unreadCount.watchedTopic,
|
||||
iconClass: item.iconClass + ' unread-count',
|
||||
});
|
||||
}
|
||||
|
||||
return item;
|
||||
});
|
||||
|
||||
templateValues.browserTitle = results.browserTitle;
|
||||
templateValues.navigation = results.navigation;
|
||||
templateValues.unreadCount = unreadCount;
|
||||
templateValues.metaTags = results.tags.meta;
|
||||
templateValues.linkTags = results.tags.link;
|
||||
templateValues.isAdmin = results.user.isAdmin;
|
||||
|
||||
@@ -19,15 +19,16 @@ navigation.get = function (callback) {
|
||||
data = data.filter(function (item) {
|
||||
return item && item.enabled;
|
||||
}).map(function (item) {
|
||||
item.originalRoute = item.route;
|
||||
|
||||
if (!item.route.startsWith('http')) {
|
||||
item.route = nconf.get('relative_path') + item.route;
|
||||
}
|
||||
|
||||
for (var i in item) {
|
||||
if (item.hasOwnProperty(i)) {
|
||||
item[i] = translator.unescape(item[i]);
|
||||
}
|
||||
}
|
||||
Object.keys(item).forEach(function (key) {
|
||||
item[key] = translator.unescape(item[key]);
|
||||
});
|
||||
|
||||
return item;
|
||||
});
|
||||
|
||||
|
||||
@@ -13,6 +13,23 @@ var meta = require('../meta');
|
||||
var pubsub = require('../pubsub');
|
||||
var events = require('../events');
|
||||
|
||||
var packageManager = nconf.get('package_manager') === 'yarn' ? 'yarn' : 'npm';
|
||||
var packageManagerExecutable = packageManager;
|
||||
var packageManagerCommands = {
|
||||
yarn: {
|
||||
install: 'add',
|
||||
uninstall: 'remove',
|
||||
},
|
||||
npm: {
|
||||
install: 'install',
|
||||
uninstall: 'uninstall',
|
||||
},
|
||||
};
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
packageManagerExecutable += '.cmd';
|
||||
}
|
||||
|
||||
module.exports = function (Plugins) {
|
||||
if (nconf.get('isPrimary') === 'true') {
|
||||
pubsub.on('plugins:toggleInstall', function (data) {
|
||||
@@ -95,7 +112,7 @@ module.exports = function (Plugins) {
|
||||
setImmediate(next);
|
||||
},
|
||||
function (next) {
|
||||
runNpmCommand(type, id, version || 'latest', next);
|
||||
runPackageManagerCommand(type, id, version || 'latest', next);
|
||||
},
|
||||
function (next) {
|
||||
Plugins.get(id, next);
|
||||
@@ -107,8 +124,12 @@ module.exports = function (Plugins) {
|
||||
], callback);
|
||||
}
|
||||
|
||||
function runNpmCommand(command, pkgName, version, callback) {
|
||||
cproc.execFile((process.platform === 'win32') ? 'npm.cmd' : 'npm', [command, pkgName + (command === 'install' ? '@' + version : ''), '--save'], function (err, stdout) {
|
||||
function runPackageManagerCommand(command, pkgName, version, callback) {
|
||||
cproc.execFile(packageManagerExecutable, [
|
||||
packageManagerCommands[packageManager][command],
|
||||
pkgName + (command === 'install' ? '@' + version : ''),
|
||||
'--save',
|
||||
], function (err, stdout) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -125,7 +146,7 @@ module.exports = function (Plugins) {
|
||||
|
||||
function upgrade(id, version, callback) {
|
||||
async.waterfall([
|
||||
async.apply(runNpmCommand, 'install', id, version || 'latest'),
|
||||
async.apply(runPackageManagerCommand, 'install', id, version || 'latest'),
|
||||
function (next) {
|
||||
Plugins.isActive(id, next);
|
||||
},
|
||||
|
||||
@@ -189,7 +189,7 @@ Upgrade.process = function (files, skipCount, callback) {
|
||||
}, next);
|
||||
},
|
||||
function (next) {
|
||||
console.log('Upgrade complete!\n'.green);
|
||||
console.log('Schema update complete!\n'.green);
|
||||
setImmediate(next);
|
||||
},
|
||||
], callback);
|
||||
@@ -205,7 +205,7 @@ Upgrade.incrementProgress = function (value) {
|
||||
if (this.total) {
|
||||
percentage = Math.floor((this.current / this.total) * 100) + '%';
|
||||
filled = Math.floor((this.current / this.total) * 15);
|
||||
unfilled = 15 - filled;
|
||||
unfilled = Math.min(0, 15 - filled);
|
||||
}
|
||||
|
||||
readline.cursorTo(process.stdout, 0);
|
||||
|
||||
67
src/upgrades/1.7.3/key_value_schema_change.js
Normal file
67
src/upgrades/1.7.3/key_value_schema_change.js
Normal file
@@ -0,0 +1,67 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
|
||||
var db = require('../../database');
|
||||
|
||||
module.exports = {
|
||||
name: 'Change the schema of simple keys so they don\'t use value field (mongodb only)',
|
||||
timestamp: Date.UTC(2017, 11, 18),
|
||||
method: function (callback) {
|
||||
var configJSON = require('../../../config.json');
|
||||
var isMongo = configJSON.hasOwnProperty('mongo') && configJSON.database === 'mongo';
|
||||
var progress = this.progress;
|
||||
if (!isMongo) {
|
||||
return callback();
|
||||
}
|
||||
var client = db.client;
|
||||
var cursor;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
client.collection('objects').count({
|
||||
_key: { $exists: true },
|
||||
value: { $exists: true },
|
||||
score: { $exists: false },
|
||||
}, next);
|
||||
},
|
||||
function (count, next) {
|
||||
progress.total = count;
|
||||
cursor = client.collection('objects').find({
|
||||
_key: { $exists: true },
|
||||
value: { $exists: true },
|
||||
score: { $exists: false },
|
||||
}).batchSize(1000);
|
||||
|
||||
var done = false;
|
||||
async.whilst(
|
||||
function () {
|
||||
return !done;
|
||||
},
|
||||
function (next) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
cursor.next(next);
|
||||
},
|
||||
function (item, next) {
|
||||
progress.incr();
|
||||
if (item === null) {
|
||||
done = true;
|
||||
return next();
|
||||
}
|
||||
|
||||
if (Object.keys(item).length === 3 && item.hasOwnProperty('_key') && item.hasOwnProperty('value')) {
|
||||
client.collection('objects').update({ _key: item._key }, { $rename: { value: 'data' } }, next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
next(err);
|
||||
});
|
||||
},
|
||||
next
|
||||
);
|
||||
},
|
||||
], callback);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user