From c9732ad2352d38f03db9b30dd2d59c362571d64b Mon Sep 17 00:00:00 2001 From: Mark Moffat Date: Sat, 26 Oct 2019 12:03:39 +1030 Subject: [PATCH] Images should be under the product id not permalink --- lib/common.js | 6 +++--- routes/admin.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/common.js b/lib/common.js index ccd614e..f6b2be5 100755 --- a/lib/common.js +++ b/lib/common.js @@ -147,16 +147,16 @@ const getThemes = () => { return fs.readdirSync(path.join(__dirname, '../', 'views', 'themes')).filter(file => fs.statSync(path.join(path.join(__dirname, '../', 'views', 'themes'), file)).isDirectory()); }; -const getImages = async (dir, req, res, callback) => { +const getImages = async (id, req, res, callback) => { const db = req.app.db; - const product = await db.products.findOne({ _id: getId(dir) }); + const product = await db.products.findOne({ _id: getId(id) }); if(!product){ return[]; } // loop files in /public/uploads/ - const files = await glob.sync(`public/uploads/${product.productPermalink}/**`, { nosort: true }); + const files = await glob.sync(`public/uploads/${product._id.toString()}/**`, { nosort: true }); // sort array files.sort(); diff --git a/routes/admin.js b/routes/admin.js index 36fd266..1b8733c 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -409,7 +409,7 @@ router.post('/admin/file/upload', restrict, checkAccess, upload.single('upload_f return; } - const productPath = product.productPermalink; + const productPath = product._id.toString(); const uploadDir = path.join('public/uploads', productPath); // Check directory and create (if needed)