You've already forked fm-dx-webserver
mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-02-26 22:13:53 +01:00
Several fixes
* Fixed rare unprompted auto-restart stream bug (bkram) [/web/js/3las/main.js] * Fixed multiple tooltip bug while RDS PS is tentatively loaded [/web/js/main.js] * Changed copying of plugin files to symlinks (junction for Windows) [/server/plugins.js] * Auto-reconnect audio stream on restored/changed internet connection [/web/js/3las/3las.js] * Main WebSocket connection can be shared with plugins [/web/js/websocket.js] [/web/index.ejs]
This commit is contained in:
@@ -21,22 +21,39 @@ function parsePluginConfig(filePath) {
|
||||
// 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, '..');
|
||||
const destinationDir = path.join(__dirname, '../web/js/plugins', path.dirname(pluginConfig.frontEndPath));
|
||||
|
||||
// Check if the source path exists
|
||||
if (!fs.existsSync(sourcePath)) {
|
||||
console.error(`Error: source path ${sourcePath} does not exist.`);
|
||||
return pluginConfig;
|
||||
}
|
||||
|
||||
// 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}`);
|
||||
|
||||
// Platform-specific handling for symlinks/junctions
|
||||
if (process.platform !== 'win32') {
|
||||
// On Linux, create a symlink
|
||||
try {
|
||||
if (fs.existsSync(destinationFile)) {
|
||||
fs.unlinkSync(destinationFile); // Remove existing file/symlink
|
||||
}
|
||||
fs.symlinkSync(sourcePath, destinationFile);
|
||||
console.log(`Symlink created from ${sourcePath} to ${destinationFile}`);
|
||||
} catch (err) {
|
||||
console.error(`Error creating symlink at ${destinationFile}: ${err.message}`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.error(`Error: frontEndPath is not defined in ${filePath}`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`Error parsing plugin config from ${filePath}: ${err}`);
|
||||
console.error(`Error parsing plugin config from ${filePath}: ${err.message}`);
|
||||
}
|
||||
|
||||
return pluginConfig;
|
||||
@@ -59,9 +76,35 @@ function collectPluginConfigs() {
|
||||
return pluginConfigs;
|
||||
}
|
||||
|
||||
// Ensure the web/js/plugins directory exists
|
||||
const webJsPluginsDir = path.join(__dirname, '../web/js/plugins');
|
||||
if (!fs.existsSync(webJsPluginsDir)) {
|
||||
fs.mkdirSync(webJsPluginsDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Main function to create symlinks/junctions for plugins
|
||||
function createLinks() {
|
||||
const pluginsDir = path.join(__dirname, '../plugins');
|
||||
const destinationPluginsDir = path.join(__dirname, '../web/js/plugins');
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
// On Windows, create a junction
|
||||
try {
|
||||
if (fs.existsSync(destinationPluginsDir)) {
|
||||
fs.rmSync(destinationPluginsDir, { recursive: true });
|
||||
}
|
||||
fs.symlinkSync(pluginsDir, destinationPluginsDir, 'junction');
|
||||
console.log(`Junction created from ${pluginsDir} to ${destinationPluginsDir}`);
|
||||
} catch (err) {
|
||||
console.error(`Error creating junction at ${destinationPluginsDir}: ${err.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Usage example
|
||||
const allPluginConfigs = collectPluginConfigs();
|
||||
createLinks();
|
||||
|
||||
module.exports = {
|
||||
allPluginConfigs
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user