From f5565dd6c9e1158738e2f551be00a079b67b1db8 Mon Sep 17 00:00:00 2001
From: Timothy Carambat <rambat1010@gmail.com>
Date: Thu, 12 Sep 2024 09:48:53 -0700
Subject: [PATCH] Patch missing folder autogenerate for plugins (#2273)

---
 server/utils/agents/imported.js | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/server/utils/agents/imported.js b/server/utils/agents/imported.js
index 136f4a3ad..8a7da4802 100644
--- a/server/utils/agents/imported.js
+++ b/server/utils/agents/imported.js
@@ -45,6 +45,15 @@ class ImportedPlugin {
     return true;
   }
 
+  /**
+   * Checks if the plugin folder exists and if it does not, creates the folder.
+   */
+  static checkPluginFolderExists() {
+    const dir = path.resolve(pluginsPath);
+    if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
+    return;
+  }
+
   /**
    * Loads plugins from `plugins` folder in storage that are custom loaded and defined.
    * only loads plugins that are active: true.
@@ -52,6 +61,7 @@ class ImportedPlugin {
    */
   static async activeImportedPlugins() {
     const plugins = [];
+    this.checkPluginFolderExists();
     const folders = fs.readdirSync(path.resolve(pluginsPath));
     for (const folder of folders) {
       const configLocation = path.resolve(
@@ -72,6 +82,7 @@ class ImportedPlugin {
    */
   static listImportedPlugins() {
     const plugins = [];
+    this.checkPluginFolderExists();
     if (!fs.existsSync(pluginsPath)) return plugins;
 
     const folders = fs.readdirSync(path.resolve(pluginsPath));
-- 
GitLab