From 9231117668212baf5772cbc92fb6e99af66a2b00 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sat, 9 Jul 2022 23:18:09 +0200 Subject: [PATCH] Fixed the addon name regex --- controller/addon.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/controller/addon.js b/controller/addon.js index 643cebf..e1e191e 100644 --- a/controller/addon.js +++ b/controller/addon.js @@ -11,7 +11,7 @@ module.exports.getAddonById = async (id) => { // Gets an addon by the user id and addon name module.exports.getAddonFromUser = async (author, addon_name) => { - return await Addon.findOne({author, name: addon_name}).populate('author', 'username email').exec(); + return await Addon.findOne({author, name: addon_name}).collation({locale: "en", strength: 2}).populate('author', 'username email').exec(); } // Updates an addon by id @@ -33,11 +33,11 @@ module.exports.listAddonsByAuthorName = async (author_name) => { } // Gets an addon by the author and addon name -module.exports.getAddonByName = async (author_name, addon_name) => { +module.exports.getAddonByName = async (author_name, name) => { const user = await getUserByName(author_name); if (user === null) return; - return await Addon.findOne({author: user._id, name: {$regex: addon_name, $options: 'i'}}, {__v: 0}).populate('author', 'username email').exec(); + return await Addon.findOne({author: user._id, name}, {__v: 0}).populate('author', 'username email').collation({locale: "en", strength: 2}).exec(); } // Searches the database for multiple addons by a query @@ -47,8 +47,8 @@ module.exports.searchAddon = async (query, limit = 25) => { } // Checks if the provided addon already exists (by the id of the author & the name of the addon) -module.exports.addonExists = async (author, addon_name) => { +module.exports.addonExists = async (author, name) => { if (!mongo.ObjectId.isValid(author)) return; - return await Addon.findOne({author, name: {$regex: addon_name, $options: 'i'}}).exec() !== null; + return await Addon.findOne({author, name}).collation({locale: "en", strength: 2}).exec() !== null; } \ No newline at end of file