Images should be under the product id not permalink

master
Mark Moffat 2019-10-26 12:03:39 +10:30
parent e6feac9e7a
commit c9732ad235
2 changed files with 4 additions and 4 deletions

View File

@ -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()); 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 db = req.app.db;
const product = await db.products.findOne({ _id: getId(dir) }); const product = await db.products.findOne({ _id: getId(id) });
if(!product){ if(!product){
return[]; return[];
} }
// loop files in /public/uploads/ // 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 // sort array
files.sort(); files.sort();

View File

@ -409,7 +409,7 @@ router.post('/admin/file/upload', restrict, checkAccess, upload.single('upload_f
return; return;
} }
const productPath = product.productPermalink; const productPath = product._id.toString();
const uploadDir = path.join('public/uploads', productPath); const uploadDir = path.join('public/uploads', productPath);
// Check directory and create (if needed) // Check directory and create (if needed)