mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-02 21:42:52 +00:00
commit
81eba67c3d
25
build.sbt
25
build.sbt
@ -59,6 +59,7 @@ lazy val noPublish = Seq(
|
|||||||
val elmSettings = Seq(
|
val elmSettings = Seq(
|
||||||
elmCompileMode := ElmCompileMode.Debug,
|
elmCompileMode := ElmCompileMode.Debug,
|
||||||
Compile / resourceGenerators += Def.task {
|
Compile / resourceGenerators += Def.task {
|
||||||
|
openapiCodegen.value
|
||||||
compileElm(
|
compileElm(
|
||||||
streams.value.log,
|
streams.value.log,
|
||||||
(Compile / baseDirectory).value,
|
(Compile / baseDirectory).value,
|
||||||
@ -565,6 +566,18 @@ val root = project
|
|||||||
|
|
||||||
// --- Helpers
|
// --- Helpers
|
||||||
|
|
||||||
|
def copyWithGZ(src: File, target: File): Seq[File] = {
|
||||||
|
val gzipFilter = "*.html" || "*.css" || "*.js"
|
||||||
|
IO.copy(Seq(src -> target))
|
||||||
|
if (gzipFilter.accept(src)) {
|
||||||
|
val gz = file(target.toString + ".gz")
|
||||||
|
IO.gzip(src, gz)
|
||||||
|
Seq(target, gz)
|
||||||
|
} else {
|
||||||
|
Seq(target)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def copyWebjarResources(
|
def copyWebjarResources(
|
||||||
src: Seq[File],
|
src: Seq[File],
|
||||||
base: File,
|
base: File,
|
||||||
@ -577,18 +590,16 @@ def copyWebjarResources(
|
|||||||
src.flatMap { dir =>
|
src.flatMap { dir =>
|
||||||
if (dir.isDirectory) {
|
if (dir.isDirectory) {
|
||||||
val files = (dir ** "*").filter(_.isFile).get.pair(Path.relativeTo(dir))
|
val files = (dir ** "*").filter(_.isFile).get.pair(Path.relativeTo(dir))
|
||||||
files.map {
|
files.flatMap {
|
||||||
case (f, name) =>
|
case (f, name) =>
|
||||||
val target = targetDir / name
|
val target = targetDir / name
|
||||||
IO.createDirectories(Seq(target.getParentFile))
|
IO.createDirectories(Seq(target.getParentFile))
|
||||||
IO.copy(Seq(f -> target))
|
copyWithGZ(f, target)
|
||||||
target
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val target = targetDir / dir.name
|
val target = targetDir / dir.name
|
||||||
IO.createDirectories(Seq(target.getParentFile))
|
IO.createDirectories(Seq(target.getParentFile))
|
||||||
IO.copy(Seq(dir -> target))
|
copyWithGZ(dir, target)
|
||||||
Seq(target)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -611,7 +622,9 @@ def compileElm(
|
|||||||
)
|
)
|
||||||
val out = proc.!!
|
val out = proc.!!
|
||||||
logger.info(out)
|
logger.info(out)
|
||||||
Seq(target)
|
val targetGZ = file(target.toString + ".gz")
|
||||||
|
IO.gzip(target, targetGZ)
|
||||||
|
Seq(target, targetGZ)
|
||||||
}
|
}
|
||||||
|
|
||||||
def createWebjarSource(wj: Seq[ModuleID], out: File): Seq[File] = {
|
def createWebjarSource(wj: Seq[ModuleID], out: File): Seq[File] = {
|
||||||
|
@ -1,41 +1,50 @@
|
|||||||
package docspell.restserver.webapp
|
package docspell.restserver.webapp
|
||||||
|
|
||||||
|
import cats.data.Kleisli
|
||||||
|
import cats.data.OptionT
|
||||||
import cats.effect._
|
import cats.effect._
|
||||||
|
|
||||||
import org.http4s.HttpRoutes
|
import org.http4s.HttpRoutes
|
||||||
import org.http4s.server.staticcontent.NoopCacheStrategy
|
import org.http4s.Method
|
||||||
import org.http4s.server.staticcontent.WebjarService.{Config => WebjarConfig, WebjarAsset}
|
import org.http4s.Response
|
||||||
import org.http4s.server.staticcontent.webjarService
|
import org.http4s.StaticFile
|
||||||
|
|
||||||
object WebjarRoutes {
|
object WebjarRoutes {
|
||||||
|
|
||||||
|
private[this] val suffixes = List(
|
||||||
|
".js",
|
||||||
|
".css",
|
||||||
|
".html",
|
||||||
|
".json",
|
||||||
|
".jpg",
|
||||||
|
".png",
|
||||||
|
".eot",
|
||||||
|
".woff",
|
||||||
|
".woff2",
|
||||||
|
".svg",
|
||||||
|
".otf",
|
||||||
|
".ttf",
|
||||||
|
".yml",
|
||||||
|
".xml"
|
||||||
|
)
|
||||||
|
|
||||||
def appRoutes[F[_]: Effect](
|
def appRoutes[F[_]: Effect](
|
||||||
blocker: Blocker
|
blocker: Blocker
|
||||||
)(implicit C: ContextShift[F]): HttpRoutes[F] =
|
)(implicit CS: ContextShift[F]): HttpRoutes[F] =
|
||||||
webjarService(
|
Kleisli {
|
||||||
WebjarConfig(
|
case req if req.method == Method.GET =>
|
||||||
filter = assetFilter,
|
val p = req.pathInfo
|
||||||
blocker = blocker,
|
if (p.contains("..") || !suffixes.exists(p.endsWith(_)))
|
||||||
cacheStrategy = NoopCacheStrategy[F]
|
OptionT.pure(Response.notFound[F])
|
||||||
)
|
else
|
||||||
)
|
StaticFile.fromResource(
|
||||||
|
s"/META-INF/resources/webjars$p",
|
||||||
def assetFilter(asset: WebjarAsset): Boolean =
|
blocker,
|
||||||
List(
|
Some(req),
|
||||||
".js",
|
true
|
||||||
".css",
|
)
|
||||||
".html",
|
case _ =>
|
||||||
".json",
|
OptionT.none
|
||||||
".jpg",
|
}
|
||||||
".png",
|
|
||||||
".eot",
|
|
||||||
".woff",
|
|
||||||
".woff2",
|
|
||||||
".svg",
|
|
||||||
".otf",
|
|
||||||
".ttf",
|
|
||||||
".yml",
|
|
||||||
".xml"
|
|
||||||
).exists(e => asset.asset.endsWith(e))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user