[pronouns][bug] fix missing config in api

This commit is contained in:
Andrea 2021-12-17 00:07:05 +01:00
parent 3a063e800a
commit b057c1ad47
2 changed files with 11 additions and 9 deletions

View File

@ -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'});

View File

@ -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]}`,