convert game gifs to game embeds in ublog
parent
e3279cdad2
commit
7b23e6cdba
|
@ -132,7 +132,8 @@ object Form {
|
|||
"githubusercontent.com",
|
||||
"googleusercontent.com",
|
||||
"i.ibb.co",
|
||||
"i.postimg.cc"
|
||||
"i.postimg.cc",
|
||||
"lichess1.org"
|
||||
)
|
||||
private val imageDomainRegex = """^(?:https?://)([^/]+)/.{6,}""".r
|
||||
sealed abstract private class Bad(val msg: String)
|
||||
|
|
|
@ -14,7 +14,8 @@ final class Env(
|
|||
ircApi: lila.irc.IrcApi,
|
||||
relationApi: lila.relation.RelationApi,
|
||||
captcher: lila.hub.actors.Captcher,
|
||||
cacheApi: lila.memo.CacheApi
|
||||
cacheApi: lila.memo.CacheApi,
|
||||
net: NetConfig
|
||||
)(implicit
|
||||
ec: scala.concurrent.ExecutionContext
|
||||
) {
|
||||
|
|
|
@ -2,8 +2,9 @@ package lila.ublog
|
|||
|
||||
import scala.concurrent.duration._
|
||||
import lila.common.Chronometer
|
||||
import lila.common.config.NetConfig
|
||||
|
||||
final class UblogMarkup {
|
||||
final class UblogMarkup(net: NetConfig) {
|
||||
|
||||
private val renderer =
|
||||
new lila.common.Markdown(
|
||||
|
@ -16,10 +17,18 @@ final class UblogMarkup {
|
|||
table = true
|
||||
)
|
||||
|
||||
def apply(post: UblogPost): String =
|
||||
cache.get(post.markdown, str => renderer(s"ublog:${post.id}")(replaceGameGifs(str)))
|
||||
|
||||
private val cache = lila.memo.CacheApi.scaffeineNoScheduler
|
||||
.expireAfterAccess(20 minutes)
|
||||
.maximumSize(1024)
|
||||
.build[String, String]()
|
||||
|
||||
def apply(post: UblogPost): String = cache.get(post.markdown, renderer(s"ublog:${post.id}"))
|
||||
private object replaceGameGifs {
|
||||
val regex = {
|
||||
"""!\[[^\]]*\]\(""" + net.assetBaseUrl + """/game/export/gif/(white|black)/(\w{8}).gif\)"""
|
||||
}.r
|
||||
def apply(markdown: String) = regex.replaceAllIn(markdown, net.baseUrl.value + "/$2/$1")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue