Skip to content

Commit

Permalink
feat: add panel get plugins endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
duruer committed May 31, 2024
1 parent 8084ac4 commit 8ab006e
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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()
}
}

0 comments on commit 8ab006e

Please sign in to comment.