diff --git a/Pano/src/main/kotlin/com/panomc/platform/route/api/panel/PanelGetPluginsAPI.kt b/Pano/src/main/kotlin/com/panomc/platform/route/api/panel/PanelGetPluginsAPI.kt new file mode 100755 index 00000000..98f967bb --- /dev/null +++ b/Pano/src/main/kotlin/com/panomc/platform/route/api/panel/PanelGetPluginsAPI.kt @@ -0,0 +1,44 @@ +package com.panomc.platform.route.api.panel + +import com.panomc.platform.PanoPluginWrapper +import com.panomc.platform.PluginManager +import com.panomc.platform.annotation.Endpoint +import com.panomc.platform.model.* +import io.vertx.ext.web.RoutingContext +import io.vertx.json.schema.SchemaParser +import java.io.PrintWriter +import java.io.StringWriter + +@Endpoint +class PanelGetPluginsAPI( + private val pluginManager: PluginManager +) : Api() { + override val paths = listOf(Path("/api/panel/plugins", RouteType.GET)) + + override fun getValidationHandler(schemaParser: SchemaParser) = null + + override suspend fun handle(context: RoutingContext): Result { + val result = mutableMapOf( + "plugins" to pluginManager.plugins.map { it as PanoPluginWrapper }.associate { + it.pluginId to mapOf( + "author" to it.descriptor.provider, + "version" to it.descriptor.version, + "status" to it.pluginState, + "dependencies" to it.descriptor.dependencies, + "license" to it.descriptor.license, + "error" to if (it.failedException == null) null else getStackTraceAsString(it.failedException), + "hash" to it.hash + ) + } + ) + + return Successful(result) + } + + private fun getStackTraceAsString(exception: Throwable): String { + val stringWriter = StringWriter() + val printWriter = PrintWriter(stringWriter) + exception.printStackTrace(printWriter) + return stringWriter.toString() + } +} \ No newline at end of file