Amazon smile converter

This commit is contained in:
Sam Wing 2019-11-13 12:34:32 -05:00
parent d1811b28a3
commit 1ecc5768e0
2 changed files with 17 additions and 5 deletions

View file

@ -15,6 +15,9 @@ To create a simple place for your entire family to use to find gifts that people
![Screenshot](screenshots/link-not-required.png)
![Screenshot](screenshots/name-from-link.png)
## Amazon Smile
By default, Christmas Community converts www.amazon.com links to smile.amazon.com. If you do not want this, set the environment variable SMILE to false (if you are using Docker Compose, make sure to put "false" in quotes).
## Docker
```
docker run --detach --name christmas-community -p 80:80 --restart always wingysam/christmas-community
@ -30,7 +33,13 @@ services:
volumes:
- ./data:/data
ports:
# If you want to go to localhost:8080 to access Christmas Community,
# use - 8080:80 instead of
- 80:80
environment:
# Amazon Smile, set to 'false' to disable www.amazon.com links
# turning into smile.amazon.com
SMILE: 'true'
restart: always
```

View file

@ -16,8 +16,11 @@ const totals = wishlist => {
const ValidURL = (string) => { // Ty SO
try {
new URL(string);
return true;
const url = new URL(string)
if (process.env.SMILE !== 'false') {
if (url.hostname === 'www.amazon.com') url.hostname = 'smile.amazon.com'
}
if (url) return url;
} catch (_) {
return false;
}
@ -52,11 +55,11 @@ module.exports = (db) => {
router.post('/:user', verifyAuth(), async (req, res) => {
const potentialUrl = req.body.itemUrlOrName.split(' ').pop();
const isUrl = ValidURL(potentialUrl);
const url = ValidURL(potentialUrl);
const item = {};
let productData;
try {
if (isUrl) productData = await getProductName(potentialUrl, config.proxyServer);
if (url) productData = await getProductName(url, config.proxyServer);
} catch (err) {
req.flash('error', err.toString());
}
@ -64,7 +67,7 @@ module.exports = (db) => {
item.addedBy = req.user._id;
item.pledgedBy = (req.user._id === req.params.user ? undefined : req.user._id);
item.note = req.body.note;
if (isUrl) item.url = potentialUrl;
if (url) item.url = url;
item.id = uuid();
const doc = await db.get(req.params.user);
doc.wishlist.push(item);