remove uuid, only use nanoid and u64

This commit is contained in:
Wingy 2020-11-01 22:24:40 -05:00
parent 7bc40ac3af
commit f076f60844
4 changed files with 1353 additions and 1734 deletions

View file

@ -1,4 +1,4 @@
const { v4: uuid} = require('uuid'); const { nanoid } = require('nanoid')
const path = require('path'); const path = require('path');
const fs = require('fs'); const fs = require('fs');
@ -7,7 +7,7 @@ const secretFilePath = path.join((process.env.SECRET_DIRNAME ? process.env.SECRE
try { try {
module.exports = fs.readFileSync(secretFilePath).toString(); module.exports = fs.readFileSync(secretFilePath).toString();
} catch (_) { } catch (_) {
const secret = uuid(); const secret = nanoid(128);
fs.writeFileSync(secretFilePath, secret); fs.writeFileSync(secretFilePath, secret);
module.exports = secret; module.exports = secret;
} }

View file

@ -31,7 +31,7 @@
"passport-local": "^1.0.0", "passport-local": "^1.0.0",
"pouchdb": "^7.2.2", "pouchdb": "^7.2.2",
"pug": "^3.0.0", "pug": "^3.0.0",
"uuid": "^8.3.1", "u64": "^1.0.1",
"yes-no": "^0.0.1" "yes-no": "^0.0.1"
} }
} }

View file

@ -2,7 +2,7 @@ const verifyAuth = require('../../middlewares/verifyAuth');
const getProductName = require('get-product-name'); const getProductName = require('get-product-name');
const express = require('express'); const express = require('express');
const config = require('../../config'); const config = require('../../config');
const { v4: uuid} = require('uuid'); const u64 = require('u64')
const totals = wishlist => { const totals = wishlist => {
let unpledged = 0; let unpledged = 0;
@ -70,6 +70,10 @@ module.exports = (db) => {
}); });
router.post('/:user', verifyAuth(), async (req, res) => { router.post('/:user', verifyAuth(), async (req, res) => {
if (!req.body.itemUrlOrName) {
req.flash('error', 'Item URL or Name is required')
return res.redirect(`/wishlist/${req.params.user}`)
}
const potentialUrl = req.body.itemUrlOrName.split(' ').pop(); const potentialUrl = req.body.itemUrlOrName.split(' ').pop();
const url = ValidURL(potentialUrl); const url = ValidURL(potentialUrl);
const item = {}; const item = {};
@ -85,10 +89,15 @@ module.exports = (db) => {
item.note = req.body.note; item.note = req.body.note;
if (url) item.url = url; if (url) item.url = url;
if (!url) item.name = req.body.itemUrlOrName if (!url) item.name = req.body.itemUrlOrName
item.id = uuid(); item.id = u64.encode(new Date().getTime().toString());
const doc = await db.get(req.params.user); const doc = await db.get(req.params.user);
doc.wishlist.push(item); doc.wishlist.push(item);
await db.put(doc); try {
await db.put(doc);
} catch {
req.flash('error', 'Items are being added too quickly. Please try again.')
return res.redirect(`/wishlist/${req.params.user}`)
}
req.flash( req.flash(
'success', 'success',
( (

3066
yarn.lock

File diff suppressed because it is too large Load diff