From 9475d2c96b28e8129bd52318a51c0e3941b8e268 Mon Sep 17 00:00:00 2001 From: NoobishSVK Date: Thu, 25 Apr 2024 20:53:29 +0200 Subject: [PATCH] hotfix for plugins (missing files) --- plugins/example.js | 14 ++++++++ plugins/example/frontend.js | 1 + server/plugins.js | 67 +++++++++++++++++++++++++++++++++++++ web/css/multiselect.css | 45 +++++++++++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 plugins/example.js create mode 100644 plugins/example/frontend.js create mode 100644 server/plugins.js create mode 100644 web/css/multiselect.css diff --git a/plugins/example.js b/plugins/example.js new file mode 100644 index 0000000..24515b5 --- /dev/null +++ b/plugins/example.js @@ -0,0 +1,14 @@ +// Plugin configuration, this is used in the administration when plugins are loaded +var pluginConfig = { + name: 'Example plugin', + version: '1.0', + author: 'OpenRadio', + frontEndPath: 'example/frontend.js' +} + +// Backend (server) changes can go here... + +// Don't change anything below here if you are making your own plugin +module.exports = { + pluginConfig +} \ No newline at end of file diff --git a/plugins/example/frontend.js b/plugins/example/frontend.js new file mode 100644 index 0000000..ebcd6f7 --- /dev/null +++ b/plugins/example/frontend.js @@ -0,0 +1 @@ +console.log('Webserver plugins loaded successfully.'); \ No newline at end of file diff --git a/server/plugins.js b/server/plugins.js new file mode 100644 index 0000000..3b87e6b --- /dev/null +++ b/server/plugins.js @@ -0,0 +1,67 @@ +const fs = require('fs'); +const path = require('path'); +const { serverConfig } = require('./server_config'); + +// Function to read all .js files in a directory +function readJSFiles(dir) { + const files = fs.readdirSync(dir); + return files.filter(file => file.endsWith('.js')); +} + +// Function to parse plugin config from a file +function parsePluginConfig(filePath) { + const fileContent = fs.readFileSync(filePath, 'utf8'); + const pluginConfig = {}; + + // Assuming pluginConfig is a JavaScript object defined in each .js file + try { + const pluginExports = require(filePath); + Object.assign(pluginConfig, pluginExports.pluginConfig); + + // Check if pluginConfig has frontEndPath defined + if (pluginConfig.frontEndPath) { + const sourcePath = path.join(path.dirname(filePath), pluginConfig.frontEndPath); + const destinationDir = path.join(path.dirname(filePath), '../web/js/plugins', pluginConfig.frontEndPath, '..'); + + // Check if the destination directory exists, if not, create it + if (!fs.existsSync(destinationDir)) { + fs.mkdirSync(destinationDir, { recursive: true }); // Create directory recursively + } + + // Copy the file to the destination directory + const destinationFile = path.join(destinationDir, path.basename(sourcePath)); + fs.copyFileSync(sourcePath, destinationFile); + console.log(`File copied from ${sourcePath} to ${destinationFile}`); + } else { + console.error(`Error: frontEndPath is not defined in ${filePath}`); + } + } catch (err) { + console.error(`Error parsing plugin config from ${filePath}: ${err}`); + } + + return pluginConfig; +} + +// Main function to collect plugin configs from all .js files in the 'plugins' directory +function collectPluginConfigs() { + const pluginsDir = path.join(__dirname, '../plugins'); + const jsFiles = readJSFiles(pluginsDir); + + const pluginConfigs = []; + jsFiles.forEach(file => { + const filePath = path.join(pluginsDir, file); + const config = parsePluginConfig(filePath); + if (Object.keys(config).length > 0) { + pluginConfigs.push(config); + } + }); + + return pluginConfigs; +} + +// Usage example +const allPluginConfigs = collectPluginConfigs(); + +module.exports = { + allPluginConfigs +} \ No newline at end of file diff --git a/web/css/multiselect.css b/web/css/multiselect.css new file mode 100644 index 0000000..be45c53 --- /dev/null +++ b/web/css/multiselect.css @@ -0,0 +1,45 @@ +.multiselect { + width: 400px; + height: 320px; + background-color: var(--color-2); + padding: 8px 16px; + border-radius: 30px; + padding: 20px; + } + + .multiselect:hover { + background-color: var(--color-2); + } + + .multiselect:focus { + outline: 0; + } + + .multiselect option { + font-size: 14px; + font-weight: 500; + padding: 8px; + position: relative; + color: var(--color-4); + } + + .multiselect option:checked::after { + content: attr(title); + background: var(--color-4); + color: var(--color-main); + position: absolute; + width: 344px; + height: 21px; + left: 0; + top: 0; + padding: 8px; + border: none; + } + + .multiselect option:focus, .multiselect option:active { + background: transparent !important; + } + + .multiselect:active > option:checked { + background: red !important; + } \ No newline at end of file