update deps, bye icanhazepoch

This commit is contained in:
creeper123123321 2022-10-09 12:30:39 -03:00
parent 64bc013ed3
commit 4f87550ee8
4 changed files with 36 additions and 25 deletions

View File

@ -1,3 +1,5 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer
import com.google.javascript.jscomp.CompilerOptions.LanguageMode
import com.googlecode.htmlcompressor.compressor.HtmlCompressor
import org.gradlewebtools.minify.minifier.js.JsMinifier
@ -13,7 +15,7 @@ buildscript {
plugins {
`java-library`
application
kotlin("jvm") version "1.7.10"
kotlin("jvm") version "1.7.20"
id("maven-publish")
id("com.github.ben-manes.versions") version "0.42.0"
id("com.github.johnrengelman.shadow") version "7.1.2"
@ -91,7 +93,7 @@ dependencies {
implementation("org.jline:jline-terminal-jansi:3.21.0")
implementation("org.slf4j:slf4j-api:$slf4jVer")
val ktorVersion = "2.1.0"
val ktorVersion = "2.1.2"
implementation("io.ktor:ktor-network-tls-certificates-jvm:$ktorVersion")
implementation("io.ktor:ktor-server-websockets:$ktorVersion")
implementation("io.ktor:ktor-server-netty-jvm:$ktorVersion")
@ -117,9 +119,9 @@ run.standardInput = System.`in`
project.configurations.implementation.get().isCanBeResolved = true
tasks {
named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
named<ShadowJar>("shadowJar") {
configurations = listOf(project.configurations.implementation.get())
transform(com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer::class.java)
transform(Log4j2PluginsCacheFileTransformer::class.java)
}
build {
dependsOn(shadowJar)

View File

@ -1,6 +1,7 @@
package com.viaversion.aas.web
import io.ktor.http.*
import io.ktor.http.content.*
import io.ktor.serialization.gson.*
import io.ktor.server.http.content.*
import io.ktor.server.application.*
@ -8,7 +9,7 @@ import io.ktor.server.plugins.*
import io.ktor.server.plugins.cachingheaders.*
import io.ktor.server.plugins.callloging.*
import io.ktor.server.plugins.compression.*
import io.ktor.server.plugins.conditionalheaders.*
import io.ktor.server.plugins.contentnegotiation.*
import io.ktor.server.plugins.defaultheaders.*
import io.ktor.server.plugins.forwardedheaders.*
import io.ktor.server.plugins.partialcontent.*
@ -27,12 +28,6 @@ import java.time.Duration
class ViaWebApp(val viaWebServer: WebServer) {
fun Application.main() {
install(DefaultHeaders)
install(ConditionalHeaders)
install(CachingHeaders) {
options { _, _ ->
io.ktor.http.content.CachingOptions(CacheControl.MaxAge(600, visibility = CacheControl.Visibility.Public))
}
}
install(CallLogging) {
level = Level.DEBUG
this.format {
@ -48,19 +43,27 @@ class ViaWebApp(val viaWebServer: WebServer) {
}
install(XForwardedHeaders)
install(ForwardedHeaders)
// i think we aren't vulnerable to breach, dynamic things are websockets
// https://ktor.io/docs/compression.html#security
install(Compression)
install(PartialContent)
install(ContentNegotiation) {
gson()
}
routing {
routeStatic()
routeWs()
routeApi()
}
}
private fun Route.routeStatic() {
static {
static("/") {
// https://ktor.io/docs/compression.html#security
install(Compression)
install(CachingHeaders) {
options { _, _ ->
CachingOptions(CacheControl.MaxAge(600, visibility = CacheControl.Visibility.Public))
}
}
//install(ConditionalHeaders) https://youtrack.jetbrains.com/issue/KTOR-4943/
install(PartialContent)
get("{path...}") {
val relativePath = Path.of(call.parameters.getAll("path")?.joinToString("/") ?: "")
val index = Path.of("index.html")
@ -101,4 +104,10 @@ class ViaWebApp(val viaWebServer: WebServer) {
}
}
}
private fun Route.routeApi() {
get("/api/getEpoch") {
call.respond(System.currentTimeMillis() / 1000)
}
}
}

View File

@ -309,10 +309,10 @@ async function getIpAddress(cors) {
.then(it => it.trim());
}
function getNetworkTimestamp() {
return fetch("https://icanhazepoch.com")
return fetch("/api/getEpoch", { "headers": { "accept": "application/json" } })
.then(checkFetchSuccess("code"))
.then(r => r.text())
.then(it => parseInt(it.trim()));
.then(r => r.json())
.then(it => parseInt(it));
}
let notificationCallbacks = new Map();
$(() => {

View File

@ -332,11 +332,11 @@ async function getIpAddress(cors: boolean): Promise<string> {
.then(it => it.trim());
}
function getNetworkTimestamp() {
return fetch("https://icanhazepoch.com")
function getNetworkTimestamp(): Promise<number> {
return fetch("/api/getEpoch", {"headers": {"accept": "application/json"}})
.then(checkFetchSuccess("code"))
.then(r => r.text())
.then(it => parseInt(it.trim()))
.then(r => r.json())
.then(it => parseInt(it))
}
// Notification
@ -686,7 +686,7 @@ function removeToken(token: string) {
function getTokens(): Array<string> {
let serialized = localStorage.getItem("viaaas_tokens");
let parsed = serialized? JSON.parse(serialized) : {};
let parsed = serialized ? JSON.parse(serialized) : {};
return parsed[wsUrl] || [];
}