mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-02-03 16:59:41 +00:00
Remove separate plugins dir and use metadata dir for plugins folder
This commit is contained in:
parent
ad89fb2eac
commit
23b480b11a
5 changed files with 15 additions and 14 deletions
|
|
@ -44,7 +44,7 @@ const expressSession = require('express-session')
|
|||
const MemoryStore = require('./libs/memorystore')
|
||||
|
||||
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.Host = HOST
|
||||
global.Source = SOURCE
|
||||
|
|
@ -52,7 +52,6 @@ class Server {
|
|||
global.ConfigPath = fileUtils.filePathToPOSIX(Path.normalize(CONFIG_PATH))
|
||||
global.MetadataPath = fileUtils.filePathToPOSIX(Path.normalize(METADATA_PATH))
|
||||
global.RouterBasePath = ROUTER_BASE_PATH
|
||||
global.PluginsPath = fileUtils.filePathToPOSIX(Path.normalize(PLUGINS_PATH))
|
||||
global.XAccel = process.env.USE_X_ACCEL
|
||||
global.AllowCors = process.env.ALLOW_CORS === '1'
|
||||
global.DisableSsrfRequestFilter = process.env.DISABLE_SSRF_REQUEST_FILTER === '1'
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ const Logger = require('../Logger')
|
|||
const Database = require('../Database')
|
||||
const PluginAbstract = require('../PluginAbstract')
|
||||
const fs = require('fs').promises
|
||||
const fsExtra = require('../libs/fsExtra')
|
||||
|
||||
/**
|
||||
* @typedef PluginContext
|
||||
|
|
@ -15,6 +16,10 @@ class PluginManager {
|
|||
this.plugins = []
|
||||
}
|
||||
|
||||
get pluginMetadataPath() {
|
||||
return Path.posix.join(global.MetadataPath, 'plugins')
|
||||
}
|
||||
|
||||
get pluginData() {
|
||||
return this.plugins.map((plugin) => plugin.manifest)
|
||||
}
|
||||
|
|
@ -35,7 +40,7 @@ class PluginManager {
|
|||
* @returns {Promise<{manifest: Object, contents: PluginAbstract}>}
|
||||
*/
|
||||
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) {
|
||||
Logger.error(`No files found in plugin ${pluginPath}`)
|
||||
|
|
@ -54,7 +59,7 @@ class PluginManager {
|
|||
|
||||
let manifestJson = null
|
||||
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) {
|
||||
Logger.error(`Error parsing manifest file for plugin ${pluginPath}`, error)
|
||||
return null
|
||||
|
|
@ -82,11 +87,13 @@ class PluginManager {
|
|||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
Logger.info(`[PluginManager] Loaded plugin ${plugin.manifest.name}`)
|
||||
this.plugins.push(plugin)
|
||||
|
|
@ -152,7 +159,7 @@ class PluginManager {
|
|||
|
||||
try {
|
||||
// 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)
|
||||
console.log('packageContents', packageContents)
|
||||
packageContents.init()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue