Amazon smile converter
This commit is contained in:
parent
d1811b28a3
commit
1ecc5768e0
2 changed files with 17 additions and 5 deletions
|
@ -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/link-not-required.png)
|
||||||
![Screenshot](screenshots/name-from-link.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
|
||||||
```
|
```
|
||||||
docker run --detach --name christmas-community -p 80:80 --restart always wingysam/christmas-community
|
docker run --detach --name christmas-community -p 80:80 --restart always wingysam/christmas-community
|
||||||
|
@ -30,7 +33,13 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- ./data:/data
|
- ./data:/data
|
||||||
ports:
|
ports:
|
||||||
|
# If you want to go to localhost:8080 to access Christmas Community,
|
||||||
|
# use - 8080:80 instead of
|
||||||
- 80:80
|
- 80:80
|
||||||
|
environment:
|
||||||
|
# Amazon Smile, set to 'false' to disable www.amazon.com links
|
||||||
|
# turning into smile.amazon.com
|
||||||
|
SMILE: 'true'
|
||||||
restart: always
|
restart: always
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,11 @@ const totals = wishlist => {
|
||||||
|
|
||||||
const ValidURL = (string) => { // Ty SO
|
const ValidURL = (string) => { // Ty SO
|
||||||
try {
|
try {
|
||||||
new URL(string);
|
const url = new URL(string)
|
||||||
return true;
|
if (process.env.SMILE !== 'false') {
|
||||||
|
if (url.hostname === 'www.amazon.com') url.hostname = 'smile.amazon.com'
|
||||||
|
}
|
||||||
|
if (url) return url;
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -52,11 +55,11 @@ module.exports = (db) => {
|
||||||
|
|
||||||
router.post('/:user', verifyAuth(), async (req, res) => {
|
router.post('/:user', verifyAuth(), async (req, res) => {
|
||||||
const potentialUrl = req.body.itemUrlOrName.split(' ').pop();
|
const potentialUrl = req.body.itemUrlOrName.split(' ').pop();
|
||||||
const isUrl = ValidURL(potentialUrl);
|
const url = ValidURL(potentialUrl);
|
||||||
const item = {};
|
const item = {};
|
||||||
let productData;
|
let productData;
|
||||||
try {
|
try {
|
||||||
if (isUrl) productData = await getProductName(potentialUrl, config.proxyServer);
|
if (url) productData = await getProductName(url, config.proxyServer);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
req.flash('error', err.toString());
|
req.flash('error', err.toString());
|
||||||
}
|
}
|
||||||
|
@ -64,7 +67,7 @@ module.exports = (db) => {
|
||||||
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);
|
||||||
item.note = req.body.note;
|
item.note = req.body.note;
|
||||||
if (isUrl) item.url = potentialUrl;
|
if (url) item.url = url;
|
||||||
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