mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-24 01:10:31 +01:00
feat: add filter
This commit is contained in:
@@ -7,6 +7,7 @@ const _ = require('lodash');
|
||||
const meta = require('../meta');
|
||||
const languages = require('../languages');
|
||||
const helpers = require('./helpers');
|
||||
const plugins = require('../plugins');
|
||||
|
||||
module.exports = function (middleware) {
|
||||
middleware.addHeaders = helpers.try(function addHeaders(req, res, next) {
|
||||
@@ -75,10 +76,13 @@ module.exports = function (middleware) {
|
||||
next();
|
||||
});
|
||||
|
||||
middleware.autoLocale = helpers.try(async function autoLocale(req, res, next) {
|
||||
let langs;
|
||||
middleware.autoLocale = helpers.try(async (req, res, next) => {
|
||||
await plugins.hooks.fire('filter:middleware.autoLocale', {
|
||||
req: req,
|
||||
res: res,
|
||||
});
|
||||
if (req.query.lang) {
|
||||
langs = await listCodes();
|
||||
const langs = await listCodes();
|
||||
if (!langs.includes(req.query.lang)) {
|
||||
req.query.lang = meta.config.defaultLang;
|
||||
}
|
||||
@@ -87,7 +91,7 @@ module.exports = function (middleware) {
|
||||
if (parseInt(req.uid, 10) > 0 || !meta.config.autoDetectLang) {
|
||||
return next();
|
||||
}
|
||||
langs = await listCodes();
|
||||
const langs = await listCodes();
|
||||
const lang = req.acceptsLanguages(langs);
|
||||
if (!lang) {
|
||||
return next();
|
||||
|
||||
Reference in New Issue
Block a user