Only check after last space for url
This commit is contained in:
parent
9313da0afe
commit
eb3d97be7d
1 changed files with 4 additions and 3 deletions
|
@ -41,18 +41,19 @@ module.exports = (db) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/:user', verifyAuth(), async (req, res) => {
|
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 = {};
|
const item = {};
|
||||||
let productData;
|
let productData;
|
||||||
try {
|
try {
|
||||||
if (isUrl) productData = await getProductName(req.body.itemUrlOrName, config.proxyServer);
|
if (isUrl) productData = await getProductName(potentialUrl, config.proxyServer);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
req.flash('error', err.toString());
|
req.flash('error', err.toString());
|
||||||
}
|
}
|
||||||
item.name = (productData ? productData.name : req.body.itemUrlOrName);
|
item.name = (productData ? productData.name : req.body.itemUrlOrName);
|
||||||
item.addedBy = req.user._id;
|
item.addedBy = req.user._id;
|
||||||
item.pledgedBy = (req.user._id === req.params.user ? undefined : 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();
|
item.id = uuid();
|
||||||
const doc = await db.get(req.params.user);
|
const doc = await db.get(req.params.user);
|
||||||
doc.wishlist.push(item);
|
doc.wishlist.push(item);
|
||||||
|
|
Loading…
Reference in a new issue