From d4c54ac5043540257b5f4efbc1a39b003f80b16b Mon Sep 17 00:00:00 2001 From: Avalon Date: Wed, 10 Sep 2025 02:34:13 +0000 Subject: [PATCH] Remove extra returns from Data.getStaticDirectories --- src/plugins/data.js | 46 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/plugins/data.js b/src/plugins/data.js index ba6e319e78..0b9b52352b 100644 --- a/src/plugins/data.js +++ b/src/plugins/data.js @@ -84,15 +84,11 @@ Data.getActive = async function () { return await Promise.all(pluginPaths.map(p => Data.loadPluginInfo(p))); }; - +//ChatGPT produced reorganization of the code to minimize the number of return statments. Data.getStaticDirectories = async function (pluginData) { const validMappedPath = /^[\w\-_]+$/; - if (!pluginData.staticDirs) { - return; - } - - const dirs = Object.keys(pluginData.staticDirs); + const dirs = Object.keys(pluginData.staticDirs ?? {}); if (!dirs.length) { return; } @@ -100,33 +96,36 @@ Data.getStaticDirectories = async function (pluginData) { const staticDirs = {}; async function processDir(route) { - if (!validMappedPath.test(route)) { - winston.warn(`[plugins/${pluginData.id}] Invalid mapped path specified: ${ - route}. Path must adhere to: ${validMappedPath.toString()}`); - return; - } - const dirPath = await resolveModulePath(pluginData.path, pluginData.staticDirs[route]); - if (!dirPath) { - winston.warn(`[plugins/${pluginData.id}] Invalid mapped path specified: ${ - route} => ${pluginData.staticDirs[route]}`); - return; - } + let dirPath; try { + // guard 1 + if (!validMappedPath.test(route)) { + winston.warn(`[plugins/${pluginData.id}] Invalid mapped path specified: ${ + route}. Path must adhere to: ${validMappedPath}`); + return; + } + + dirPath = await resolveModulePath(pluginData.path, pluginData.staticDirs[route]); + if (!dirPath) { + winston.warn(`[plugins/${pluginData.id}] Invalid mapped path specified: ${ + route} => ${pluginData.staticDirs[route]}`); + return; + } + const stats = await fs.promises.stat(dirPath); if (!stats.isDirectory()) { - winston.warn(`[plugins/${pluginData.id}] Mapped path '${ - route} => ${dirPath}' is not a directory.`); + winston.warn(`[plugins/${pluginData.id}] Mapped path '${route} => ${dirPath}' is not a directory.`); return; } + // success path staticDirs[`${pluginData.id}/${route}`] = dirPath; } catch (err) { if (err.code === 'ENOENT') { - winston.warn(`[plugins/${pluginData.id}] Mapped path '${ - route} => ${dirPath}' not found.`); - return; + winston.warn(`[plugins/${pluginData.id}] Mapped path '${route} => ${dirPath}' not found.`); + } else { + throw err; } - throw err; } } @@ -136,6 +135,7 @@ Data.getStaticDirectories = async function (pluginData) { }; + Data.getFiles = async function (pluginData, type) { if (!Array.isArray(pluginData[type]) || !pluginData[type].length) { return;