From b057c1ad4765845b2a64bafe7781bbc0f4b71577 Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 17 Dec 2021 00:07:05 +0100 Subject: [PATCH] [pronouns][bug] fix missing config in api --- server/routes/pronouns.js | 2 +- src/buildPronoun.js | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/server/routes/pronouns.js b/server/routes/pronouns.js index ea94b85c..97c6e986 100644 --- a/server/routes/pronouns.js +++ b/server/routes/pronouns.js @@ -61,7 +61,7 @@ router.get('/pronouns/:pronoun*', handleErrorAsync(async (req, res) => { router.get('/pronouns-name/:pronoun*', handleErrorAsync(async (req, res) => { const pronoun = buildPronoun( parsePronouns(loadTsv('pronouns/pronouns')), - decodeURIComponent(req.params.pronoun + req.params[0]), + req.params.pronoun + req.params[0], ); if (!pronoun) { return res.status(404).json({error: 'Not found'}); diff --git a/src/buildPronoun.js b/src/buildPronoun.js index 5bb17e27..8b5a7edb 100644 --- a/src/buildPronoun.js +++ b/src/buildPronoun.js @@ -42,6 +42,8 @@ const buildPronounFromTemplate = (key, template) => { } export const buildPronoun = (pronouns, path) => { + const config = global.config || process.env.CONFIG; + const pronounsWithAliases = addAliasesToPronouns(pronouns); const pronounStr = path.split(','); @@ -59,23 +61,23 @@ export const buildPronoun = (pronouns, path) => { ? base : Pronoun.from(Compressor.uncompress(pronounStr, base ? base.toArray() : null)); - if (!process.env.CONFIG) { + if (!config) { return pronoun; } - if (!pronoun && process.env.CONFIG.pronouns.emoji !== false && isEmoji(path)) { - pronoun = buildPronounFromTemplate(path, process.env.CONFIG.pronouns.emoji); + if (!pronoun && config.pronouns.emoji !== false && isEmoji(path)) { + pronoun = buildPronounFromTemplate(path, config.pronouns.emoji); } - if (!pronoun && process.env.CONFIG.pronouns.null && process.env.CONFIG.pronouns.null.morphemes && path.startsWith(':') && path.length < 12) { - pronoun = buildPronounFromTemplate(path.substring(1), process.env.CONFIG.pronouns.null); + if (!pronoun && config.pronouns.null && config.pronouns.null.morphemes && path.startsWith(':') && path.length < 12) { + pronoun = buildPronounFromTemplate(path.substring(1), config.pronouns.null); } const p = path.split('/').filter(s => !!s); - if (!pronoun && process.env.CONFIG.pronouns.slashes !== false) { - const slashMorphemes = process.env.CONFIG.pronouns.slashes === true + if (!pronoun && config.pronouns.slashes !== false) { + const slashMorphemes = config.pronouns.slashes === true ? MORPHEMES - : process.env.CONFIG.pronouns.slashes; + : config.pronouns.slashes; if (slashMorphemes && p.length === slashMorphemes.length) { pronoun = new Pronoun( `${p[0]}/${p[1]}`,