Generate stuff automatically

This commit is contained in:
carbotaniuman 2020-07-04 14:00:59 -05:00
parent 372e136560
commit e481527fb3
7 changed files with 77 additions and 97 deletions

2
.gitignore vendored
View file

@ -106,4 +106,4 @@ nbproject/**
log/** log/**
cache/** cache/**
dev settings.json

View file

@ -54,60 +54,25 @@ java {
spotless { spotless {
java { java {
indentWithSpaces(4) targetExclude("build/generated/**/*")
eclipse() eclipse()
removeUnusedImports() removeUnusedImports()
trimTrailingWhitespace() trimTrailingWhitespace()
endWithNewline() endWithNewline()
} }
kotlin { kotlin {
indentWithSpaces(4)
ktlint() ktlint()
trimTrailingWhitespace() trimTrailingWhitespace()
endWithNewline() endWithNewline()
} }
} }
run { tasks.register("generateVersion", Copy) {
args = ["dev/settings.json"] def templateContext = [version: version]
inputs.properties templateContext
from "src/template/java"
into "$buildDir/generated/java"
expand templateContext
} }
tasks.register("depsize") { sourceSets.main.java.srcDir generateVersion.outputs.files
description = "Prints dependencies for 'default' configuration"
doLast() {
listConfigurationDependencies(configurations.default)
}
}
tasks.register("depsize-all-configurations") {
description = "Prints dependencies for all available configurations"
doLast() {
configurations.each {
if (it.isCanBeResolved()) {
listConfigurationDependencies(it)
}
}
}
}
def listConfigurationDependencies(Configuration configuration) {
def formatStr = "%,10.2f"
def size = configuration.collect { it.length() / (1024 * 1024) }.sum()
def out = new StringBuffer()
out << "\nConfiguration name: \"${configuration.name}\"\n"
if (size) {
out << "Total dependencies size:".padRight(65)
out << "${String.format(formatStr, size)} Mb\n\n"
configuration.sort { -it.length() }
.each {
out << "${it.name}".padRight(65)
out << "${String.format(formatStr, (it.length() / 1024))} kb\n"
}
} else {
out << "No dependencies found";
}
println(out)
}

View file

@ -22,7 +22,6 @@ import java.time.Duration
object Constants { object Constants {
const val CLIENT_BUILD = 14 const val CLIENT_BUILD = 14
const val CLIENT_VERSION = "1.1.1"
const val WEBUI_VERSION = "0.1.1" const val WEBUI_VERSION = "0.1.1"
val MAX_AGE_CACHE: Duration = Duration.ofDays(14) val MAX_AGE_CACHE: Duration = Duration.ofDays(14)

View file

@ -31,6 +31,7 @@ import java.io.FileWriter
import java.io.IOException import java.io.IOException
import java.util.regex.Pattern import java.util.regex.Pattern
import kotlin.system.exitProcess import kotlin.system.exitProcess
import mdnet.BuildInfo
import mdnet.base.settings.ClientSettings import mdnet.base.settings.ClientSettings
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
@ -41,7 +42,7 @@ object Main {
@JvmStatic @JvmStatic
fun main(args: Array<String>) { fun main(args: Array<String>) {
println( println(
"Mangadex@Home Client Version ${Constants.CLIENT_VERSION} (Build ${Constants.CLIENT_BUILD}) initializing" "Mangadex@Home Client Version ${BuildInfo.VERSION} (Build ${Constants.CLIENT_BUILD}) initializing"
) )
println() println()
println("Copyright (c) 2020, MangaDex Network") println("Copyright (c) 2020, MangaDex Network")

View file

@ -19,6 +19,7 @@ along with this MangaDex@Home. If not, see <http://www.gnu.org/licenses/>.
/* ktlint-disable no-wildcard-imports */ /* ktlint-disable no-wildcard-imports */
package mdnet.base.server package mdnet.base.server
import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.databind.DeserializationFeature import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
@ -107,7 +108,8 @@ class ImageServer(private val cache: DiskLruCache, private val statistics: Atomi
if (tokenized || serverSettings.forceTokens) { if (tokenized || serverSettings.forceTokens) {
val tokenArr = Base64.getUrlDecoder().decode(Path.of("token")(request)) val tokenArr = Base64.getUrlDecoder().decode(Path.of("token")(request))
val token = JACKSON.readValue<Token>( val token = try {
JACKSON.readValue<Token>(
try { try {
sodium.cryptoBoxOpenEasyAfterNm( sodium.cryptoBoxOpenEasyAfterNm(
tokenArr.sliceArray(24 until tokenArr.size), tokenArr.sliceArray(0 until 24), serverSettings.tokenKey tokenArr.sliceArray(24 until tokenArr.size), tokenArr.sliceArray(0 until 24), serverSettings.tokenKey
@ -119,6 +121,13 @@ class ImageServer(private val cache: DiskLruCache, private val statistics: Atomi
return@then Response(Status.FORBIDDEN) return@then Response(Status.FORBIDDEN)
} }
) )
} catch (e: JsonProcessingException) {
if (LOGGER.isInfoEnabled) {
LOGGER.info("Request for $sanitizedUri rejected for invalid token")
}
return@then Response(Status.FORBIDDEN)
}
if (OffsetDateTime.now().isAfter(token.expires)) { if (OffsetDateTime.now().isAfter(token.expires)) {
if (LOGGER.isInfoEnabled) { if (LOGGER.isInfoEnabled) {
LOGGER.info("Request for $sanitizedUri rejected for expired token") LOGGER.info("Request for $sanitizedUri rejected for expired token")

View file

@ -23,6 +23,7 @@ import java.time.ZoneOffset
import java.time.ZonedDateTime import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
import java.util.* import java.util.*
import mdnet.BuildInfo
import mdnet.base.Constants import mdnet.base.Constants
import org.http4k.core.Filter import org.http4k.core.Filter
import org.http4k.core.HttpHandler import org.http4k.core.HttpHandler
@ -39,7 +40,7 @@ fun addCommonHeaders(): Filter {
{ request: Request -> { request: Request ->
val response = next(request) val response = next(request)
response.header("Date", HTTP_TIME_FORMATTER.format(ZonedDateTime.now(ZoneOffset.UTC))) response.header("Date", HTTP_TIME_FORMATTER.format(ZonedDateTime.now(ZoneOffset.UTC)))
.header("Server", "Mangadex@Home Node ${Constants.CLIENT_VERSION} (${Constants.CLIENT_BUILD})") .header("Server", "Mangadex@Home Node ${BuildInfo.VERSION} (${Constants.CLIENT_BUILD})")
} }
} }
} }

View file

@ -0,0 +1,5 @@
package mdnet;
public class BuildInfo {
public static final String VERSION = "${version}";
}