From: Lanius Trolling Date: Wed, 14 Dec 2022 22:31:55 +0000 (-0500) Subject: Change Tylan numerals X-Git-Url: https://gitweb.starshipfights.net/?a=commitdiff_plain;h=c6049f543b587999d2ce4b79c89706589d540556;p=factbooks Change Tylan numerals --- diff --git a/build.gradle.kts b/build.gradle.kts index a8ce5c1..ea7c65e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,13 +22,14 @@ dependencies { implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.4.1") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1") - implementation("io.ktor:ktor-server-netty:2.1.3") - implementation("io.ktor:ktor-server-html-builder:2.1.3") + implementation("io.ktor:ktor-server-netty:2.2.1") + implementation("io.ktor:ktor-server-html-builder:2.2.1") - implementation("io.ktor:ktor-server-call-id:2.1.3") - implementation("io.ktor:ktor-server-call-logging:2.1.3") - implementation("io.ktor:ktor-server-forwarded-header:2.1.3") - implementation("io.ktor:ktor-server-status-pages:2.1.3") + implementation("io.ktor:ktor-server-call-id:2.2.1") + implementation("io.ktor:ktor-server-call-logging:2.2.1") + implementation("io.ktor:ktor-server-forwarded-header:2.2.1") + implementation("io.ktor:ktor-server-sessions-jvm:2.2.1") + implementation("io.ktor:ktor-server-status-pages:2.2.1") implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.8.0") diff --git a/src/main/kotlin/info/mechyrdia/Factbooks.kt b/src/main/kotlin/info/mechyrdia/Factbooks.kt index 8f6db51..19dff0e 100644 --- a/src/main/kotlin/info/mechyrdia/Factbooks.kt +++ b/src/main/kotlin/info/mechyrdia/Factbooks.kt @@ -1,3 +1,5 @@ +@file:JvmName("Factbooks") + package info.mechyrdia import info.mechyrdia.lore.* @@ -15,100 +17,112 @@ import io.ktor.server.plugins.statuspages.* import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.* +import io.ktor.server.sessions.* +import io.ktor.util.* import org.slf4j.event.Level import java.io.File import java.io.IOException import java.util.concurrent.atomic.AtomicLong -object Factbooks { - @JvmStatic - fun main(args: Array) { - System.setProperty("logback.statusListenerClass", "ch.qos.logback.core.status.NopStatusListener") +fun main() { + System.setProperty("logback.statusListenerClass", "ch.qos.logback.core.status.NopStatusListener") + + System.setProperty("io.ktor.development", "false") + + embeddedServer(Netty, port = Configuration.CurrentConfiguration.port, host = Configuration.CurrentConfiguration.host, module = Application::factbooks).start(wait = true) +} + +fun Application.factbooks() { + install(IgnoreTrailingSlash) + install(XForwardedHeaders) + + install(CallId) { + val counter = AtomicLong(0) + generate { + "call-${counter.incrementAndGet().toULong()}-${System.currentTimeMillis()}" + } + } + + install(CallLogging) { + level = Level.INFO - System.setProperty("io.ktor.development", "false") + callIdMdc("ktor-call-id") - embeddedServer(Netty, port = Configuration.CurrentConfiguration.port, host = Configuration.CurrentConfiguration.host) { - install(IgnoreTrailingSlash) - install(XForwardedHeaders) - - install(CallId) { - val counter = AtomicLong(0) - generate { - "call-${counter.incrementAndGet().toULong()}-${System.currentTimeMillis()}" - } - } - - install(CallLogging) { - level = Level.INFO - - callIdMdc("ktor-call-id") - - format { call -> - "Call #${call.callId} Client ${call.request.origin.remoteHost} `${call.request.userAgent()}` Request ${call.request.httpMethod.value} ${call.request.uri} Response ${call.response.status()}" - } - } + format { call -> + "Call #${call.callId} Client ${call.request.origin.remoteHost} `${call.request.userAgent()}` Request ${call.request.httpMethod.value} ${call.request.uri} Response ${call.response.status()}" + } + } + + /* + install(Sessions) { + cookie("USER_SESSION", SessionStorageMongoDB()) { + identity { Id().id } - install(StatusPages) { - status(HttpStatusCode.NotFound) { call, _ -> - call.respondHtml(HttpStatusCode.NotFound, call.error404()) - } - - exception { call, (url, permanent) -> - call.respondRedirect(url, permanent) - } - exception { call, _ -> - call.respondHtml(HttpStatusCode.BadRequest, call.error400()) - } - exception { call, _ -> - call.respondHtml(HttpStatusCode.NotFound, call.error404()) - } - exception { call, _ -> - call.respondHtml(HttpStatusCode.NotFound, call.error404()) - } - - exception { call, ex -> - call.application.log.error("Got uncaught exception from serving call ${call.callId}", ex) - - call.respondHtml(HttpStatusCode.InternalServerError, call.error500()) - throw ex - } - } + cookie.extensions["SameSite"] = "lax" + cookie.extensions["Secure"] = null + } + } + */ + + install(StatusPages) { + status(HttpStatusCode.NotFound) { call, _ -> + call.respondHtml(HttpStatusCode.NotFound, call.error404()) + } + + exception { call, (url, permanent) -> + call.respondRedirect(url, permanent) + } + exception { call, _ -> + call.respondHtml(HttpStatusCode.BadRequest, call.error400()) + } + exception { call, _ -> + call.respondHtml(HttpStatusCode.NotFound, call.error404()) + } + exception { call, _ -> + call.respondHtml(HttpStatusCode.NotFound, call.error404()) + } + + exception { call, ex -> + call.application.log.error("Got uncaught exception from serving call ${call.callId}", ex) - routing { - get("/") { - redirect("/lore") - } - - static("/static") { - resources("static") - } - - get("/lore/{path...}") { - call.respondHtml(HttpStatusCode.OK, call.loreArticlePage()) - } - - static("/assets") { - files(File(Configuration.CurrentConfiguration.assetDir)) - } - - get("/change-theme") { - call.respondHtml(HttpStatusCode.OK, call.changeThemePage()) - } - - post("/change-theme") { - val newTheme = when (call.receiveParameters()["theme"]) { - "light" -> "light" - "dark" -> "dark" - else -> "system" - } - call.response.cookies.append("factbook-theme", newTheme, maxAge = Int.MAX_VALUE.toLong()) - redirect("/lore") - } - - post("/tylan-lang") { - call.respondText(TylanAlphabet.tylanToFontAlphabet(call.receiveText())) - } + call.respondHtml(HttpStatusCode.InternalServerError, call.error500()) + throw ex + } + } + + routing { + get("/") { + redirect("/lore") + } + + static("/static") { + resources("static") + } + + get("/lore/{path...}") { + call.respondHtml(HttpStatusCode.OK, call.loreArticlePage()) + } + + static("/assets") { + files(File(Configuration.CurrentConfiguration.assetDir)) + } + + get("/change-theme") { + call.respondHtml(HttpStatusCode.OK, call.changeThemePage()) + } + + post("/change-theme") { + val newTheme = when (call.receiveParameters()["theme"]) { + "light" -> "light" + "dark" -> "dark" + else -> "system" } - }.start(wait = true) + call.response.cookies.append("factbook-theme", newTheme, maxAge = Int.MAX_VALUE.toLong()) + redirect("/lore") + } + + post("/tylan-lang") { + call.respondText(TylanAlphabet.tylanToFontAlphabet(call.receiveText())) + } } } diff --git a/src/main/kotlin/info/mechyrdia/lore/tylan_language.kt b/src/main/kotlin/info/mechyrdia/lore/tylan_language.kt index 2d0bb12..1a88a51 100644 --- a/src/main/kotlin/info/mechyrdia/lore/tylan_language.kt +++ b/src/main/kotlin/info/mechyrdia/lore/tylan_language.kt @@ -11,6 +11,9 @@ object TylanAlphabet { ) private val replacements = listOf( + Regex("([0-9xy]+)(?!\\s)") to "$1 ", + Regex("(?