From e26ac82c6634aca0cc06f86f69370104b6697634 Mon Sep 17 00:00:00 2001 From: Tiger Oakes Date: Tue, 29 Sep 2020 08:53:36 -0700 Subject: [PATCH] Fix missing keywords --- backend/app.js | 2 +- backend/db.js | 4 ++-- backend/utils.js | 26 ++++++++++++-------------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/backend/app.js b/backend/app.js index 0f2090e..d58e350 100644 --- a/backend/app.js +++ b/backend/app.js @@ -1946,7 +1946,7 @@ app.post('/api/getFile', optionalJwt, function (req, res) { } }); -app.post('/api/getAllFiles', optionalJwt, function (req, res) { +app.post('/api/getAllFiles', optionalJwt, async function (req, res) { // these are returned let files = []; let playlists = []; diff --git a/backend/db.js b/backend/db.js index 81524aa..6f12be1 100644 --- a/backend/db.js +++ b/backend/db.js @@ -182,7 +182,7 @@ async function importUnregisteredFiles() { } // run through check list and check each file to see if it's missing from the db - dirs_to_check.forEach(dir_to_check => { + for (const dir_to_check of dirs_to_check) { // recursively get all files in dir's path const files = await utils.getDownloadedFilesByType(dir_to_check.basePath, dir_to_check.type); @@ -195,7 +195,7 @@ async function importUnregisteredFiles() { logger.verbose(`Added discovered file to the database: ${file.id}`); } }); - }); + } } diff --git a/backend/utils.js b/backend/utils.js index d7ac82d..4bfad5e 100644 --- a/backend/utils.js +++ b/backend/utils.js @@ -161,25 +161,23 @@ function deleteJSONFile(name, type, customPath = null) { async function recFindByExt(base,ext,files,result) { - files = files || fs.readdirSync(base) + files = files || (await fs.readdir(base)) result = result || [] - files.forEach( - function (file) { - var newbase = path.join(base,file) - if ( fs.statSync(newbase).isDirectory() ) - { - result = await recFindByExt(newbase,ext,fs.readdirSync(newbase),result) - } - else + for (const file in files) { + var newbase = path.join(base,file) + if ( (await fs.stat(newbase)).isDirectory() ) + { + result = await recFindByExt(newbase,ext,await fs.readdir(newbase),result) + } + else + { + if ( file.substr(-1*(ext.length+1)) == '.' + ext ) { - if ( file.substr(-1*(ext.length+1)) == '.' + ext ) - { - result.push(newbase) - } + result.push(newbase) } } - ) + } return result }