mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-15 09:55:49 +01:00
Add image API for plug-in
This commit is contained in:
0
etc/deploy-assemby-jar.sh
Normal file → Executable file
0
etc/deploy-assemby-jar.sh
Normal file → Executable file
10
src/main/scala/plugin/Images.scala
Normal file
10
src/main/scala/plugin/Images.scala
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package plugin
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a helper method to generate data URI of images registered by plug-in.
|
||||||
|
*/
|
||||||
|
object Images {
|
||||||
|
|
||||||
|
def dataURI(id: String) = s"data:image/png;base64,${PluginRegistry().getImage(id)}"
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,16 +1,19 @@
|
|||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import java.io.{FilenameFilter, File}
|
import java.io.{InputStream, FilenameFilter, File}
|
||||||
import java.net.URLClassLoader
|
import java.net.URLClassLoader
|
||||||
import javax.servlet.ServletContext
|
import javax.servlet.ServletContext
|
||||||
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
|
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
|
||||||
|
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
import org.apache.commons.codec.binary.{StringUtils, Base64}
|
||||||
import service.RepositoryService.RepositoryInfo
|
import service.RepositoryService.RepositoryInfo
|
||||||
import util.Directory._
|
import util.Directory._
|
||||||
import util.JDBCUtil._
|
import util.JDBCUtil._
|
||||||
|
import util.ControlUtil._
|
||||||
import util.{Version, Versions}
|
import util.{Version, Versions}
|
||||||
|
|
||||||
|
import scala.collection.mutable
|
||||||
import scala.collection.mutable.ListBuffer
|
import scala.collection.mutable.ListBuffer
|
||||||
import app.{ControllerBase, Context}
|
import app.{ControllerBase, Context}
|
||||||
|
|
||||||
@@ -19,6 +22,7 @@ class PluginRegistry {
|
|||||||
private val plugins = new ListBuffer[PluginInfo]
|
private val plugins = new ListBuffer[PluginInfo]
|
||||||
private val javaScripts = new ListBuffer[(String, String)]
|
private val javaScripts = new ListBuffer[(String, String)]
|
||||||
private val controllers = new ListBuffer[(ControllerBase, String)]
|
private val controllers = new ListBuffer[(ControllerBase, String)]
|
||||||
|
private val images = mutable.Map[String, String]()
|
||||||
|
|
||||||
def addPlugin(pluginInfo: PluginInfo): Unit = {
|
def addPlugin(pluginInfo: PluginInfo): Unit = {
|
||||||
plugins += pluginInfo
|
plugins += pluginInfo
|
||||||
@@ -26,6 +30,18 @@ class PluginRegistry {
|
|||||||
|
|
||||||
def getPlugins(): List[PluginInfo] = plugins.toList
|
def getPlugins(): List[PluginInfo] = plugins.toList
|
||||||
|
|
||||||
|
def addImage(id: String, in: InputStream): Unit = {
|
||||||
|
val bytes = using(in){ in =>
|
||||||
|
val bytes = new Array[Byte](in.available)
|
||||||
|
in.read(bytes)
|
||||||
|
bytes
|
||||||
|
}
|
||||||
|
val encoded = StringUtils.newStringUtf8(Base64.encodeBase64(bytes, false))
|
||||||
|
images += ((id, encoded))
|
||||||
|
}
|
||||||
|
|
||||||
|
def getImage(id: String): String = images(id)
|
||||||
|
|
||||||
def addController(controller: ControllerBase, path: String): Unit = {
|
def addController(controller: ControllerBase, path: String): Unit = {
|
||||||
controllers += ((controller, path))
|
controllers += ((controller, path))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user