From 8bb0a7fde013dddfc300b201dcc1de2f509a25ed Mon Sep 17 00:00:00 2001 From: tecc Date: Thu, 1 Jun 2023 23:50:55 +0200 Subject: [PATCH] fix(api-profile-filter): Fix filtering data in profile requests --- server/routes/profile.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/server/routes/profile.js b/server/routes/profile.js index 94a742eca..9d3729927 100644 --- a/server/routes/profile.js +++ b/server/routes/profile.js @@ -78,20 +78,26 @@ class ProfileOptions { }; constructor(query_obj, locales) { + if (query_obj == null) return; + const default_props = query_obj["props"]; this.default_props = ProfileOptions._parse_props(default_props) - for (const key of Object.keys(locales)) { - const lprops_obj = query_obj["lprops"]; - let props; - if (typeof lprops_obj === "object") { - props = lprops_obj[key]; - } else { - props = query_obj[`lprops.${key.toLowerCase()}`]; - } - if (props != null) { - this.locale_specific_props[key] = ProfileOptions._parse_props(props); + if (locales != null) { + for (const key of Object.keys(locales)) { + const lprops_obj = query_obj["lprops"]; + let props; + if (typeof lprops_obj === "object") { + props = lprops_obj[key]; + } else { + props = query_obj[`lprops.${key.toLowerCase()}`]; + } + if (props != null) { + this.locale_specific_props[key] = ProfileOptions._parse_props(props); + } } + } else { + console.warn("ProfileOptions object was constructed without specifying locales parameter - not providing locale-specific data"); } } @@ -698,7 +704,7 @@ router.post('/profile/save', handleErrorAsync(async (req, res) => { await req.db.get(SQL`UPDATE users SET inactiveWarning = null WHERE id = ${req.user.id}`); - return res.json(await fetchProfiles(req.db, req.user.username, true)); + return res.json(await fetchProfiles(req.db, req.user.username, true, new ProfileOptions({}))); })); router.post('/profile/delete/:locale', handleErrorAsync(async (req, res) => {