mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Remove separate plugins dir and use metadata dir for plugins folder
This commit is contained in:
		
							parent
							
								
									ad89fb2eac
								
							
						
					
					
						commit
						23b480b11a
					
				
							
								
								
									
										4
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								index.js
									
									
									
									
									
								
							| @ -13,7 +13,6 @@ if (isDev) { | |||||||
|   if (devEnv.SkipBinariesCheck) process.env.SKIP_BINARIES_CHECK = '1' |   if (devEnv.SkipBinariesCheck) process.env.SKIP_BINARIES_CHECK = '1' | ||||||
|   if (devEnv.AllowIframe) process.env.ALLOW_IFRAME = '1' |   if (devEnv.AllowIframe) process.env.ALLOW_IFRAME = '1' | ||||||
|   if (devEnv.BackupPath) process.env.BACKUP_PATH = devEnv.BackupPath |   if (devEnv.BackupPath) process.env.BACKUP_PATH = devEnv.BackupPath | ||||||
|   if (devEnv.PluginsPath) process.env.PLUGINS_PATH = devEnv.PluginsPath |  | ||||||
|   process.env.SOURCE = 'local' |   process.env.SOURCE = 'local' | ||||||
|   process.env.ROUTER_BASE_PATH = devEnv.RouterBasePath || '' |   process.env.ROUTER_BASE_PATH = devEnv.RouterBasePath || '' | ||||||
| } | } | ||||||
| @ -22,11 +21,10 @@ const PORT = process.env.PORT || 80 | |||||||
| const HOST = process.env.HOST | const HOST = process.env.HOST | ||||||
| const CONFIG_PATH = process.env.CONFIG_PATH || '/config' | const CONFIG_PATH = process.env.CONFIG_PATH || '/config' | ||||||
| const METADATA_PATH = process.env.METADATA_PATH || '/metadata' | const METADATA_PATH = process.env.METADATA_PATH || '/metadata' | ||||||
| const PLUGINS_PATH = process.env.PLUGINS_PATH || '/plugins' |  | ||||||
| const SOURCE = process.env.SOURCE || 'docker' | const SOURCE = process.env.SOURCE || 'docker' | ||||||
| const ROUTER_BASE_PATH = process.env.ROUTER_BASE_PATH || '' | const ROUTER_BASE_PATH = process.env.ROUTER_BASE_PATH || '' | ||||||
| 
 | 
 | ||||||
| console.log('Config', CONFIG_PATH, METADATA_PATH) | console.log('Config', CONFIG_PATH, METADATA_PATH) | ||||||
| 
 | 
 | ||||||
| const Server = new server(SOURCE, PORT, HOST, CONFIG_PATH, METADATA_PATH, PLUGINS_PATH, ROUTER_BASE_PATH) | const Server = new server(SOURCE, PORT, HOST, CONFIG_PATH, METADATA_PATH, ROUTER_BASE_PATH) | ||||||
| Server.start() | Server.start() | ||||||
|  | |||||||
							
								
								
									
										5
									
								
								prod.js
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								prod.js
									
									
									
									
									
								
							| @ -1,7 +1,6 @@ | |||||||
| const optionDefinitions = [ | const optionDefinitions = [ | ||||||
|   { name: 'config', alias: 'c', type: String }, |   { name: 'config', alias: 'c', type: String }, | ||||||
|   { name: 'metadata', alias: 'm', type: String }, |   { name: 'metadata', alias: 'm', type: String }, | ||||||
|   { name: 'plugins', alias: 'l', type: String }, |  | ||||||
|   { name: 'port', alias: 'p', type: String }, |   { name: 'port', alias: 'p', type: String }, | ||||||
|   { name: 'host', alias: 'h', type: String }, |   { name: 'host', alias: 'h', type: String }, | ||||||
|   { name: 'source', alias: 's', type: String } |   { name: 'source', alias: 's', type: String } | ||||||
| @ -19,18 +18,16 @@ global.appRoot = __dirname | |||||||
| 
 | 
 | ||||||
| const inputConfig = options.config ? Path.resolve(options.config) : null | const inputConfig = options.config ? Path.resolve(options.config) : null | ||||||
| const inputMetadata = options.metadata ? Path.resolve(options.metadata) : null | const inputMetadata = options.metadata ? Path.resolve(options.metadata) : null | ||||||
| const inputPlugins = options.plugins ? Path.resolve(options.plugins) : null |  | ||||||
| 
 | 
 | ||||||
| const PORT = options.port || process.env.PORT || 3333 | const PORT = options.port || process.env.PORT || 3333 | ||||||
| const HOST = options.host || process.env.HOST | const HOST = options.host || process.env.HOST | ||||||
| const CONFIG_PATH = inputConfig || process.env.CONFIG_PATH || Path.resolve('config') | const CONFIG_PATH = inputConfig || process.env.CONFIG_PATH || Path.resolve('config') | ||||||
| const METADATA_PATH = inputMetadata || process.env.METADATA_PATH || Path.resolve('metadata') | const METADATA_PATH = inputMetadata || process.env.METADATA_PATH || Path.resolve('metadata') | ||||||
| const PLUGINS_PATH = inputPlugins || process.env.PLUGINS_PATH || Path.resolve('plugins') |  | ||||||
| const SOURCE = options.source || process.env.SOURCE || 'debian' | const SOURCE = options.source || process.env.SOURCE || 'debian' | ||||||
| 
 | 
 | ||||||
| const ROUTER_BASE_PATH = process.env.ROUTER_BASE_PATH || '' | const ROUTER_BASE_PATH = process.env.ROUTER_BASE_PATH || '' | ||||||
| 
 | 
 | ||||||
| console.log(process.env.NODE_ENV, 'Config', CONFIG_PATH, METADATA_PATH) | console.log(process.env.NODE_ENV, 'Config', CONFIG_PATH, METADATA_PATH) | ||||||
| 
 | 
 | ||||||
| const Server = new server(SOURCE, PORT, HOST, CONFIG_PATH, METADATA_PATH, PLUGINS_PATH, ROUTER_BASE_PATH) | const Server = new server(SOURCE, PORT, HOST, CONFIG_PATH, METADATA_PATH, ROUTER_BASE_PATH) | ||||||
| Server.start() | Server.start() | ||||||
|  | |||||||
| @ -44,7 +44,7 @@ const expressSession = require('express-session') | |||||||
| const MemoryStore = require('./libs/memorystore') | const MemoryStore = require('./libs/memorystore') | ||||||
| 
 | 
 | ||||||
| class Server { | class Server { | ||||||
|   constructor(SOURCE, PORT, HOST, CONFIG_PATH, METADATA_PATH, PLUGINS_PATH, ROUTER_BASE_PATH) { |   constructor(SOURCE, PORT, HOST, CONFIG_PATH, METADATA_PATH, ROUTER_BASE_PATH) { | ||||||
|     this.Port = PORT |     this.Port = PORT | ||||||
|     this.Host = HOST |     this.Host = HOST | ||||||
|     global.Source = SOURCE |     global.Source = SOURCE | ||||||
| @ -52,7 +52,6 @@ class Server { | |||||||
|     global.ConfigPath = fileUtils.filePathToPOSIX(Path.normalize(CONFIG_PATH)) |     global.ConfigPath = fileUtils.filePathToPOSIX(Path.normalize(CONFIG_PATH)) | ||||||
|     global.MetadataPath = fileUtils.filePathToPOSIX(Path.normalize(METADATA_PATH)) |     global.MetadataPath = fileUtils.filePathToPOSIX(Path.normalize(METADATA_PATH)) | ||||||
|     global.RouterBasePath = ROUTER_BASE_PATH |     global.RouterBasePath = ROUTER_BASE_PATH | ||||||
|     global.PluginsPath = fileUtils.filePathToPOSIX(Path.normalize(PLUGINS_PATH)) |  | ||||||
|     global.XAccel = process.env.USE_X_ACCEL |     global.XAccel = process.env.USE_X_ACCEL | ||||||
|     global.AllowCors = process.env.ALLOW_CORS === '1' |     global.AllowCors = process.env.ALLOW_CORS === '1' | ||||||
|     global.DisableSsrfRequestFilter = process.env.DISABLE_SSRF_REQUEST_FILTER === '1' |     global.DisableSsrfRequestFilter = process.env.DISABLE_SSRF_REQUEST_FILTER === '1' | ||||||
|  | |||||||
| @ -3,6 +3,7 @@ const Logger = require('../Logger') | |||||||
| const Database = require('../Database') | const Database = require('../Database') | ||||||
| const PluginAbstract = require('../PluginAbstract') | const PluginAbstract = require('../PluginAbstract') | ||||||
| const fs = require('fs').promises | const fs = require('fs').promises | ||||||
|  | const fsExtra = require('../libs/fsExtra') | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * @typedef PluginContext |  * @typedef PluginContext | ||||||
| @ -15,6 +16,10 @@ class PluginManager { | |||||||
|     this.plugins = [] |     this.plugins = [] | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   get pluginMetadataPath() { | ||||||
|  |     return Path.posix.join(global.MetadataPath, 'plugins') | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   get pluginData() { |   get pluginData() { | ||||||
|     return this.plugins.map((plugin) => plugin.manifest) |     return this.plugins.map((plugin) => plugin.manifest) | ||||||
|   } |   } | ||||||
| @ -35,7 +40,7 @@ class PluginManager { | |||||||
|    * @returns {Promise<{manifest: Object, contents: PluginAbstract}>} |    * @returns {Promise<{manifest: Object, contents: PluginAbstract}>} | ||||||
|    */ |    */ | ||||||
|   async loadPlugin(pluginPath) { |   async loadPlugin(pluginPath) { | ||||||
|     const pluginFiles = await fs.readdir(pluginPath, { withFileTypes: true }).then((files) => files.filter((file) => !file.isDirectory())) |     const pluginFiles = await fsExtra.readdir(pluginPath, { withFileTypes: true }).then((files) => files.filter((file) => !file.isDirectory())) | ||||||
| 
 | 
 | ||||||
|     if (!pluginFiles.length) { |     if (!pluginFiles.length) { | ||||||
|       Logger.error(`No files found in plugin ${pluginPath}`) |       Logger.error(`No files found in plugin ${pluginPath}`) | ||||||
| @ -54,7 +59,7 @@ class PluginManager { | |||||||
| 
 | 
 | ||||||
|     let manifestJson = null |     let manifestJson = null | ||||||
|     try { |     try { | ||||||
|       manifestJson = await fs.readFile(Path.join(pluginPath, manifestFile.name), 'utf8').then((data) => JSON.parse(data)) |       manifestJson = await fsExtra.readFile(Path.join(pluginPath, manifestFile.name), 'utf8').then((data) => JSON.parse(data)) | ||||||
|     } catch (error) { |     } catch (error) { | ||||||
|       Logger.error(`Error parsing manifest file for plugin ${pluginPath}`, error) |       Logger.error(`Error parsing manifest file for plugin ${pluginPath}`, error) | ||||||
|       return null |       return null | ||||||
| @ -82,11 +87,13 @@ class PluginManager { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async loadPlugins() { |   async loadPlugins() { | ||||||
|     const pluginDirs = await fs.readdir(global.PluginsPath, { withFileTypes: true, recursive: true }).then((files) => files.filter((file) => file.isDirectory())) |     await fsExtra.ensureDir(this.pluginMetadataPath) | ||||||
|  | 
 | ||||||
|  |     const pluginDirs = await fsExtra.readdir(this.pluginMetadataPath, { withFileTypes: true, recursive: true }).then((files) => files.filter((file) => file.isDirectory())) | ||||||
| 
 | 
 | ||||||
|     for (const pluginDir of pluginDirs) { |     for (const pluginDir of pluginDirs) { | ||||||
|       Logger.info(`[PluginManager] Loading plugin ${pluginDir.name}`) |       Logger.info(`[PluginManager] Loading plugin ${pluginDir.name}`) | ||||||
|       const plugin = await this.loadPlugin(Path.join(global.PluginsPath, pluginDir.name)) |       const plugin = await this.loadPlugin(Path.join(this.pluginMetadataPath, pluginDir.name)) | ||||||
|       if (plugin) { |       if (plugin) { | ||||||
|         Logger.info(`[PluginManager] Loaded plugin ${plugin.manifest.name}`) |         Logger.info(`[PluginManager] Loaded plugin ${plugin.manifest.name}`) | ||||||
|         this.plugins.push(plugin) |         this.plugins.push(plugin) | ||||||
| @ -152,7 +159,7 @@ class PluginManager { | |||||||
| 
 | 
 | ||||||
|     try { |     try { | ||||||
|       // Try to load the plugin
 |       // Try to load the plugin
 | ||||||
|       const pluginPath = Path.join(global.PluginsPath, plugin.name) |       const pluginPath = Path.join(this.pluginMetadataPath, plugin.name) | ||||||
|       const packageContents = require(pluginPath) |       const packageContents = require(pluginPath) | ||||||
|       console.log('packageContents', packageContents) |       console.log('packageContents', packageContents) | ||||||
|       packageContents.init() |       packageContents.init() | ||||||
|  | |||||||
							
								
								
									
										0
									
								
								test/server/managers/plugins/readme.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								test/server/managers/plugins/readme.md
									
									
									
									
									
										Normal file
									
								
							
		Loading…
	
		Reference in New Issue
	
	Block a user