print game to PDF, stream it as chunked HTTP and cache it in CDN
parent
458e389887
commit
8717264ae0
|
@ -10,3 +10,6 @@
|
||||||
[submodule "public/staunton"]
|
[submodule "public/staunton"]
|
||||||
path = public/staunton
|
path = public/staunton
|
||||||
url = https://github.com/clarkerubber/Staunton-Pieces
|
url = https://github.com/clarkerubber/Staunton-Pieces
|
||||||
|
[submodule "submodules/pdfexporter"]
|
||||||
|
path = submodules/pdfexporter
|
||||||
|
url = https://github.com/clarkerubber/lichessPDFExporter
|
||||||
|
|
|
@ -6,6 +6,7 @@ import akka.pattern.ask
|
||||||
import play.api.http.ContentTypes
|
import play.api.http.ContentTypes
|
||||||
import play.api.mvc._
|
import play.api.mvc._
|
||||||
import play.twirl.api.Html
|
import play.twirl.api.Html
|
||||||
|
import play.api.libs.iteratee.{ Iteratee, Enumerator }
|
||||||
|
|
||||||
import lila.analyse.{ Analysis, TimeChart, AdvantageChart }
|
import lila.analyse.{ Analysis, TimeChart, AdvantageChart }
|
||||||
import lila.api.Context
|
import lila.api.Context
|
||||||
|
@ -92,6 +93,13 @@ object Analyse extends LilaController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def pdf(id: String) = Open { implicit ctx =>
|
||||||
|
OptionResult(GameRepo game id) { game =>
|
||||||
|
Ok.chunked(Enumerator.outputStream(Env.game.pdfExport(game.id))).withHeaders(
|
||||||
|
CONTENT_TYPE -> ContentTypes.withCharset("application/pdf"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private def gameOpening(game: GameModel) =
|
private def gameOpening(game: GameModel) =
|
||||||
if (game.fromPosition || game.variant.exotic) none
|
if (game.fromPosition || game.variant.exotic) none
|
||||||
else chess.OpeningExplorer openingOf game.pgnMoves
|
else chess.OpeningExplorer openingOf game.pgnMoves
|
||||||
|
|
|
@ -138,6 +138,8 @@ POST /$gameId<\w{8}>/better-analysis/$color<white|black> controllers.Analyse.be
|
||||||
POST /$gameId<\w{8}>/post-analysis controllers.Analyse.postAnalysis(gameId: String)
|
POST /$gameId<\w{8}>/post-analysis controllers.Analyse.postAnalysis(gameId: String)
|
||||||
GET /$gameId<\w{8}>/pgn controllers.Analyse.pgn(gameId: String)
|
GET /$gameId<\w{8}>/pgn controllers.Analyse.pgn(gameId: String)
|
||||||
|
|
||||||
|
GET /game/pdf/$gameId<\w{8}> controllers.Analyse.pdf(gameId: String)
|
||||||
|
|
||||||
# Pref
|
# Pref
|
||||||
POST /pref/:name controllers.Pref.set(name: String)
|
POST /pref/:name controllers.Pref.set(name: String)
|
||||||
GET /account/preferences controllers.Pref.form
|
GET /account/preferences controllers.Pref.form
|
||||||
|
|
|
@ -28,6 +28,7 @@ final class Env(
|
||||||
val ActorName = config getString "actor.name"
|
val ActorName = config getString "actor.name"
|
||||||
val UciMemoTtl = config duration "uci_memo.ttl"
|
val UciMemoTtl = config duration "uci_memo.ttl"
|
||||||
val netBaseUrl = config getString "net.base_url"
|
val netBaseUrl = config getString "net.base_url"
|
||||||
|
val PdfExecPath = config getString "pdf.exec_path"
|
||||||
}
|
}
|
||||||
import settings._
|
import settings._
|
||||||
|
|
||||||
|
@ -35,6 +36,8 @@ final class Env(
|
||||||
|
|
||||||
private[game] lazy val gameColl = db(CollectionGame)
|
private[game] lazy val gameColl = db(CollectionGame)
|
||||||
|
|
||||||
|
lazy val pdfExport = PdfExport(PdfExecPath) _
|
||||||
|
|
||||||
lazy val cached = new Cached(ttl = CachedNbTtl)
|
lazy val cached = new Cached(ttl = CachedNbTtl)
|
||||||
|
|
||||||
lazy val paginator = new PaginatorBuilder(
|
lazy val paginator = new PaginatorBuilder(
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package lila.game
|
||||||
|
|
||||||
|
import java.io.{ File, OutputStream }
|
||||||
|
import scala.sys.process._
|
||||||
|
|
||||||
|
object PdfExport {
|
||||||
|
|
||||||
|
private val logger = ProcessLogger(_ => (), _ => ())
|
||||||
|
|
||||||
|
def apply(execPath: String)(id: String)(out: OutputStream) {
|
||||||
|
val exec = Process(Seq("php", "main.php", id), new File(execPath))
|
||||||
|
exec #> out ! logger
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,6 +22,7 @@ final class Env(
|
||||||
val CollectionTranslation = config getString "collection.translation"
|
val CollectionTranslation = config getString "collection.translation"
|
||||||
val ContextGitUrl = config getString "context.git.url"
|
val ContextGitUrl = config getString "context.git.url"
|
||||||
val ContextGitFile = config getString "context.git.file"
|
val ContextGitFile = config getString "context.git.file"
|
||||||
|
val CdnDomain = config getString "cdn_domain"
|
||||||
}
|
}
|
||||||
import settings._
|
import settings._
|
||||||
|
|
||||||
|
@ -40,7 +41,10 @@ final class Env(
|
||||||
|
|
||||||
lazy val keys = new I18nKeys(translator)
|
lazy val keys = new I18nKeys(translator)
|
||||||
|
|
||||||
lazy val requestHandler = new I18nRequestHandler(pool, RequestHandlerProtocol)
|
lazy val requestHandler = new I18nRequestHandler(
|
||||||
|
pool,
|
||||||
|
RequestHandlerProtocol,
|
||||||
|
CdnDomain)
|
||||||
|
|
||||||
lazy val jsDump = new JsDump(
|
lazy val jsDump = new JsDump(
|
||||||
path = appPath + "/" + WebPathRelative,
|
path = appPath + "/" + WebPathRelative,
|
||||||
|
|
|
@ -6,12 +6,18 @@ import play.api.mvc.{ Action, RequestHeader, Handler }
|
||||||
|
|
||||||
import lila.common.HTTPRequest
|
import lila.common.HTTPRequest
|
||||||
|
|
||||||
final class I18nRequestHandler(pool: I18nPool, protocol: String) {
|
final class I18nRequestHandler(
|
||||||
|
pool: I18nPool,
|
||||||
|
protocol: String,
|
||||||
|
cdnDomain: String) {
|
||||||
|
|
||||||
def apply(req: RequestHeader): Option[Handler] =
|
def apply(req: RequestHeader): Option[Handler] =
|
||||||
(HTTPRequest.isRedirectable(req) && !pool.domainLang(req).isDefined) option Action {
|
(HTTPRequest.isRedirectable(req) &&
|
||||||
Redirect(redirectUrl(req))
|
!pool.domainLang(req).isDefined &&
|
||||||
}
|
req.host != cdnDomain
|
||||||
|
) option Action {
|
||||||
|
Redirect(redirectUrl(req))
|
||||||
|
}
|
||||||
|
|
||||||
private def redirectUrl(req: RequestHeader) =
|
private def redirectUrl(req: RequestHeader) =
|
||||||
protocol +
|
protocol +
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 8d6c9550432ce462e4e977a770751354da097cf4
|
Loading…
Reference in New Issue