-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add panel get plugins endpoint
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
Pano/src/main/kotlin/com/panomc/platform/route/api/panel/PanelGetPluginsAPI.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |