mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	Add check for server plugin id clash
This commit is contained in:
		| @@ -5,6 +5,12 @@ const express = require('express'); | |||||||
| const { getConfigValue } = require('./util'); | const { getConfigValue } = require('./util'); | ||||||
| const enableServerPlugins = getConfigValue('enableServerPlugins', false); | const enableServerPlugins = getConfigValue('enableServerPlugins', false); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Map of loaded plugins. | ||||||
|  |  * @type {Map<string, any>} | ||||||
|  |  */ | ||||||
|  | const loadedPlugins = new Map(); | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Determine if a file is a CommonJS module. |  * Determine if a file is a CommonJS module. | ||||||
|  * @param {string} file Path to file |  * @param {string} file Path to file | ||||||
| @@ -186,11 +192,18 @@ async function initPlugin(app, plugin, exitHooks) { | |||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     if (loadedPlugins.has(id)) { | ||||||
|  |         console.error(`Failed to load plugin module; plugin ID '${id}' is already in use`); | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     // Allow the plugin to register API routes under /api/plugins/[plugin ID] via a router |     // Allow the plugin to register API routes under /api/plugins/[plugin ID] via a router | ||||||
|     const router = express.Router(); |     const router = express.Router(); | ||||||
|  |  | ||||||
|     await plugin.init(router); |     await plugin.init(router); | ||||||
|  |  | ||||||
|  |     loadedPlugins.set(id, plugin); | ||||||
|  |  | ||||||
|     // Add API routes to the app if the plugin registered any |     // Add API routes to the app if the plugin registered any | ||||||
|     if (router.stack.length > 0) { |     if (router.stack.length > 0) { | ||||||
|         app.use(`/api/plugins/${id}`, router); |         app.use(`/api/plugins/${id}`, router); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user