Only check after last space for url

This commit is contained in:
Wingysam 2018-11-22 16:59:21 -05:00
parent 9313da0afe
commit eb3d97be7d

View file

@ -41,18 +41,19 @@ module.exports = (db) => {
});
router.post('/:user', verifyAuth(), async (req, res) => {
const isUrl = ValidURL(req.body.itemUrlOrName);
const potentialUrl = req.body.itemUrlOrName.split(' ').pop();
const isUrl = ValidURL(potentialUrl);
const item = {};
let productData;
try {
if (isUrl) productData = await getProductName(req.body.itemUrlOrName, config.proxyServer);
if (isUrl) productData = await getProductName(potentialUrl, config.proxyServer);
} catch (err) {
req.flash('error', err.toString());
}
item.name = (productData ? productData.name : req.body.itemUrlOrName);
item.addedBy = req.user._id;
item.pledgedBy = (req.user._id === req.params.user ? undefined : req.user._id);
if (isUrl) item.url = req.body.itemUrlOrName;
if (isUrl) item.url = potentialUrl;
item.id = uuid();
const doc = await db.get(req.params.user);
doc.wishlist.push(item);