mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 22:45:51 +01:00
Add prototype of global action support
This commit is contained in:
@@ -13,6 +13,8 @@ import org.eclipse.jgit.api.Git
|
||||
import util.Directory
|
||||
import plugin._
|
||||
|
||||
import scala.slick.jdbc.meta.MBestRowIdentifierColumn.Scope.Session
|
||||
|
||||
object AutoUpdate {
|
||||
|
||||
/**
|
||||
@@ -103,8 +105,10 @@ object AutoUpdate {
|
||||
conn.update("UPDATE ACTIVITY SET ADDITIONAL_INFO = ? WHERE ACTIVITY_ID = ?", newInfo, rs.getInt("ACTIVITY_ID"))
|
||||
}
|
||||
}
|
||||
FileUtils.deleteDirectory(Directory.getPluginCacheDir())
|
||||
FileUtils.deleteDirectory(new File(Directory.PluginHome))
|
||||
ignore {
|
||||
FileUtils.deleteDirectory(Directory.getPluginCacheDir())
|
||||
//FileUtils.deleteDirectory(new File(Directory.PluginHome))
|
||||
}
|
||||
}
|
||||
},
|
||||
new Version(2, 2),
|
||||
@@ -235,10 +239,12 @@ class AutoUpdateListener extends ServletContextListener {
|
||||
}
|
||||
}
|
||||
logger.debug("End schema update")
|
||||
|
||||
// Load plugins
|
||||
|
||||
PluginRegistry.initialize(conn)
|
||||
}
|
||||
|
||||
// Load plugins
|
||||
PluginRegistry.initialize()
|
||||
}
|
||||
|
||||
def contextDestroyed(sce: ServletContextEvent): Unit = {
|
||||
|
||||
38
src/main/scala/servlet/PluginActionFilter.scala
Normal file
38
src/main/scala/servlet/PluginActionFilter.scala
Normal file
@@ -0,0 +1,38 @@
|
||||
package servlet
|
||||
|
||||
import javax.servlet._
|
||||
import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
|
||||
|
||||
import play.twirl.api.Html
|
||||
import plugin.PluginRegistry
|
||||
|
||||
class PluginActionFilter extends Filter {
|
||||
|
||||
def init(config: FilterConfig) = {}
|
||||
|
||||
def destroy(): Unit = {}
|
||||
|
||||
def doFilter(req: ServletRequest, res: ServletResponse, chain: FilterChain): Unit = (req, res) match {
|
||||
case (req: HttpServletRequest, res: HttpServletResponse) => {
|
||||
val method = req.getMethod.toLowerCase
|
||||
val path = req.getRequestURI.substring(req.getContextPath.length)
|
||||
val registry = PluginRegistry()
|
||||
registry.getGlobalAction(method, path).map { action =>
|
||||
action(req, res) match {
|
||||
// TODO to be type classes?
|
||||
case x: String =>
|
||||
res.setContentType("text/plain; charset=UTF-8")
|
||||
res.getWriter.write(x)
|
||||
res.getWriter.flush()
|
||||
case x: Html =>
|
||||
res.setContentType("text/html; charset=UTF-8")
|
||||
res.getWriter.write(x.body)
|
||||
res.getWriter.flush()
|
||||
}
|
||||
}.getOrElse {
|
||||
chain.doFilter(req, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user