convert game gifs to game embeds in ublog

pull/9737/head
Thibault Duplessis 2021-09-05 22:29:17 +02:00
parent e3279cdad2
commit 7b23e6cdba
3 changed files with 15 additions and 4 deletions

View File

@ -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)

View File

@ -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
) {

View File

@ -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")
}
}