Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Moffat committed Oct 26, 2019
1 parent f0f3c56 commit 7070cde
Show file tree
Hide file tree
Showing 5 changed files with 789 additions and 891 deletions.
2 changes: 1 addition & 1 deletion lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const restrictedRoutes = [
{ route: '/admin/product/published_state', response: 'json' },
{ route: '/admin/product/setasmainimage', response: 'json' },
{ route: '/admin/product/deleteimage', response: 'json' },
{ route: '/admin/product/removeoption', response: 'json' },
{ route: '/admin/order/statusupdate', response: 'json' },
{ route: '/admin/settings/update', response: 'json' },
{ route: '/admin/settings/option/remove', response: 'json' },
{ route: '/admin/settings/pages/new', response: 'redirect' },
{ route: '/admin/settings/pages/edit/:page', response: 'redirect' },
{ route: '/admin/settings/pages/update', response: 'json' },
Expand Down
61 changes: 30 additions & 31 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,41 +147,40 @@ 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 = (dir, req, res, callback) => {
const getImages = async (dir, req, res, callback) => {
const db = req.app.db;

db.products.findOne({ _id: getId(dir) }, (err, product) => {
if(err){
console.error(colors.red('Error getting images', err));
}
const product = await db.products.findOne({ _id: getId(dir) });
if(!product){
return[];
}

// loop files in /public/uploads/
glob('public/uploads/' + product.productPermalink + '/**', { nosort: true }, (er, files) => {
// sort array
files.sort();

// declare the array of objects
const fileList = [];

// loop these files
for(let i = 0; i < files.length; i++){
// only want files
if(fs.lstatSync(files[i]).isDirectory() === false){
// declare the file object and set its values
const file = {
id: i,
path: files[i].substring(6)
};
if(product.productImage === files[i].substring(6)){
file.productImage = true;
}
// push the file object into the array
fileList.push(file);
}
// loop files in /public/uploads/
const files = await glob.sync(`public/uploads/${product.productPermalink}/**`, { nosort: true });

// sort array
files.sort();

// declare the array of objects
const fileList = [];

// loop these files
for(let i = 0; i < files.length; i++){
// only want files
if(fs.lstatSync(files[i]).isDirectory() === false){
// declare the file object and set its values
const file = {
id: i,
path: files[i].substring(6)
};
if(product.productImage === files[i].substring(6)){
file.productImage = true;
}
callback(fileList);
});
});
// push the file object into the array
fileList.push(file);
}
}
return fileList;
};

const getConfig = () => {
Expand Down
Loading

0 comments on commit 7070cde

Please sign in to comment.